Exporter.h

Go to the documentation of this file.
00001 /* $Id:$ */
00002 
00003 #ifndef __EXPORTER_H
00004 #define __EXPORTER_H
00005 
00006 /*
00007  * Explorer traversing the whole scene graph and writing it to file
00008  * using some format
00009  */
00010 
00011 #include <esg/explorer/Explorer.h>
00012 
00013 namespace esg {
00014 
00015 class Exporter : public Explorer {
00016 protected:
00017     FILE   * _file;
00018     bool     _close;
00019     bool     _result;
00020 
00021 protected:
00022     void _indent (unsigned depth, const char * ind = "   ") {
00023         for (unsigned i = 0; i < depth; i++) fprintf(_file, "%s", ind);
00024     }
00025     
00026 public:
00027     Exporter (FILE   * f /* opened (!) file */,
00028               bool     c /* wether to close file at the end */)
00029         : _file(f), _close(c), _result(false)
00030     {}
00031 
00032     virtual void explore (SceneGraphObject& obj) {
00033         while (!_trStack.empty()) _trStack.pop();
00034         if (_file) {
00035             _result = true;
00036             (void) _explore(obj);
00037             if (_close) fclose(_file);
00038         } else
00039             _result = false;
00040     }
00041 
00042     bool result (void) const { return _result; }
00043 
00044     void setOutput (FILE * f /* opened (!) file */,
00045                     bool   c /* wether to close file at the end */)
00046     {
00047         if (_file && _close) fclose(_file);
00048         _file  = f;
00049         _close = c;
00050     }
00051 };
00052 
00053 };
00054 
00055 #endif // __EXPORTER_H

Generated on Wed Jun 28 12:24:28 2006 for esg by  doxygen 1.4.6