ObjectPtr Object::LoadContext::loadObjectOrReference( const IndexedIO *container, const IndexedIO::EntryID &name ) { IndexedIO::Entry e = container->entry( name ); if( e.entryType()==IndexedIO::File ) { IndexedIO::EntryIDList pathParts; if ( e.dataType() == IndexedIO::InternedStringArray ) { pathParts.resize( e.arrayLength() ); InternedString *p = &(pathParts[0]); container->read( name, p, e.arrayLength() ); } else { // for backward compatibility... string path; container->read( name, path ); typedef boost::tokenizer<boost::char_separator<char> > Tokenizer; // \todo: this would have trouble if the name of the object contains slashes... Tokenizer tokens(path, boost::char_separator<char>("/")); Tokenizer::iterator t = tokens.begin(); for ( ; t != tokens.end(); t++ ) { pathParts.push_back( *t ); } } std::pair< LoadedObjectMap::iterator,bool > ret = m_loadedObjects->insert( std::pair<IndexedIO::EntryIDList, ObjectPtr>( pathParts, NULL ) ); if ( ret.second ) { // jump to the path.. ConstIndexedIOPtr ioObject = m_ioInterface->directory( pathParts ); // add the loaded object to the map. ret.first->second = loadObject( ioObject ); } return ret.first->second; } else { ConstIndexedIOPtr ioObject = container->subdirectory( name ); IndexedIO::EntryIDList pathParts; ioObject->path( pathParts ); std::pair< LoadedObjectMap::iterator,bool > ret = m_loadedObjects->insert( std::pair<IndexedIO::EntryIDList, ObjectPtr>( pathParts, NULL ) ); if ( ret.second ) { // add the loaded object to the map. ret.first->second = loadObject( ioObject ); } return ret.first->second; } }
void PathMatcherData::load( LoadContextPtr context ) { Data::load( context ); unsigned int v = g_ioVersion; ConstIndexedIOPtr container = context->container( staticTypeName(), v ); const IndexedIO::Entry stringsEntry = container->entry( "strings" ); std::vector<InternedString> strings; strings.resize( stringsEntry.arrayLength() ); InternedString *stringsPtr = strings.data(); container->read( "strings", stringsPtr, stringsEntry.arrayLength() ); const IndexedIO::Entry pathLengthsEntry = container->entry( "pathLengths" ); std::vector<unsigned int> pathLengths; pathLengths.resize( pathLengthsEntry.arrayLength() ); unsigned int *pathLengthsPtr = pathLengths.data(); container->read( "pathLengths", pathLengthsPtr, pathLengthsEntry.arrayLength() ); const IndexedIO::Entry exactMatchesEntry = container->entry( "exactMatches" ); std::vector<unsigned char> exactMatches; exactMatches.resize( exactMatchesEntry.arrayLength() ); unsigned char *exactMatchesPtr = exactMatches.data(); container->read( "exactMatches", exactMatchesPtr, exactMatchesEntry.arrayLength() ); std::vector<InternedString> path; for( size_t i = 0, e = pathLengths.size(); i < e; ++i ) { path.resize( pathLengths[i] ); if( pathLengths[i] ) { path.back() = *stringsPtr++; } if( exactMatches[i] ) { writable().addPath( path ); } } }