Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

osg::BINLoader Class Reference
[File Input/Output]

#include <OSGBINLoader.h>

List of all members.

Type information

typedef std::map< UInt32,
FCInfoStruct
IDLookupMap
class FCIdMapper

Public Member Functions

Constructors/Destructor
BINLoader (std::istream &is)
virtual ~BINLoader ()
read / root access
*void read (void)
NodePtr getRootNode (void)
std::vector< NodePtrgetRootNodes (void)

Private Member Functions

private helper functions
*bool createFieldContainers (void)
void chargeFieldContainers (void)

Private Attributes

provate members
*BinaryFileHandler _inFileHandler
IDLookupMap _fcInfoMap
UInt32 _countContainers
std::vector< NodePtr_vec_pRootNodes
bool _valid_stream

Classes

class  BinaryFileHandler
struct  FCIdMapper
struct  FCInfoStruct


Detailed Description

OpenSG propritrary file loader

    UInt32          num of root nodes
for each root node
      UInt32        root node field container id

    UInt32          num of types
for each type
      UInt32        type name len
      Char8         len bytes
      UInt32        num of instances
for each instance
        UInt32      field container id

for each instance
    UInt32          field container id
    ...             field values written by copyToBin

    

Definition at line 53 of file OSGBINLoader.h.


Member Typedef Documentation

typedef std::map<UInt32, FCInfoStruct> osg::BINLoader::IDLookupMap [protected]
 

Definition at line 92 of file OSGBINLoader.h.


Constructor & Destructor Documentation

BINLoader::BINLoader std::istream &  is  ) 
 

constructor

Definition at line 85 of file OSGBINLoader.cpp.

00085                                    :
00086     _inFileHandler(is),
00087     _fcInfoMap(),
00088     _countContainers(0),
00089     _vec_pRootNodes(),
00090     _valid_stream(is != false)
00091 {
00092 }

BINLoader::~BINLoader void   )  [virtual]
 

destructor

Definition at line 96 of file OSGBINLoader.cpp.

00097 {
00098 }


Member Function Documentation

void BINLoader::read void   ) 
 

process the whole input file

Definition at line 105 of file OSGBINLoader.cpp.

References _valid_stream, _vec_pRootNodes, chargeFieldContainers(), createFieldContainers(), and SFATAL.

Referenced by osg::BINSceneFileType::read().

00106 {
00107     if(!_valid_stream)
00108     {
00109         SFATAL << "BINLoader::read : Stream is invalid!" << std::endl;
00110         return;
00111     }
00112 
00113     _vec_pRootNodes.clear();
00114     if(!createFieldContainers())
00115     {
00116         _valid_stream = false;
00117         return;
00118     }
00119 
00120     chargeFieldContainers();
00121 }

NodePtr BINLoader::getRootNode void   ) 
 

return first root node

Definition at line 125 of file OSGBINLoader.cpp.

References _valid_stream, _vec_pRootNodes, and osg::NullFC.

Referenced by osg::BINSceneFileType::read().

00126 {
00127     if(!_valid_stream)
00128     {
00129         return NullFC;
00130     }
00131 
00132     return _vec_pRootNodes[0];
00133 }

std::vector< NodePtr > BINLoader::getRootNodes void   ) 
 

return all root nodes

Definition at line 137 of file OSGBINLoader.cpp.

References _vec_pRootNodes.

00138 {
00139     return _vec_pRootNodes;
00140 }

bool BINLoader::createFieldContainers void   )  [private]
 

create all fieldcontainers with default values

Definition at line 147 of file OSGBINLoader.cpp.

References _countContainers, _fcInfoMap, _inFileHandler, _vec_pRootNodes, osg::FieldContainerFactory::createFieldContainer(), osg::NodePtr::dcast(), osg::FieldContainerPtrBase::getFieldContainerId(), osg::BinaryDataHandler::getValue(), osg::BINLoader::FCInfoStruct::newId, osg::NullFC, osg::BINLoader::FCInfoStruct::ptr, SFATAL, SINFO, and osg::FieldContainerFactory::the().

Referenced by read().

00148 {
00149     UInt32 countTypes = 0, countCurrentType = 0, oldFCId = 0, numOfRoots = 0,
00150         currentId = 0, i, j;
00151     std::string fcTypeCName;
00152     FCInfoStruct newFCInfo;
00153     std::set < UInt32 > setOfRootIds;
00154 
00155     //fetch the number of roots
00156     _inFileHandler.getValue(numOfRoots);
00157 
00158     //fetch the root IDs
00159     for(i = 0; i != numOfRoots; ++i)
00160     {
00161         _inFileHandler.getValue(currentId);
00162         setOfRootIds.insert(currentId);
00163     }
00164 
00165     //fetch number of different types
00166     _inFileHandler.getValue(countTypes);
00167 
00168     //fetch number of and IDs themselves
00169     for(i = 0; i != countTypes; ++i)
00170     {
00171         _inFileHandler.getValue(fcTypeCName);
00172         _inFileHandler.getValue(countCurrentType);
00173         for(j = 0; j != countCurrentType; j++)
00174         {
00175             _inFileHandler.getValue(oldFCId);
00176             newFCInfo.ptr = FieldContainerFactory::the()->createFieldContainer(fcTypeCName.c_str());
00177 
00178             if(newFCInfo.ptr == NullFC)
00179             {
00180                 SFATAL << "Couldn't create unknown FieldContainer with type '" <<
00181                        fcTypeCName << "'!" << std::endl;
00182                 return false;
00183             }
00184             _countContainers++;
00185 
00186             //det. all RootNodes
00187             if(setOfRootIds.find(oldFCId) != setOfRootIds.end())
00188             {
00189                 _vec_pRootNodes.push_back(NodePtr::dcast(newFCInfo.ptr));
00190             }
00191 
00192             newFCInfo.newId = newFCInfo.ptr.getFieldContainerId();
00193 
00194             if(_fcInfoMap.insert(std::make_pair(oldFCId, newFCInfo)).second
00195                == false)
00196             {
00197                 std::cerr <<
00198                     "ERROR in BINLoader::createFieldContainers()" <<
00199                     std::endl;
00200             }
00201         }
00202     }
00203 
00204     SINFO << "created " << _countContainers << " containers" << std::endl;
00205     return true;
00206 }

