Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

IOManager.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *        Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen         *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *                                                                           *
00009  *                                License                                    *
00010  *                                                                           *
00011  *  This library is free software; you can redistribute it and/or modify it  *
00012  *  under the terms of the GNU Library General Public License as published   *
00013  *  by the Free Software Foundation, version 2.                              *
00014  *                                                                           *
00015  *  This library is distributed in the hope that it will be useful, but      *
00016  *  WITHOUT ANY WARRANTY; without even the implied warranty of               *
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
00018  *  Library General Public License for more details.                         *
00019  *                                                                           *
00020  *  You should have received a copy of the GNU Library General Public        *
00021  *  License along with this library; if not, write to the Free Software      *
00022  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                *
00023  *                                                                           *
00024 \*===========================================================================*/
00025 // $Id: IOManager.hh,v 1.8 2003/07/15 11:24:15 openmeshadm Exp $
00026 
00027 //=============================================================================
00028 //
00029 //  Implements the OpenMesh IOManager singleton
00030 //
00031 //=============================================================================
00032 
00033 #ifndef __IOMANAGER_HH__
00034 #define __IOMANAGER_HH__
00035 
00036 
00037 //=== INCLUDES ================================================================
00038 
00039 
00040 // STL
00041 #include <iostream>
00042 #include <sstream>
00043 #include <string>
00044 #include <set>
00045 
00046 // OpenMesh
00047 #include <OpenMesh/Core/System/config.h>
00048 #include <OpenMesh/Core/IO/Options.hh>
00049 #include <OpenMesh/Core/IO/reader/BaseReader.hh>
00050 #include <OpenMesh/Core/IO/writer/BaseWriter.hh>
00051 #include <OpenMesh/Core/IO/importer/BaseImporter.hh>
00052 #include <OpenMesh/Core/IO/exporter/BaseExporter.hh>
00053 #include <OpenMesh/Core/Utils/SingletonT.hh>
00054 
00055 
00056 //== NAMESPACES ===============================================================
00057 
00058 
00059 namespace OpenMesh {
00060 namespace IO {
00061 
00062 
00063 //=== IMPLEMENTATION ==========================================================
00064 
00065 
00085 class _IOManager_
00086 {
00087 public:
00088   
00089 
00096   bool read(const std::string& _filename, 
00097             BaseImporter& _bi, 
00098             Options& _opt);
00099 
00100 
00101 
00108   bool write(const std::string& _filename, 
00109              BaseExporter& _be,
00110              Options _opt=Options::Default);
00111 
00112    
00113 
00115   bool can_read( const std::string& _format ) const;
00116 
00118   bool can_write( const std::string& _format ) const;
00119 
00120    
00121   size_t binary_size(const std::string& _format, 
00122                      BaseExporter& _be,
00123                      Options _opt = Options::Default)
00124   {
00125     const BaseWriter *bw = find_writer(_format);
00126     return bw ? bw->binary_size(_be,_opt) : 0;
00127   }    
00128 
00129 
00130 
00131 public: //-- QT convenience function ------------------------------------------
00132    
00133 
00138   const std::string& qt_read_filters()  const { return read_filters_;  }
00139 
00140 
00145   const std::string& qt_write_filters() const { return write_filters_; }
00146 
00147 
00148 
00149 private:
00150 
00151   // collect all readable file extensions
00152   void update_read_filters();
00153 
00154 
00155   // collect all writeable file extensions
00156   void update_write_filters();
00157    
00158 
00159 
00160 public:  //-- SYSTEM PART------------------------------------------------------
00161 
00162 
00166   bool register_module(BaseReader* _bl)
00167   {
00168     reader_modules_.insert(_bl);
00169     update_read_filters();
00170     return true;
00171   }
00172 
00173 
00174   
00178   bool register_module(BaseWriter* _bw)
00179   {
00180     writer_modules_.insert(_bw);
00181     update_write_filters();
00182     return true;
00183   }
00184 
00185   
00186 private:
00187   
00188   const BaseWriter *find_writer(const std::string& _format);
00189   
00190   // stores registered reader modules
00191   std::set<BaseReader*> reader_modules_;
00192   
00193   // stores registered writer modules
00194   std::set<BaseWriter*> writer_modules_;
00195   
00196   // input filters (e.g. for Qt file dialog)
00197   std::string read_filters_;
00198   
00199   // output filters (e.g. for Qt file dialog)
00200   std::string write_filters_;
00201 };
00202 
00203 
00204 //=============================================================================
00205 
00206 
00211 typedef SingletonT<_IOManager_> IOManager;
00212 
00213 
00214 //=============================================================================
00215 } // namespace IO
00216 } // namespace OpenMesh
00217 //=============================================================================
00218 #endif
00219 //=============================================================================

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .