// // MetaTable::addObject // // Adds a generic metaobject to the table. The metatable does not assume // responsibility for the memory management of metaobjects or type strings. // Key strings are managed, however, to avoid serious problems with mutual // references between metaobjects. // void MetaTable::addObject(MetaObject *object) { unsigned int curNumChains = pImpl->keyhash.getNumChains(); // check for key table overload if(pImpl->keyhash.getLoadFactor() > METALOADFACTOR && curNumChains < metaPrimes[METANUMPRIMES - 1]) { int i; // find a prime larger than the current number of chains for(i = 0; curNumChains < metaPrimes[i]; ++i); pImpl->keyhash.rebuild(metaPrimes[i]); } // Initialize type name object->setType(); // Add the object to the key table. // haleyjd 09/17/2012: use the precomputed unmodulated hash code for the // MetaObject's interned key. pImpl->keyhash.addObject(object, MetaKeyForIndex(object->getKeyIdx()).unmodHC); // Add the object to the type table, which is static in size pImpl->typehash.addObject(object); }
// // MetaObject(size_t keyIndex) // // Constructor for MetaObject using an interned key index // MetaObject::MetaObject(size_t keyIndex) : Super(), links(), typelinks(), type() { metakey_t &keyObj = MetaKeyForIndex(keyIndex); key = keyObj.key; keyIdx = keyObj.index; }
// // MetaTable::getObjectKeyAndType // // Overload taking a MetaObject interned key index and RTTIObject::Type // instance. // MetaObject *MetaTable::getObjectKeyAndType(size_t keyIndex, const MetaObject::Type *type) const { metakey_t &keyObj = MetaKeyForIndex(keyIndex); MetaObject *obj = nullptr; while((obj = pImpl->keyhash.keyIterator(obj, keyObj.key, keyObj.unmodHC))) { if(obj->isInstanceOf(type)) break; } return obj; }
// // MetaTable::getNextObject // // Returns the next object with the same key, or the first such object // in the table if NULL is passed in the object pointer. Returns NULL // when no further objects of the same key are available. // MetaObject *MetaTable::getNextObject(MetaObject *object, const char *key) { // If no key is provided but object is valid, get the next object with the // same key as the current one. if(object && !key) { unsigned int hc = MetaKeyForIndex(object->getKeyIdx()).unmodHC; key = object->getKey(); return pImpl->keyhash.keyIterator(object, key, hc); } else return pImpl->keyhash.keyIterator(object, key); }
// // MetaTable::addObject // // Adds a generic metaobject to the table. The metatable does not assume // responsibility for the memory management of metaobjects or type strings. // Key strings are managed, however, to avoid serious problems with mutual // references between metaobjects. // void MetaTable::addObject(MetaObject *object) { // Check for rehash MetaHashRebuild<>(pImpl->keyhash); // Initialize type name object->setType(); // Add the object to the key table. // haleyjd 09/17/2012: use the precomputed unmodulated hash code for the // MetaObject's interned key. pImpl->keyhash.addObject(object, MetaKeyForIndex(object->getKeyIdx()).unmodHC); // Add the object to the type table, which is static in size pImpl->typehash.addObject(object); }
// // MetaTable::getNextKeyAndType // // Overload taking a MetaObject interned key index. // MetaObject *MetaTable::getNextKeyAndType(MetaObject *object, size_t keyIdx, const char *type) { MetaObject *obj = object; metakey_t &keyObj = MetaKeyForIndex(keyIdx); if(object) { // As above, allow NULL in type to mean "same as current" if(!type) type = object->getClassName(); } while((obj = pImpl->keyhash.keyIterator(obj, keyObj.key, keyObj.unmodHC))) { if(obj->isInstanceOf(type)) break; } return obj; }
// // MetaTable::getNextObject // // Overload taking a MetaObject interned key index. // MetaObject *MetaTable::getNextObject(MetaObject *object, size_t keyIndex) { metakey_t &keyObj = MetaKeyForIndex(keyIndex); return pImpl->keyhash.keyIterator(object, keyObj.key, keyObj.unmodHC); }
// // MetaTable::getObject // // Overload taking a MetaObject interned key index. // MetaObject *MetaTable::getObject(size_t keyIndex) { metakey_t &keyObj = MetaKeyForIndex(keyIndex); return pImpl->keyhash.objectForKey(keyObj.key, keyObj.unmodHC); }