#include <OSGOSGWriter.h>
Member | |
| void | visitContainer (const FieldContainerPtr pFC) |
| void | visitField (const Field *pF) |
| void | writeContainer (const FieldContainerPtr pFC) |
| void | writeField (const Field *pF, const FieldDescription *fieldDesc) |
| *FCInfoHelperMap | _visitedFCMap |
| StandardStringConversionState | _state |
| Indenter | _indent |
| std::ostream & | _outStream |
Public Member Functions | |
Constructors | |
| * | OSGWriter (std::ostream &stream, UInt32 indentStep=4) |
Destructor | |
| * | ~OSGWriter (void) |
Write | |
| *void | write (FieldContainerPtr container) |
| void | write (std::vector< FieldContainerPtr > containers) |
Protected Types | |
| typedef std::map< FieldContainerPtr, FCInfoHelper > | FCInfoHelperMap |
Static Protected Attributes | |
| static const UInt32 | DefaultSFWidth = TypeTraits<UInt32>::getMax() |
| static const UInt32 | DefaultMFWidth = 60 |
Private Member Functions | |
| OSGWriter (const OSGWriter &source) | |
| prohibit default function (move to 'public' if needed) | |
| void | operator= (const OSGWriter &source) |
| prohibit default function (move to 'public' if needed) | |
Classes | |
| struct | FCInfoHelper |
Definition at line 65 of file OSGOSGWriter.h.
|
|
Definition at line 109 of file OSGOSGWriter.h. |
|
||||||||||||
|
Constructor. Set members to initial values. Definition at line 75 of file OSGOSGWriter.cpp. 00075 : 00076 _visitedFCMap( ), 00077 _state (0, DefaultSFWidth), 00078 _indent (0, indentStep ), 00079 _outStream (stream ) 00080 { 00081 }
|
|
|
Destructor. There are no dynamic members to destroy. Definition at line 88 of file OSGOSGWriter.cpp.
|
|
|
|
|
|
Write a single FieldContainer with all its "children", i.e. everything that can be reached via Ptr-Fields. Definition at line 98 of file OSGOSGWriter.cpp. References _indent, _outStream, _visitedFCMap, osg::Indenter::setIndent(), visitContainer(), and writeContainer(). Referenced by osg::OSGSceneFileType::write(). 00099 { 00100 _visitedFCMap.clear(); 00101 _indent.setIndent(0); 00102 00103 _outStream << "#OSG V1.0 " << std::endl; 00104 00105 visitContainer(container); 00106 writeContainer(container); 00107 }
|
|
|
Write all FieldContainers in containers with their "children", i.e. everything that can be reached via Ptr-Fields. Definition at line 113 of file OSGOSGWriter.cpp. References _indent, _outStream, _visitedFCMap, osg::Indenter::setIndent(), visitContainer(), and writeContainer(). 00114 { 00115 _visitedFCMap.clear(); 00116 _indent.setIndent(0); 00117 00118 _outStream << "#OSG V1.0 " << std::endl; 00119 00120 std::vector<FieldContainerPtr>::reverse_iterator iter; 00121 00122 for(iter = containers.rbegin(); iter != containers.rend(); ++iter) 00123 { 00124 visitContainer( *iter ); 00125 } 00126 00127 for(iter = containers.rbegin(); iter != containers.rend(); ++iter) 00128 { 00129 writeContainer( *iter ); 00130 } 00131 }
|
|
|
Definition at line 166 of file OSGOSGWriter.cpp. References _visitedFCMap, osg::FieldContainerType::getFieldDescription(), osg::FieldContainerType::getNumFieldDescs(), osg::FieldDescription::isInternal(), osg::NullFC, SWARNING, and visitField(). Referenced by visitField(), and write(). 00167 { 00168 00169 if(pFC == NullFC) 00170 { 00171 return; 00172 } 00173 00174 typedef std::pair<FCInfoHelperMap::iterator, bool> MapInsertInfo; 00175 00176 std::string containerName; 00177 const FieldContainerType& fcType = pFC->getType(); 00178 UInt32 numFields = fcType.getNumFieldDescs(); 00179 MapInsertInfo insertInfo; 00180 00181 insertInfo = _visitedFCMap.insert(std::make_pair(pFC, FCInfoHelper())); 00182 if(insertInfo.second == true) 00183 { 00184 //the FC was NOT visited before 00185 for(UInt32 field=1; field<=numFields; field++) 00186 { 00187 const FieldDescription* fieldDesc = 00188 fcType.getFieldDescription(field); 00189 if(fieldDesc->isInternal()) 00190 { 00191 continue; 00192 } 00193 visitField(pFC->getField(field)); 00194 } 00195 } 00196 else 00197 { 00198 //the FC was in the map => FC is shared 00199 FCInfoHelperMap::iterator iter = _visitedFCMap.find(pFC); 00200 if(iter == _visitedFCMap.end()) 00201 { 00202 SWARNING << "OSGWriter::visitContainer(): FieldContainerPtr " 00203 << "not found in map" << std::endl; 00204 return; 00205 } 00206 if(iter->second.hasName == false) 00207 { 00208 iter->second.setName(pFC); 00209 iter->second.hasName = true; 00210 } 00211 } 00212 }
|
|
|
Definition at line 214 of file OSGOSGWriter.cpp. References osg::Field::getCardinality(), osg::TypeBase::getCName(), osg::Field::getType(), osg::SField< FieldTypeT, fieldNameSpace >::getValue(), osg::FieldType::MULTI_FIELD, osg::FieldType::SINGLE_FIELD, osg::MField< FieldTypeT, fieldNameSpace >::size(), and visitContainer(). Referenced by visitContainer(). 00215 { 00216 if(pF == NULL) 00217 { 00218 return; 00219 } 00220 00221 const FieldType& fType = pF->getType(); 00222 // const DataType & contentType = pF->getContentType(); 00223 00224 //handle SFAttachmentMap as special case here 00225 //if(fType.isDerivedFrom(SFAttachmentMap::getClassType())) 00226 if(strstr(fType.getCName(), "AttachmentMap") != NULL) 00227 { 00228 //visit the Attachment FCs 00229 00230 const SFAttachmentMap *sfAttMap = (const SFAttachmentMap*) pF; 00231 AttachmentMap attMap = sfAttMap->getValue(); 00232 00233 AttachmentMap::const_iterator iter = attMap.begin(); 00234 AttachmentMap::const_iterator end = attMap.end(); 00235 00236 for(; iter!=end; ++iter) 00237 { 00238 visitContainer(iter->second); 00239 } 00240 } 00241 //else if(contentType.isDerivedFrom(FieldContainerPtr::getClassType())) 00242 else if(strstr(fType.getCName(), "Ptr") != NULL) 00243 { 00244 //this Field points to FC 00245 00246 //to access the content of a field one must know the cardinality 00247 if(pF->getCardinality() == FieldType::SINGLE_FIELD) 00248 { 00249 const SFFieldContainerPtr* sfFCPtr = 00250 (const SFFieldContainerPtr*) pF; 00251 visitContainer(sfFCPtr->getValue()); 00252 } 00253 else if(pF->getCardinality() == FieldType::MULTI_FIELD) 00254 { 00255 const MFFieldContainerPtr* mfFCPtr = 00256 (const MFFieldContainerPtr*) pF; 00257 UInt32 mfSize = mfFCPtr->size(); 00258 for(UInt32 i=0; i < mfSize; i++) 00259 { 00260 visitContainer((*(mfFCPtr))[i]); 00261 } 00262 } 00263 } 00264 }
|
|
|
Definition at line 266 of file OSGOSGWriter.cpp. References _indent, _outStream, _visitedFCMap, osg::FieldContainerType::getFieldDescription(), osg::FieldContainerType::getNumFieldDescs(), osg::FieldDescription::isInternal(), osg::NullFC, SWARNING, and writeField(). Referenced by write(), and writeField(). 00267 { 00268 if(pFC == NullFC) 00269 { 00270 return; 00271 } 00272 00273 const FieldContainerType& fcType = pFC->getType(); 00274 UInt32 numFields = fcType.getNumFieldDescs(); 00275 00276 FCInfoHelperMap::iterator iter = _visitedFCMap.find(pFC); 00277 if(iter == _visitedFCMap.end()) 00278 { 00279 SWARNING << "OSGWriter::writeContainer(): FieldContainerPtr " 00280 << "not found in map" << std::endl; 00281 return; 00282 } 00283 00284 if(!iter->second.written) 00285 { 00286 //FC is not written yet 00287 iter->second.written = true; 00288 if(iter->second.hasName) 00289 { 00290 _outStream << _indent << "DEF " 00291 << iter->second.containerName << " " 00292 << pFC->getTypeName() << " {" 00293 << std::endl; 00294 } 00295 else{ 00296 _outStream << _indent << pFC->getTypeName() << " {" 00297 << std::endl; 00298 } 00299 00300 _indent++; 00301 00302 for(UInt32 field=1; field<=numFields; field++) 00303 { 00304 const FieldDescription* fieldDesc = 00305 fcType.getFieldDescription(field); 00306 if(fieldDesc->isInternal()) 00307 { 00308 continue; 00309 } 00310 writeField(pFC->getField(field), fieldDesc); 00311 } 00312 _indent--; 00313 _outStream << _indent << "}" << std::endl; 00314 } 00315 else 00316 { 00317 //FC is already written -> its shared -> write reference 00318 if(!iter->second.hasName) 00319 { 00320 SWARNING << "OSGWriter::writeContainer(): FieldContainer is " 00321 << "shared, but not named" 00322 << std::endl; 00323 return; 00324 } 00325 00326 _outStream << _indent 00327 << "USE " 00328 << iter->second.containerName 00329 << std::endl; 00330 } 00331 00332 }
|
|
||||||||||||
|
Definition at line 335 of file OSGOSGWriter.cpp. References _indent, _outStream, _state, DefaultMFWidth, DefaultSFWidth, osg::Field::getCardinality(), osg::TypeBase::getCName(), osg::Indenter::getIndent(), osg::FieldDescription::getName(), osg::Field::getType(), osg::SField< FieldTypeT, fieldNameSpace >::getValue(), osg::Field::getValueByStr(), osg::FieldType::MULTI_FIELD, osg::NullFC, osg::StandardStringConversionState::setIndent(), osg::StandardStringConversionState::setWidth(), osg::FieldType::SINGLE_FIELD, osg::MField< FieldTypeT, fieldNameSpace >::size(), and writeContainer(). Referenced by writeContainer(). 00336 { 00337 00338 if(pF == NULL) 00339 { 00340 return; 00341 } 00342 00343 const FieldType& fType = pF->getType(); 00344 // const DataType& contentType = pF->getContentType(); 00345 00346 //handle SFAttachmentMap as special case here 00347 //if(fType.isDerivedFrom(SFAttachmentMap::getClassType())) 00348 if(strstr(fType.getCName(), "AttachmentMap") != NULL) 00349 { 00350 //write Attachments 00351 00352 const SFAttachmentMap *sfAttMap = (const SFAttachmentMap*) pF; 00353 AttachmentMap attMap = sfAttMap->getValue(); 00354 00355 AttachmentMap::const_iterator iter = attMap.begin(); 00356 AttachmentMap::const_iterator end = attMap.end(); 00357 00358 _outStream << _indent << fieldDesc->getName() << " [ "; 00359 _indent++; 00360 _state.setIndent(_indent.getIndent()); 00361 00362 //if the Attachment Map is empty write [] as its content 00363 if(iter==end) 00364 { 00365 _outStream << " ] " << std::endl; 00366 _indent--; 00367 } 00368 else 00369 { 00370 _outStream << std::endl; 00371 00372 for(; iter!=end; ++iter) 00373 { 00374 if(iter->second->getInternal().getValue() != true) 00375 { 00376 writeContainer(iter->second); 00377 } 00378 } 00379 _indent--; 00380 00381 _outStream << _indent << " ] " << std::endl; 00382 } 00383 } 00384 //else if(contentType.isDerivedFrom(FieldContainerPtr::getClassType())) 00385 else if(strstr(fType.getCName(), "Ptr") != NULL) 00386 { 00387 //this Field points to FC 00388 00389 _state.setIndent(_indent.getIndent()); 00390 _outStream << _indent << fieldDesc->getName(); 00391 00392 //to access the content of a field via a Field* 00393 //one must know the cardinality 00394 if(pF->getCardinality() == FieldType::SINGLE_FIELD) 00395 { 00396 const SFFieldContainerPtr* sfFCPtr = 00397 (const SFFieldContainerPtr*) pF; 00398 if(sfFCPtr->getValue() == NullFC) 00399 { 00400 _outStream << " NULL" << std::endl; 00401 } 00402 else 00403 { 00404 _outStream << std::endl; 00405 _indent++; 00406 writeContainer(sfFCPtr->getValue()); 00407 _indent--; 00408 } 00409 } 00410 else if(pF->getCardinality() == FieldType::MULTI_FIELD) 00411 { 00412 _outStream << " [" << std::endl; 00413 _indent++; 00414 const MFFieldContainerPtr* mfFCPtr = 00415 (const MFFieldContainerPtr*) pF; 00416 UInt32 mfSize = mfFCPtr->size(); 00417 for(UInt32 i=0; i < mfSize; i++) 00418 { 00419 if((*(mfFCPtr))[i] == NullFC) 00420 { 00421 _outStream << _indent << "NULL" << std::endl; 00422 } 00423 else 00424 { 00425 writeContainer((*(mfFCPtr))[i]); 00426 } 00427 } 00428 _indent--; 00429 _outStream << _indent << "]" << std::endl; 00430 } 00431 } 00432 else 00433 { 00434 //this Field contains data -> write it out 00435 00436 _state.setIndent(_indent.getIndent()); 00437 _outStream << _indent << fieldDesc->getName(); 00438 00439 std::string fieldValue; 00440 00441 //to access the content of a field via a Field* 00442 //one must know the cardinality 00443 if(pF->getCardinality() == FieldType::SINGLE_FIELD) 00444 { 00445 _state.setIndent(0); 00446 _state.setWidth(DefaultSFWidth); 00447 pF->getValueByStr(fieldValue, _state); 00448 _outStream << " " << fieldValue << std::endl; 00449 } 00450 else if(pF->getCardinality() == FieldType::MULTI_FIELD) 00451 { 00452 _outStream << " [" << std::endl; 00453 00454 _indent++; 00455 _state.setIndent(_indent.getIndent()); 00456 _state.setWidth(DefaultMFWidth); 00457 pF->getValueByStr(fieldValue, _state); 00458 _outStream << fieldValue << std::endl; 00459 _indent--; 00460 00461 _outStream << _indent << "]" << std::endl; 00462 } 00463 } 00464 }
|
|
|
|
|
|
Definition at line 58 of file OSGOSGWriter.cpp. Referenced by writeField(). |
|
|
Definition at line 59 of file OSGOSGWriter.cpp. Referenced by writeField(). |
|
|
Definition at line 115 of file OSGOSGWriter.h. Referenced by visitContainer(), write(), and writeContainer(). |
|
|
Definition at line 116 of file OSGOSGWriter.h. Referenced by writeField(). |
|
|
Definition at line 117 of file OSGOSGWriter.h. Referenced by write(), writeContainer(), and writeField(). |
|
|
Definition at line 118 of file OSGOSGWriter.h. Referenced by write(), writeContainer(), and writeField(). |
1.4.3