Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

IFileManager.cxx

Go to the documentation of this file.
00001 // IFileManager.cxx: implementation of the IFileManager class.
00002 //
00004 
00005 #include "xml/IFileManager.h"
00006 #include "xml/IFile.h"
00007 #include "facilities/error.h"
00008 
00009 #include <strstream>
00010 #include <cassert>
00011 
00012 namespace xml {
00013   std::vector<IFileManager::LoadParamFunc> IFileManager::s_calls;
00014   IFileManager* IFileManager::s_instance = 0;
00015 
00017   // Construction/Destruction
00019   
00020   IFileManager::IFileManager() : m_file(0)
00021     {
00022       assert(!s_instance);
00023       s_instance = this;
00024     }
00025   
00026   void IFileManager::load( IFile* file )
00027     {
00028       if (file == 0) FATAL_MACRO ("Unable to open initialization file.");
00029       m_file = file;
00030       loadParams();
00031     }
00032   
00033   void IFileManager::load(char *filename)
00034     {
00035       m_file = new IFile(filename);
00036       loadParams();
00037     }
00038   
00039   bool  IFileManager::loadParams( LoadParamFunc func )
00040     {
00041       static  std::vector<IFileManager::LoadParamFunc>  s_calls;
00042       
00043       if (func != 0)  s_calls.push_back(func);
00044       
00045       if ((!s_instance) || (!s_instance->m_file))       return false;
00046       
00047       // already initialized, handle the setup right now
00048       if (s_calls.size() > 0)   {
00049         // catch up on all loadParameters or similar calls
00050         // which were queued until an instance of the class was
00051         // created.
00052         std::vector<LoadParamFunc>::const_iterator      it = s_calls.begin();
00053         while (it != s_calls.end()) {
00054           (**it)(*s_instance->m_file);
00055           it++;
00056         }
00057         
00058         // if a re-initialization is desired, remove this line
00059         s_calls.clear();
00060       }
00061       return true;
00062     }
00063 
00064   void IFileManager::printOn(std::ostream& out)
00065     {
00066       if(m_file) m_file->printOn(out);
00067     }
00068   IFileManager::~IFileManager()
00069     {
00070       s_instance = 0;
00071       delete m_file;
00072     }
00073   
00074 } // end namespace xml
00075 
00076   

Generated at Wed Nov 21 12:22:26 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000