Browse Source

Made persistent types more explicit.

David Piuva 5 years ago
parent
commit
18c72841bb

+ 1 - 1
Source/DFPSR/persistent/atomic/PersistentBoolean.h

@@ -29,8 +29,8 @@
 namespace dsr {
 namespace dsr {
 
 
 class PersistentBoolean : public Persistent {
 class PersistentBoolean : public Persistent {
-PERSISTENT_DECLARATION(PersistentBoolean)
 public:
 public:
+	PERSISTENT_DECLARATION(PersistentBoolean)
 	bool value;
 	bool value;
 public:
 public:
 	PersistentBoolean() : value(0) {}
 	PersistentBoolean() : value(0) {}

+ 1 - 1
Source/DFPSR/persistent/atomic/PersistentColor.h

@@ -30,8 +30,8 @@
 namespace dsr {
 namespace dsr {
 
 
 class PersistentColor : public Persistent {
 class PersistentColor : public Persistent {
-PERSISTENT_DECLARATION(PersistentColor)
 public:
 public:
+	PERSISTENT_DECLARATION(PersistentColor)
 	ColorRgbI32 value;
 	ColorRgbI32 value;
 public:
 public:
 	PersistentColor() : value(0, 0, 0) {}
 	PersistentColor() : value(0, 0, 0) {}

+ 1 - 1
Source/DFPSR/persistent/atomic/PersistentInteger.h

@@ -29,8 +29,8 @@
 namespace dsr {
 namespace dsr {
 
 
 class PersistentInteger : public Persistent {
 class PersistentInteger : public Persistent {
-PERSISTENT_DECLARATION(PersistentInteger)
 public:
 public:
+	PERSISTENT_DECLARATION(PersistentInteger)
 	int64_t value;
 	int64_t value;
 public:
 public:
 	PersistentInteger() : value(0) {}
 	PersistentInteger() : value(0) {}

+ 6 - 0
Source/DFPSR/persistent/atomic/PersistentString.cpp

@@ -27,6 +27,12 @@ using namespace dsr;
 
 
 PERSISTENT_DEFINITION(PersistentString)
 PERSISTENT_DEFINITION(PersistentString)
 
 
+PersistentString PersistentString::unmangled(const ReadableString &text) {
+	PersistentString result;
+	result.value = text;
+	return result;
+}
+
 bool PersistentString::assignValue(const ReadableString &text) {
 bool PersistentString::assignValue(const ReadableString &text) {
 	this->value = string_unmangleQuote(text);
 	this->value = string_unmangleQuote(text);
 	return true;
 	return true;

+ 3 - 2
Source/DFPSR/persistent/atomic/PersistentString.h

@@ -29,12 +29,13 @@
 namespace dsr {
 namespace dsr {
 
 
 class PersistentString : public Persistent {
 class PersistentString : public Persistent {
-PERSISTENT_DECLARATION(PersistentString)
 public:
 public:
+	PERSISTENT_DECLARATION(PersistentString)
 	String value;
 	String value;
 public:
 public:
 	PersistentString() : value("") {}
 	PersistentString() : value("") {}
-	explicit PersistentString(String text) : value(text) {}
+	// Because the constructor from text is used for serialization, an explicit constructor must be used to avoid mangling
+	static PersistentString unmangled(const ReadableString &text);
 public:
 public:
 	virtual bool assignValue(const ReadableString &text) override;
 	virtual bool assignValue(const ReadableString &text) override;
 	virtual String& toStreamIndented(String& out, const ReadableString& indentation) const override;
 	virtual String& toStreamIndented(String& out, const ReadableString& indentation) const override;

+ 1 - 2
Source/test/tests/PersistentTest.cpp

@@ -11,7 +11,7 @@ public:
 	PersistentString b;
 	PersistentString b;
 public:
 public:
 	MyClass() {}
 	MyClass() {}
-	MyClass(int a, const String &b) : a(a), b(b) {}
+	MyClass(int a, const String &b) : a(a), b(PersistentString::unmangled(b)) {}
 public:
 public:
 	void declareAttributes(StructureDefinition &target) const override {
 	void declareAttributes(StructureDefinition &target) const override {
 		target.declareAttribute(U"a");
 		target.declareAttribute(U"a");
@@ -154,7 +154,6 @@ START_TEST(Persistent)
 	tree.addChild(std::make_shared<MySubClass>(34, U"foo", 56, 78));
 	tree.addChild(std::make_shared<MySubClass>(34, U"foo", 56, 78));
 	second->addChild(std::make_shared<MyClass>(3, U"third"));
 	second->addChild(std::make_shared<MyClass>(3, U"third"));
 	ASSERT_MATCH(tree.toString(), exampleThree);
 	ASSERT_MATCH(tree.toString(), exampleThree);
-	//printText(tree.toString(), U"\n");
 
 
 	// Tree structure from text
 	// Tree structure from text
 	std::shared_ptr<Persistent> treeCopy = createPersistentClassFromText(exampleThree);
 	std::shared_ptr<Persistent> treeCopy = createPersistentClassFromText(exampleThree);