Hi Daniel, first and foremost I terribly apologize for coming so late here.
With regard to your question, I've a few comments:
- maxon::BaseArray can store instance derived by classes that are not necessarily defined using
MAXON_DISALLOW_COPY_AND_ASSIGN
: the BaseArray Manual present in the Classes section four different cases of classes.
- in < R20 the maxon::HashMap was not designed to manage instances derived by classes defined with the
MAXON_DISALLOW_COPY_AND_ASSIGN
: if you want to manage such instances in HashMap in R19 or older it's likely you have to store the instances in the stack and store the references in the HashMap.
That said, in R19, you can either decide to use a class not defined with MAXON_DISALLOW_COPY_AND_ASSIGN with both maxon::BaseArray and maxon::HashMap or if you want to use the MAXON_DISALLOW_COPY_AND ASSIGN then you've to take care of storing references in the R19 HashMap.
class TestClassDisallowCopyAndAssign
{
MAXON_DISALLOW_COPY_AND_ASSIGN(TestClassDisallowCopyAndAssign)
private:
Bool _mybool;
Int32 _myint;
public:
TestClassDisallowCopyAndAssign() {}
TestClassDisallowCopyAndAssign(const Bool boolVal, const Int32 intVal)
{
_mybool = boolVal;
_myint = intVal;
}
~TestClassDisallowCopyAndAssign() {}
// move constructor
TestClassDisallowCopyAndAssign(TestClassDisallowCopyAndAssign&& src)
{
_mybool = std::move(src._mybool);
_myint = std::move(src._myint);
}
// move assignment operator
MAXON_OPERATOR_MOVE_ASSIGNMENT(TestClassDisallowCopyAndAssign);
// copy
Bool CopyFrom(const TestClassDisallowCopyAndAssign& src)
{
_mybool = src._mybool;
_myint = src._myint;
return true;
}
Bool GetBool() const { return _mybool; }
Int32 GetInt32() const { return _myint; }
};
class TestClass
{
private:
Bool _mybool;
Int32 _myint;
public:
TestClass() {}
TestClass(const Bool boolVal, const Int32 intVal)
{
_mybool = boolVal;
_myint = intVal;
}
~TestClass() {}
TestClass(const TestClass& src) : _mybool(src._mybool), _myint(src._myint) { }
Bool GetBool() const { return _mybool; }
Int32 GetInt32() const { return _myint; }
};
...
// using BaseArray with a instances that can be copied
maxon::BaseArray<TestClass> arrayTestClass;
TestClass item1 = TestClass(false, 1);
TestClass item2 = TestClass(true, 2);
TestClass item3 = TestClass(false, 3);
TestClass item4 = TestClass(true, 4);
arrayTestClass.Append(item1);
arrayTestClass.Append(item2);
arrayTestClass.Append(item3);
arrayTestClass.Append(item4);
for (Int32 i = 0; i < arrayTestClass.GetCount(); i++)
{
GePrint("arrayTestClass[" + String::IntToString(i) + "]: "+String::IntToString(arrayTestClass[i].GetBool())+"/"+String::IntToString(arrayTestClass[i].GetInt32()));
}
// using HashMap with a instances that can be copied
maxon::HashMap<Int32, TestClass> mapTestClass;
mapTestClass.Put(404, item1);
mapTestClass.Put(101, item2);
mapTestClass.Put(303, item3);
mapTestClass.Put(202, item4);
for (Int32 i = 0; i < mapTestClass.GetCount(); i++)
{
const Int32 k = mapTestClass.GetNonEmptyBucket(i)->GetKey();
const TestClass value = mapTestClass.GetNonEmptyBucket(i)->GetValue();
GePrint("mapTestClass["+String::IntToString(i)+"]: key["+String::IntToString(k)+"], value["+String::IntToString(value.GetBool())+"/"+String::IntToString(value.GetInt32())+"]");
}
Int32 key = 101;
GePrint("mapTestClass@Key[" + String::IntToString(key)+"]: "+ String::IntToString(mapTestClass.FindEntry(key)->GetValue().GetBool()) + "/" + String::IntToString(mapTestClass.FindEntry(key)->GetValue().GetInt32()));
key = 303;
GePrint("mapTestClass@Key[" + String::IntToString(key)+"]: "+ String::IntToString(mapTestClass.FindEntry(key)->GetValue().GetBool()) + "/" + String::IntToString(mapTestClass.FindEntry(key)->GetValue().GetInt32()));
// using BaseArray with instances that can NOT be copied (DISALLOW_COPY_AND_ASSIGN)
maxon::BaseArray<TestClassDisallowCopyAndAssign> arrayTestClassDCA;
TestClassDisallowCopyAndAssign item1DCA = TestClassDisallowCopyAndAssign(false, 10);
TestClassDisallowCopyAndAssign item2DCA = TestClassDisallowCopyAndAssign(true, 20);
TestClassDisallowCopyAndAssign item3DCA = TestClassDisallowCopyAndAssign(false, 30);
TestClassDisallowCopyAndAssign item4DCA = TestClassDisallowCopyAndAssign(true, 40);
arrayTestClassDCA.Append(item1DCA);
arrayTestClassDCA.Append(item2DCA);
arrayTestClassDCA.Append(item3DCA);
arrayTestClassDCA.Append(item4DCA);
for (Int32 i = 0; i < arrayTestClassDCA.GetCount(); i++)
{
GePrint("arrayTestClassDCA[" + String::IntToString(i) + "]: "+String::IntToString(arrayTestClassDCA[i].GetBool())+"/"+String::IntToString(arrayTestClassDCA[i].GetInt32()));
}
// using HashMap with instances that can NOT be copied (DISALLOW_COPY_AND_ASSIGN)
maxon::HashMap<Int32, TestClassDisallowCopyAndAssign*> mapTestClassDCA;
mapTestClassDCA.Put(4040, &item1DCA);
mapTestClassDCA.Put(1010, &item2DCA);
mapTestClassDCA.Put(3030, &item3DCA);
mapTestClassDCA.Put(2020, &item4DCA);
for (Int32 i = 0; i < mapTestClass.GetCount(); i++)
{
const Int32 k = mapTestClassDCA.GetNonEmptyBucket(i)->GetKey();
TestClassDisallowCopyAndAssign** value = &(mapTestClassDCA.GetNonEmptyBucket(i)->GetValue());
GePrint("mapTestClassDCA["+String::IntToString(i)+"]: key["+String::IntToString(k)+"], value["+String::IntToString((*value)->GetBool())+"/"+String::IntToString((*value)->GetInt32())+"]");
}
key = 2020;
GePrint("mapTestClassDCA@Key[" + String::IntToString(key)+"]: "+ String::IntToString(mapTestClassDCA.FindEntry(key)->GetValue()->GetBool()) + "/" + String::IntToString(mapTestClassDCA.FindEntry(key)->GetValue()->GetInt32()));
key = 4040;
GePrint("mapTestClassDCA@Key[" + String::IntToString(key)+"]: "+ String::IntToString(mapTestClassDCA.FindEntry(key)->GetValue()->GetBool()) + "/" + String::IntToString(mapTestClassDCA.FindEntry(key)->GetValue()->GetInt32()));
...
Best, R