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

IOManager.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2005 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.2 2004/10/14 12:43:53 botsch 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.hh>
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 private:
00088   
00089   _IOManager_() {}
00090   friend _IOManager_& IOManager();
00091 
00092 
00093 public:
00094 
00095 
00102   bool read(const std::string& _filename, 
00103             BaseImporter& _bi, 
00104             Options& _opt);
00105 
00106 
00107 
00114   bool write(const std::string& _filename, 
00115              BaseExporter& _be,
00116              Options _opt=Options::Default);
00117 
00118    
00119 
00121   bool can_read( const std::string& _format ) const;
00122 
00124   bool can_write( const std::string& _format ) const;
00125 
00126    
00127   size_t binary_size(const std::string& _format, 
00128                      BaseExporter& _be,
00129                      Options _opt = Options::Default)
00130   {
00131     const BaseWriter *bw = find_writer(_format);
00132     return bw ? bw->binary_size(_be,_opt) : 0;
00133   }    
00134 
00135 
00136 
00137 public: //-- QT convenience function ------------------------------------------
00138    
00139 
00144   const std::string& qt_read_filters()  const { return read_filters_;  }
00145 
00146 
00151   const std::string& qt_write_filters() const { return write_filters_; }
00152 
00153 
00154 
00155 private:
00156 
00157   // collect all readable file extensions
00158   void update_read_filters();
00159 
00160 
00161   // collect all writeable file extensions
00162   void update_write_filters();
00163    
00164 
00165 
00166 public:  //-- SYSTEM PART------------------------------------------------------
00167 
00168 
00172   bool register_module(BaseReader* _bl)
00173   {
00174     reader_modules_.insert(_bl);
00175     update_read_filters();
00176     return true;
00177   }
00178 
00179 
00180   
00184   bool register_module(BaseWriter* _bw)
00185   {
00186     writer_modules_.insert(_bw);
00187     update_write_filters();
00188     return true;
00189   }
00190 
00191   
00192 private:
00193   
00194   const BaseWriter *find_writer(const std::string& _format);
00195   
00196   // stores registered reader modules
00197   std::set<BaseReader*> reader_modules_;
00198   
00199   // stores registered writer modules
00200   std::set<BaseWriter*> writer_modules_;
00201   
00202   // input filters (e.g. for Qt file dialog)
00203   std::string read_filters_;
00204   
00205   // output filters (e.g. for Qt file dialog)
00206   std::string write_filters_;
00207 };
00208 
00209 
00210 //=============================================================================
00211 
00212 
00213 extern _IOManager_*  __IOManager_instance;
00214 
00215 _IOManager_& IOManager();
00216 
00217 
00218 
00219 //=============================================================================
00220 } // namespace IO
00221 } // namespace OpenMesh
00222 //=============================================================================
00223 #endif
00224 //=============================================================================

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