Browse Source

Made direct access methods for persistent strings.

David Piuva 5 years ago
parent
commit
324c6d73dc
2 changed files with 43 additions and 0 deletions
  1. 37 0
      Source/DFPSR/api/guiAPI.cpp
  2. 6 0
      Source/DFPSR/api/guiAPI.h

+ 37 - 0
Source/DFPSR/api/guiAPI.cpp

@@ -233,6 +233,43 @@ String dsr::component_getProperty(const Component& component, const ReadableStri
 		return target->toString();
 	}
 }
+ReturnCode dsr::component_setProperty_string(const Component& component, const ReadableString& propertyName, const ReadableString& value, bool mustAssign) {
+	MUST_EXIST(component, component_setProperty);
+	Persistent* target = component->findAttribute(propertyName);
+	PersistentString* stringTarget = dynamic_cast<PersistentString*>(target);
+	if (target == nullptr) {
+		if (mustAssign) {
+			throwError("component_setProperty_string: ", propertyName, " in ", component->getClassName(), " could not be found.\n");
+		}
+		return ReturnCode::KeyNotFound;
+	} else if (stringTarget == nullptr) {
+		if (mustAssign) {
+			throwError("component_setProperty_string: ", propertyName, " in ", component->getClassName(), " was a ", target->getClassName(), " instead of a string.\n");
+		}
+		return ReturnCode::KeyNotFound;
+	} else {
+		stringTarget->value = value;
+		return ReturnCode::Good;
+	}
+}
+String dsr::component_getProperty_string(const Component& component, const ReadableString& propertyName, bool mustExist) {
+	MUST_EXIST(component, component_getProperty);
+	Persistent* target = component->findAttribute(propertyName);
+	PersistentString* stringTarget = dynamic_cast<PersistentString*>(target);
+	if (target == nullptr) {
+		if (mustExist) {
+			throwError("component_getProperty_string: ", propertyName, " in ", component->getClassName(), " could not be found.\n");
+		}
+		return U"";
+	} else if (stringTarget == nullptr) {
+		if (mustExist) {
+			throwError("component_getProperty_string: ", propertyName, " in ", component->getClassName(), " was a ", target->getClassName(), " instead of a string.\n");
+		}
+		return U"";
+	} else {
+		return stringTarget->value;
+	}
+}
 
 String dsr::component_call(const Component& component, const ReadableString& methodName, const ReadableString& arguments) {
 	MUST_EXIST(component, component_call);

+ 6 - 0
Source/DFPSR/api/guiAPI.h

@@ -171,6 +171,9 @@ namespace dsr {
 	//   Unless mustAssign forces an exception.
 	//     Returns ReturnCode::ParsingFailure if propertyName was found but value couldn't be converted to its type.
 	ReturnCode component_setProperty(const Component& component, const ReadableString& propertyName, const ReadableString& value, bool mustAssign = true);
+	// A version optimized for basic strings to bypass quote mangling
+	//   The new value is given as it is without unmangling.
+	ReturnCode component_setProperty_string(const Component& component, const ReadableString& propertyName, const ReadableString& value, bool mustAssign = true);
 	// Returns a property found using propertyName in component.
 	//   Raises an exception if component doesn't exist.
 	//   Matching of propertyName is case insensitive.
@@ -179,6 +182,9 @@ namespace dsr {
 	//   If mustExist is false
 	//     Returns an empty string when propertyName isn't found.
 	String component_getProperty(const Component& component, const ReadableString& propertyName, bool mustExist = true);
+	// A version optimized for basic strings to bypass quote mangling
+	//   Returns the result without adding any quote signs or escape characters
+	String component_getProperty_string(const Component& component, const ReadableString& propertyName, bool mustExist = true);
 
 	// Call a named method in the component using optional text arguments
 	String component_call(const Component& component, const ReadableString& methodName);