OpenMesh
OpenMesh/Core/IO/Options.hh
00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *  This file is part of OpenMesh.                                           *
00009  *                                                                           *
00010  *  OpenMesh is free software: you can redistribute it and/or modify         * 
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenMesh is distributed in the hope that it will be useful,              *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenMesh.  If not,                                    *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/ 
00034 
00035 /*===========================================================================*\
00036  *                                                                           *             
00037  *   $Revision: 362 $                                                         *
00038  *   $Date: 2011-01-26 10:21:12 +0100 (Mi, 26 Jan 2011) $                   *
00039  *                                                                           *
00040 \*===========================================================================*/
00041 
00042 
00043 #ifndef OPENMESH_IO_OPTIONS_HH
00044 #define OPENMESH_IO_OPTIONS_HH
00045 
00046 
00047 //=== INCLUDES ================================================================
00048 
00049 
00050 // OpenMesh
00051 #include <OpenMesh/Core/System/config.h>
00052 
00053 
00054 //== NAMESPACES ==============================================================
00055 
00056 
00057 namespace OpenMesh {
00058 namespace IO   {
00059 
00060 
00061 //=== IMPLEMENTATION ==========================================================
00062 
00063 
00068 
00069 
00070 //-----------------------------------------------------------------------------
00071 
00088 class Options
00089 {
00090 public:
00091   typedef int       enum_type;
00092   typedef enum_type value_type;
00093    
00096   enum Flag {
00097       Default        = 0x0000, 
00098       Binary         = 0x0001, 
00099       MSB            = 0x0002, 
00100       LSB            = 0x0004, 
00101       Swap           = 0x0006, 
00102       VertexNormal   = 0x0010, 
00103       VertexColor    = 0x0020, 
00104       VertexTexCoord = 0x0040, 
00105       EdgeColor      = 0x0080, 
00106       FaceNormal     = 0x0100, 
00107       FaceColor      = 0x0200, 
00108       ColorAlpha     = 0x0400  
00109   };
00110 
00111 public:
00112 
00114   Options() : flags_( Default )
00115   { }
00116 
00117 
00119   Options(const Options& _opt) : flags_(_opt.flags_)
00120   { }
00121    
00122 
00124   Options(Flag _flg) : flags_( _flg)
00125   { }
00126 
00127    
00129   Options(const value_type _flgs) : flags_( _flgs)
00130   { }
00131 
00132    
00133   ~Options()
00134   { }
00135    
00137   void cleanup(void)
00138   { flags_ = Default; }
00139 
00141   void clear(void)
00142   { flags_ = 0; }
00143 
00145   bool is_empty(void) const { return !flags_; }
00146 
00147 public:
00148    
00149 
00151 
00152 
00153   Options& operator = ( const Options& _rhs )
00154   { flags_ = _rhs.flags_; return *this; }
00155 
00156   Options& operator = ( const value_type _rhs )
00157   { flags_ = _rhs; return *this; }
00158 
00160 
00161   
00163 
00164 
00165   Options& operator -= ( const value_type _rhs )
00166   { flags_ &= ~_rhs; return *this; }
00167 
00168   Options& unset( const value_type _rhs)
00169   { return (*this -= _rhs); }   
00170 
00172 
00173    
00174 
00176 
00177    
00178   Options& operator += ( const value_type _rhs )
00179   { flags_ |= _rhs; return *this; }
00180 
00181   Options& set( const value_type _rhs)
00182   { return (*this += _rhs); }
00183 
00185 
00186 public:
00187 
00188 
00189   // Check if an option or several options are set.
00190   bool check(const value_type _rhs) const
00191   {
00192     return (flags_ & _rhs)==_rhs;
00193   }
00194    
00195   bool is_binary()           const { return check(Binary); }
00196   bool vertex_has_normal()   const { return check(VertexNormal); }
00197   bool vertex_has_color()    const { return check(VertexColor); }
00198   bool vertex_has_texcoord() const { return check(VertexTexCoord); }
00199   bool edge_has_color()      const { return check(EdgeColor); }
00200   bool face_has_normal()     const { return check(FaceNormal); }
00201   bool face_has_color()      const { return check(FaceColor); }
00202   bool color_has_alpha()     const { return check(ColorAlpha); }
00203 
00204 
00206   bool operator == (const value_type _rhs) const
00207   { return flags_ == _rhs; }
00208    
00209 
00211   bool operator != (const value_type _rhs) const
00212   { return flags_ != _rhs; }
00213    
00214 
00216   operator value_type ()     const { return flags_; }
00217    
00218 private:
00219    
00220   bool operator && (const value_type _rhs) const;
00221    
00222   value_type flags_;
00223 };
00224 
00225 //-----------------------------------------------------------------------------
00226 
00227 
00228 
00229 
00231 
00232 
00233 //=============================================================================
00234 } // namespace IO
00235 } // namespace OpenMesh
00236 //=============================================================================
00237 #endif
00238 //=============================================================================
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines