inline const T &Dict::set(const String &key, const T &value) { _Dict::iterator i = dict.find(key); if (i != dict.end()) i->second = DictValue(value); else dict.insert(std::make_pair(key, DictValue(value))); return value; }
////////////////////////////////////////////////////////////////////////// // serialiseDict //virtual Json::Value SeJsonWriter::serialiseDict( void* pData, const ReField* pField, BcU32 ParentFlags ) { Json::Value DictValue( Json::objectValue ); auto pFieldValueType = pField->getValueType(); auto pFieldKeyType = pField->getKeyType(); auto ValueSerialiser = pFieldValueType->getTypeSerialiser(); auto KeySerialiser = pFieldKeyType->getTypeSerialiser(); auto pReadIterator = pField->newReadIterator( pField->getData< void >( pData ) ); // Run a check to make sure we are not a simple deref field. if( ( pField->getKeyFlags() & bcRFF_SIMPLE_DEREF ) != 0 ) { BcAssert( false ); return Json::nullValue; } // Early out if we can't serialise. if( KeySerialiser == nullptr ) { PSY_LOG( "SeJsonWriter: Unable to serialise for key \"%s\"\n", ( *pFieldKeyType->getName() ).c_str() ); return Json::nullValue; } if( ValueSerialiser == nullptr ) { PSY_LOG( "SeJsonWriter: Unable to serialise for value \"%s\"\n", ( *pFieldValueType->getName() ).c_str() ); return Json::nullValue; } std::string OutKeyString; // Iterate over values and serialise individually. // NOTE: Json only supports strings as keys, therefore // if serialising to Json, we must only support strings too. // We could support any object, but it's unlikely we will // use anything that isn't serialisable to strings. while( pReadIterator->isValid() ) { void* pValueData = pReadIterator->getValue(); void* pKeyData = pReadIterator->getKey(); if( KeySerialiser->serialiseToString( pKeyData, OutKeyString ) ) { Json::Value ClassValue; if( ( pField->getValueFlags() & bcRFF_SIMPLE_DEREF ) == 0 ) { ClassValue = serialiseClass( pValueData, static_cast< const ReClass* >( pFieldValueType ), ParentFlags, true ); // TODO: Only if pointer type. } else { void* pPointerValueData = *reinterpret_cast< void** >( pValueData ); ClassValue = serialisePointer( pPointerValueData, static_cast< const ReClass* >( pFieldValueType ), ParentFlags ); } DictValue[ OutKeyString ] = ClassValue; } else { BcAssert( false ); // This should never be hit. It means we're using an invalid key type. } pReadIterator->next(); } delete pReadIterator; return DictValue; }