• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Directories
  • File List
  • File Members

xbm.hpp

Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2008 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023   contact: julien_jorge@yahoo.fr
00024 */
00030 #ifndef __CLAW_XBM_HPP__
00031 #define __CLAW_XBM_HPP__
00032 
00033 #include <claw/image.hpp>
00034 #include <iostream>
00035 #include <string>
00036 
00037 namespace claw
00038 {
00039   namespace graphic
00040   {
00045     class xbm : public image
00046     {
00047     public:
00048       /*----------------------------------------------------------------------*/
00053       class reader
00054       {
00055       public:
00056         reader( image& img );
00057         reader( image& img, std::istream& f );
00058         reader( xbm& img, std::istream& f );
00059         ~reader();
00060 
00061         void load( std::istream& f );
00062 
00063       private:
00064         void read_from_file( std::istream& f );
00065 
00066         void read_size( std::istream& f );
00067         unsigned int read_dim( const std::string& line ) const;
00068         unsigned int read_bits_per_entry( std::istream& f ) const;
00069         void read_name( std::istream& f );
00070         void read_pixels( std::istream& f, unsigned int bpe ) const;
00071 
00072         void read_line
00073         ( std::istream& f, std::string& line, char endchar ) const;
00074         void remove_comments
00075         ( std::istream& f, std::string& line, char endchar ) const;
00076 
00077       private:
00079         image& m_image;
00080 
00082         std::string m_name;
00083 
00085         claw::math::coordinate_2d<int>* m_hot;
00086 
00087       }; // class reader
00088 
00089       /*----------------------------------------------------------------------*/
00094       class writer
00095       {
00096       public:
00100         struct options
00101         {
00102         public:
00103           options();
00104 
00105           options( const std::string& n,
00106                    const claw::math::coordinate_2d<int>* h );
00107 
00108         public:
00110           std::string name;
00111 
00113           const claw::math::coordinate_2d<int>* hot;
00114 
00115         }; // options
00116 
00117       public:
00118         writer( const image& img );
00119         writer( const image& img, std::ostream& f,
00120                 const options& opt = options() );
00121         
00122         void save( std::ostream& f, const options& opt = options() ) const;
00123 
00124       private:
00125         void save_bits( std::ostream& f ) const;
00126 
00127       private:
00129         const image& m_image;
00130 
00131       }; // class writer
00132 
00133     public:
00134       xbm( unsigned int w, unsigned int h );
00135       xbm( const image& that );
00136       xbm( std::istream& f );
00137       ~xbm();
00138 
00139       void save( std::ostream& os ) const;
00140 
00141       void set_name( const std::string& name );
00142       void set_hot( const claw::math::coordinate_2d<int>& hot );
00143 
00144     private:
00146       std::string m_name;
00147 
00149       claw::math::coordinate_2d<int>* m_hot;
00150 
00151     }; // class xbm
00152   } // namespace graphic
00153 } // namespace claw
00154 
00155 #endif // __CLAW_XBM_HPP__

Generated on Thu Sep 30 2010 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.7.1