19 #ifndef INTERFACE_FUNCTIONS_CC
20 #define INTERFACE_FUNCTIONS_CC
41 template <
class ObjType>
43 static int16_t typeID = -1;
50 else if (!std::is_base_of<Object, ObjType>::value) {
55 std::string name = getTypeName<ObjType>();
63 #define CHAR_PTR(c) ((char*)c)
69 #ifdef INITIALIZE_ALLOCATOR_BLOCK
70 void* space = calloc(1, numBytesIn);
72 void* space = malloc(numBytesIn);
74 if (space ==
nullptr) {
75 std::cout <<
"Fatal Error in makeObjectAllocatorBlock(): out of memory" << std::endl;
83 bool throwExceptionOnFail) {
103 template <
class ObjType>
108 template <
class ObjType>
122 temp.template setup<ObjType>();
124 #ifdef DEBUG_OBJECT_MODEL
132 if (space ==
nullptr) {
142 setUpAndCopyFromTemplate<ObjType>(returnVal->
getObject(), &forMe,
nullptr);
144 #ifdef DEBUG_OBJECT_MODEL
156 template <
class ObjType,
class... Args>
158 #ifdef DEBUG_OBJECT_MODEL
160 temp.template setup<ObjType>();
161 std::cout <<
"to get RAM from allocator with size ="
166 #ifdef DEBUG_OBJECT_MODEL
173 if (returnVal ==
nullptr) {
180 new ((
void*)returnVal->getObject()) ObjType(args...);
186 #ifdef DEBUG_OBJECT_MODEL
195 returnVal->setRefCount(0);
201 template <
class ObjType,
class... Args>
203 #ifdef DEBUG_OBJECT_MODEL
205 temp.template setup<ObjType>();
206 std::cout <<
"In makeObjectWithExtraStorage:" << std::endl;
207 std::cout <<
"extra=" << extra << std::endl;
208 std::cout <<
"sizeof(ObjType)=" <<
sizeof(ObjType) << std::endl;
210 std::cout <<
"to get RAM from allocator with size ="
215 #ifdef DEBUG_OBJECT_MODEL
223 if (returnVal ==
nullptr)
229 new ((
void*)returnVal->getObject()) ObjType(args...);
235 #ifdef DEBUG_OBJECT_MODEL
244 returnVal->setRefCount(0);
250 template <
class ObjType>
257 std::cout <<
"the handle to get record is not in current allocation block" << std::endl;
264 template <
class OutObjType,
class InObjType>
269 result.typeInfo = castMe.typeInfo;
270 result.getTarget()->incRefCount();
274 template <
class ObjType>
284 temp = forMe.copyTargetToCurrentAllocationBlock();
305 template <
class TargetType>
310 temp->child = copyMe;
#define REF_COUNT_PREAMBLE_SIZE
RefCountedObject< ObjType > * getHandle(ObjType &forMe)
size_t getSizeOfConstituentObject(void *forMe) const
size_t getBytesAvailableInCurrentAllocatorBlock()
AllocatorState temporarilyUseBlockForAllocations(void *putMeHere, size_t numBytesAvailable)
Handle< TargetType > deepCopyToCurrentAllocationBlock(Handle< TargetType > ©Me)
Allocator & getAllocator()
void setupBlock(void *where, size_t numBytesIn, bool throwExceptionOnFail)
void restoreAllocationBlock(AllocatorState &restoreMe)
NotEnoughSpace myException
RefCountedObject< ObjType > * makeObjectWithExtraStorage(size_t extra, Args &&...args)
Record< ObjType > * getRecord(Handle< ObjType > &forMe)
void * getAllocationBlock(Handle< ObjType > &forMe)
size_t getBytesAvailableInCurrentAllocatorBlock()
unsigned getNumObjectsInHomeAllocatorBlock(Handle< ObjType > &forMe)
void * getRAM(size_t howMuch)
unsigned getNumObjectsInCurrentAllocatorBlock()
int16_t getTypeCode() const
RefCountedObject< ObjType > * makeObject(Args &&...args)
unsigned getNumObjectsInAllocatorBlock(void *forMe)
void setupUserSuppliedBlock(void *where, size_t numBytesIn, bool throwExceptionOnFail)
static int16_t getIDByName(std::string objectName, bool withLock=true)
Handle< OutObjType > unsafeCast(Handle< InObjType > &castMe)
unsigned getNumObjectsInCurrentAllocatorBlock()
ObjType * getObject() const
void setRefCount(unsigned toMe)
void emptyOutBlock(void *here)
void makeObjectAllocatorBlock(size_t numBytesIn, bool throwExceptionOnFail)
unsigned getNumObjectsInAllocatorBlock(void *forMe)
void emptyOutContainingBlock(void *forMe)
unsigned getNumObjectsInHomeAllocatorBlock(Handle< ObjType > &forMe)