TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/host/ofx/OfxhPluginDesc.hpp
Go to the documentation of this file.
00001 #ifndef _OFXH_PLUGINDESC_HPP_
00002 #define _OFXH_PLUGINDESC_HPP_
00003 
00004 #include <ofxCore.h>
00005 
00006 #include <boost/algorithm/string.hpp>
00007 #include <boost/serialization/serialization.hpp>
00008 #include <boost/serialization/nvp.hpp>
00009 #include <boost/serialization/export.hpp>
00010 #include <boost/serialization/string.hpp>
00011 
00012 namespace tuttle {
00013 namespace host {
00014 namespace ofx {
00015 
00016 struct OfxhPluginIdent
00017 {
00018         OfxhPluginIdent()
00019                 : _versionMinor( 0 )
00020                 , _versionMajor( 0 ) {}
00021         OfxhPluginIdent( const std::string& identifier, const std::string& rawId, int verMin, int verMax )
00022                 : _identifier( identifier )
00023                 , _rawIdentifier( rawId )
00024                 , _versionMinor( verMin )
00025                 , _versionMajor( verMax )
00026         {}
00027 
00028         bool operator<( const OfxhPluginIdent& d2 ) const
00029         {
00030                 return _identifier < d2._identifier ||
00031                        ( _identifier == d2._identifier && _versionMajor < d2._versionMajor ) ||
00032                        ( _identifier == d2._identifier && _versionMajor == d2._versionMajor && _versionMinor < d2._versionMinor );
00033         }
00034 
00035         bool operator!=( const OfxhPluginIdent& d2 ) const
00036         {
00037                 return _identifier != d2._identifier &&
00038                        _rawIdentifier != d2._rawIdentifier &&
00039                        _versionMinor != d2._versionMinor &&
00040                        _versionMajor != d2._versionMajor;
00041         }
00042 
00043         std::string _identifier;
00044         std::string _rawIdentifier;
00045         int _versionMinor, _versionMajor;
00046 };
00047 
00048 /**
00049  * C++ version of the information kept inside an OfxPlugin struct
00050  */
00051 class OfxhPluginDesc
00052 {
00053 public:
00054         typedef OfxhPluginDesc This;
00055 
00056 protected:
00057         std::string _pluginApi; ///< the API I implement
00058         int _apiVersion; ///< the version of the API
00059 
00060         OfxhPluginIdent _ident; ///< The plugin identity
00061 
00062 public:
00063         OfxhPluginDesc();
00064 
00065         OfxhPluginDesc( const std::string& api,
00066                         int                apiVersion,
00067                         const std::string& identifier,
00068                         const std::string& rawIdentifier,
00069                         int                versionMajor,
00070                         int                versionMinor );
00071 
00072         /**
00073          * constructor for the case where we have already loaded the plugin binary and
00074          * are populating this object from it
00075          */
00076         OfxhPluginDesc( OfxPlugin& ofxPlugin );
00077 
00078         virtual ~OfxhPluginDesc();
00079 
00080         bool operator==( const This& other ) const;
00081         bool operator!=( const This& other ) const { return !This::operator==( other ); }
00082 
00083 public:
00084         const std::string& getPluginApi() const
00085         {
00086                 return _pluginApi;
00087         }
00088 
00089         int getApiVersion() const
00090         {
00091                 return _apiVersion;
00092         }
00093 
00094         const OfxhPluginIdent& getIdentity() const
00095         {
00096                 return _ident;
00097         }
00098 
00099         OfxhPluginIdent& getIdentity()
00100         {
00101                 return _ident;
00102         }
00103 
00104         const std::string& getIdentifier() const
00105         {
00106                 return _ident._identifier;
00107         }
00108 
00109         const std::string& getRawIdentifier() const
00110         {
00111                 return _ident._rawIdentifier;
00112         }
00113 
00114         int getVersionMajor() const
00115         {
00116                 return _ident._versionMajor;
00117         }
00118 
00119         int getVersionMinor() const
00120         {
00121                 return _ident._versionMinor;
00122         }
00123         
00124         std::size_t getHash() const;
00125         
00126 private:
00127         friend class boost::serialization::access;
00128         template<class Archive>
00129         void serialize( Archive& ar, const unsigned int version )
00130         {
00131                 ar& BOOST_SERIALIZATION_NVP( _pluginApi );
00132                 ar& BOOST_SERIALIZATION_NVP( _apiVersion );
00133                 //              ar & BOOST_SERIALIZATION_NVP(_ident._identifier);
00134                 ar& BOOST_SERIALIZATION_NVP( _ident._rawIdentifier );
00135                 ar& BOOST_SERIALIZATION_NVP( _ident._versionMajor );
00136                 ar& BOOST_SERIALIZATION_NVP( _ident._versionMinor );
00137 
00138                 if( typename Archive::is_loading() )
00139                 {
00140                         _ident._identifier = _ident._rawIdentifier;
00141                         boost::to_lower( _ident._identifier );
00142                 }
00143         }
00144 
00145 };
00146 
00147 }
00148 }
00149 }
00150 
00151 #ifndef SWIG
00152 BOOST_SERIALIZATION_ASSUME_ABSTRACT( tuttle::host::ofx::OfxhPluginDesc )
00153 #endif
00154 
00155 #endif
00156