void BINLoader::chargeFieldContainers void   )  [private]
 

apply field values to the field containers

Definition at line 210 of file OSGBINLoader.cpp.

References _fcInfoMap, _inFileHandler, osg::ChangedOrigin::Abstract, osg::ChangedOrigin::AbstrIncRefCount, osg::beginEditCP(), osg::endEditCP(), osg::BinaryDataHandler::getValue(), osg::FieldContainerFactory::setMapper(), SINFO, SWARNING, and osg::FieldContainerFactory::the().

Referenced by read().

00211 {
00212     FCIdMapper                  mapper(&_fcInfoMap);
00213     IDLookupMap::iterator       fcInfoIter = _fcInfoMap.begin();
00214     const IDLookupMap::iterator fcInfoEnd = _fcInfoMap.end();
00215 
00216     UInt32 mapSize = _fcInfoMap.size(), currentFieldContainerOldId, count = 0;
00217     BitVector mask;
00218     FieldContainerFactory *factory = FieldContainerFactory::the();
00219 
00220     factory->setMapper(&mapper);
00221     while(count < mapSize)
00222     {
00223         count++;
00224 
00225         SINFO <<
00226             "loading container " <<
00227             std::setw(4) <<
00228             count <<
00229             "/" <<
00230             mapSize <<
00231             "..." <<
00232             std::endl;
00233 
00234         //fetch container id
00235         _inFileHandler.getValue(currentFieldContainerOldId);
00236         fcInfoIter = _fcInfoMap.find(currentFieldContainerOldId);
00237 
00238         if(fcInfoIter == fcInfoEnd)
00239         {
00240             SWARNING <<
00241                 "ERROR in BINLoader::chargeFieldContainers():" <<
00242                 std::endl <<
00243                 "no matching container found for ID " <<
00244                 currentFieldContainerOldId <<
00245                 std::endl <<
00246                 "THIS SHOULD NOT HAPPEN!!!" <<
00247                 std::endl;
00248 
00249             continue;
00250         }
00251 
00252         if(fcInfoIter->second.read)
00253         {
00254             SWARNING <<
00255                 "ERROR in BINLoader::chargeFieldContainers():" <<
00256                 std::endl <<
00257                 "original ID: " <<
00258                 currentFieldContainerOldId <<
00259                 std::endl <<
00260                 "new ID     : " <<
00261                 fcInfoIter->second.newId <<
00262                 std::endl <<
00263                 "CONTAINER ALREADY WRITTEN! CONTAINER " <<
00264                 "WILL BE OVERWRITTEN!" <<
00265                 std::endl <<
00266                 "THIS SHOULD NOT HAPPEN!!!" <<
00267                 std::endl;
00268         }
00269 
00270         // fetch mask
00271         _inFileHandler.getValue(mask);
00272 
00273         // fetch container data
00274         beginEditCP(fcInfoIter->second.ptr, mask,
00275                             ChangedOrigin::Abstract | ChangedOrigin::AbstrIncRefCount);
00276         {
00277             fcInfoIter->second.ptr->copyFromBin(_inFileHandler, BitVector(mask));
00278         }
00279 
00280         endEditCP(fcInfoIter->second.ptr, mask,
00281                           ChangedOrigin::Abstract | ChangedOrigin::AbstrIncRefCount);
00282 
00283         fcInfoIter->second.read = true;
00284     }
00285 
00286     factory->setMapper(NULL);
00287 }


Friends And Related Function Documentation

friend class FCIdMapper [friend]
 

Definition at line 80 of file OSGBINLoader.h.


Member Data Documentation

* BinaryFileHandler osg::BINLoader::_inFileHandler [private]
 

Definition at line 134 of file OSGBINLoader.h.

Referenced by chargeFieldContainers(), and createFieldContainers().

IDLookupMap osg::BINLoader::_fcInfoMap [private]
 

Definition at line 135 of file OSGBINLoader.h.

Referenced by chargeFieldContainers(), and createFieldContainers().

UInt32 osg::BINLoader::_countContainers [private]
 

Definition at line 136 of file OSGBINLoader.h.

Referenced by createFieldContainers().

std::vector<NodePtr> osg::BINLoader::_vec_pRootNodes [private]
 

Definition at line 137 of file OSGBINLoader.h.

Referenced by createFieldContainers(), getRootNode(), getRootNodes(), and read().

bool osg::BINLoader::_valid_stream [private]
 

Definition at line 138 of file OSGBINLoader.h.

Referenced by getRootNode(), and read().


The documentation for this class was generated from the following files:
Generated on Thu Aug 25 04:13:48 2005 for OpenSG by  doxygen 1.4.3