TuttleOFX  1
LutReader.hpp
Go to the documentation of this file.
00001 #ifndef _LUTENGINE_LUTREADER_HPP_
00002 #define _LUTENGINE_LUTREADER_HPP_
00003 
00004 #include <tuttle/plugin/memory/OfxAllocator.hpp>
00005 
00006 #include <boost/filesystem/path.hpp>
00007 #include <boost/spirit/include/classic.hpp>
00008 #include <boost/spirit/include/classic_core.hpp>
00009 #include <boost/spirit/include/classic.hpp>
00010 #include <boost/spirit/include/classic_assign_actor.hpp>
00011 #include <boost/spirit/include/classic_core.hpp>
00012 #include <boost/function.hpp>
00013 
00014 #include <vector>
00015 
00016 namespace tuttle {
00017 
00018 using namespace boost;
00019 namespace fs = boost::filesystem;
00020 
00021 class LutReader
00022 {
00023 public:
00024         typedef std::vector<double, tuttle::plugin::OfxAllocator<double> > VectorDouble;
00025 protected:
00026         VectorDouble _data;
00027         VectorDouble _steps;
00028         bool _bReadOk;
00029 
00030 public:
00031         LutReader() : _bReadOk( false ) {}
00032         virtual ~LutReader() {}
00033 
00034         /// Set 3DL filename
00035         bool read( const fs::path& filename );
00036         /// Is a file read success
00037         const bool           readOk() const { return _bReadOk; }
00038         VectorDouble& data()         { return _data; }
00039         VectorDouble& steps()        { return _steps; }
00040 };
00041 
00042 // 3DL File parser
00043 struct gram_3dl : public boost::spirit::classic::grammar<gram_3dl>
00044 {
00045         gram_3dl( LutReader& lutReader )
00046                 : _lutReader( lutReader )
00047         {}
00048 
00049         template <typename ScannerT>
00050         struct definition
00051         {
00052                 definition( const gram_3dl& self )
00053                 {
00054                         using namespace boost::spirit::classic;
00055                         gram_3dl_spec     = *gram_comment >> gram_line_quantiz >> +( gram_comment | gram_rgb | space_p );
00056                         gram_rgb          = *blank_p >> *( uint_p[ push_back_a( self._lutReader.data() ) ] % *blank_p ) >> +space_p;
00057                         gram_line_quantiz = *blank_p >> *( uint_p[ push_back_a( self._lutReader.steps() ) ] % *blank_p ) >> +space_p;
00058                         gram_comment      = *blank_p >> ch_p( '#' ) >> *( anychar_p - '\n' ) >> +space_p;
00059                 }
00060 
00061                 boost::spirit::classic::rule<ScannerT> gram_test, gram_comment, gram_line_quantiz, gram_rgb, gram_3dl_spec;
00062                 boost::spirit::classic::rule<ScannerT> const& start() const { return gram_3dl_spec; }
00063         };
00064 
00065         LutReader& _lutReader;
00066 };
00067 
00068 }
00069 
00070 #endif