Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

ofxsCore.h

Go to the documentation of this file.
00001 #ifndef _ofxsCore_H_
00002 #define _ofxsCore_H_
00003 /*
00004 OFX Support Library, a library that skins the OFX plug-in API with C++ classes.
00005 Copyright (C) 2004-2005 The Foundry Visionmongers Ltd
00006 Author Bruno Nicoletti bruno@thefoundry.co.uk
00007 
00008 Redistribution and use in source and binary forms, with or without
00009 modification, are permitted provided that the following conditions are met:
00010 
00011 * Redistributions of source code must retain the above copyright notice,
00012 this list of conditions and the following disclaimer.
00013 * Redistributions in binary form must reproduce the above copyright notice,
00014 this list of conditions and the following disclaimer in the documentation
00015 and/or other materials provided with the distribution.
00016 * Neither the name The Foundry Visionmongers Ltd, nor the names of its 
00017 contributors may be used to endorse or promote products derived from this
00018 software without specific prior written permission.
00019 
00020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00021 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00024 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00027 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 
00031 The Foundry Visionmongers Ltd
00032 1 Wardour St
00033 London W1D 6PA
00034 England
00035 
00036 
00037 
00038 */
00039 
00040 
00086 #ifdef _MSC_VER
00087 #pragma warning( disable : 4290 )
00088 #endif
00089 
00090 #include "ofxCore.h"
00091 #include "ofxImageEffect.h"
00092 #include "ofxInteract.h"
00093 #include "ofxKeySyms.h"
00094 #include "ofxMemory.h"
00095 #include "ofxMessage.h"
00096 #include "ofxMultiThread.h"
00097 #include "ofxParam.h"
00098 #include "ofxProperty.h"
00099 
00100 #include <assert.h>
00101 #include <vector>
00102 #include <string>
00103 #include <map>
00104 #include <exception>
00105 #include <stdexcept>
00106 #include <sstream>
00107 
00108 #ifdef OFX_CLIENT_EXCEPTION_HEADER
00109 #include OFX_CLIENT_EXCEPTION_HEADER
00110 #endif
00111 
00116 struct OfxRGBColourB {
00117   unsigned char r, g, b;
00118 };
00119 
00124 struct OfxRGBColourS {
00125   unsigned short r, g, b;
00126 };
00127 
00132 struct OfxRGBColourF {
00133   float r, g, b;
00134 };
00135 
00140 struct OfxRGBColourD {
00141   double r, g, b;
00142 };
00143 
00148 struct Ofx3DPointI {
00149   int x, y, z;
00150 };
00151 
00156 struct Ofx3DPointD {
00157   double x, y, z;
00158 };
00159 
00161 #define mDeclareProtectedAssignAndCC(CLASS) \
00162   CLASS &operator=(const CLASS &v1) {assert(false); return *this;}      \
00163   CLASS(const CLASS &v) {assert(false); } 
00164 
00167 namespace OFX {
00169   class PropertySet;
00170 
00172   enum PropertyTypeEnum {
00173     ePointer,
00174     eInt,
00175     eString,
00176     eDouble
00177   };
00178 
00180   enum InstanceChangeReason {
00181     eChangeUserEdit,    
00182     eChangePluginEdit,  
00183     eChangeTime         
00184   };
00185 
00187   char * mapStatusToString(OfxStatus stat);
00188 
00190   namespace Exception {
00191 
00194     class Suite : public std::exception {
00195     protected :
00196       OfxStatus _status;
00197     public :
00198       Suite(OfxStatus s) : _status(s) {}
00199       OfxStatus status(void) {return _status;}
00200       operator OfxStatus() {return _status;}
00201 
00203       virtual const char * what () const throw () {return mapStatusToString(_status);}
00204 
00205     };
00206 
00208     class PropertyUnknownToHost : public std::exception {
00209     protected :
00210       std::string _what;
00211     public :
00212       PropertyUnknownToHost(const char *what) : _what(what) {}
00213       virtual ~PropertyUnknownToHost() throw() {}
00214 
00216       virtual const char * what () const throw ()
00217       {
00218         return _what.c_str();
00219       }
00220     };
00221 
00223     class PropertyValueIllegalToHost : public std::exception {
00224     protected :
00225       std::string _what;
00226     public :
00227       PropertyValueIllegalToHost(const char *what) : _what(what) {}
00228       virtual ~PropertyValueIllegalToHost() throw() {}
00229 
00231       virtual const char * what () const throw ()
00232       {
00233         return _what.c_str();
00234       }
00235     };
00236 
00240     class TypeRequest : public std::exception {
00241     protected :
00242       std::string _what;
00243     public :
00244       TypeRequest(const char *what) : _what(what) {}
00245       virtual ~TypeRequest() throw() {}
00246 
00248       virtual const char * what () const throw ()
00249       {
00250         return _what.c_str();
00251       }
00252     };
00253 
00255     // These exceptions are to be thrown by the plugin if it hits a problem, the
00256     // code managing the main entry will trap the exception and return a suitable 
00257     // status code to the host.
00258 
00260     class HostInadequate : public std::exception {
00261     protected :
00262       std::string _what;
00263     public :
00264       HostInadequate(char *what) : _what(what) {}
00265       virtual ~HostInadequate() throw() {}
00266 
00268       virtual const char * what () const throw ()
00269       {
00270         return _what.c_str();
00271       }
00272     };
00273 
00274   }; // end of Exception namespace
00275 
00277   void 
00278     throwSuiteStatusException(OfxStatus stat) 
00279     throw(OFX::Exception::Suite, std::bad_alloc);
00280 
00281   void 
00282     throwHostMissingSuiteException(std::string name) 
00283     throw(OFX::Exception::Suite);
00284 
00289   class ImageEffectDescriptor;
00290   class ImageEffect;
00291 
00293   class PropertySet {
00294   protected :
00296     OfxPropertySetHandle _propHandle;
00297 
00299     static int _gPropLogging;
00300 
00302     static bool _gThrowOnUnsupported;
00303 
00304   public :
00306     static void propEnableLogging(void)  {++_gPropLogging;}
00307 
00309     static void propDisableLogging(void) {--_gPropLogging;}
00310 
00312     static void setThrowOnUnsupportedProperties(bool v) {_gThrowOnUnsupported = v;}
00313 
00315     static bool getThrowOnUnsupportedProperties(void) {return _gThrowOnUnsupported;}
00316 
00318     PropertySet(OfxPropertySetHandle h = 0) : _propHandle(h) {}
00319     virtual ~PropertySet();
00320 
00322     void propSetHandle(OfxPropertySetHandle h) { _propHandle = h;}
00323 
00325     OfxPropertySetHandle propSetHandle(void) {return _propHandle;}
00326 
00327     int  propGetDimension(const char* property, bool throwOnFailure = true) const throw(std::bad_alloc, 
00328       OFX::Exception::PropertyUnknownToHost, 
00329       OFX::Exception::PropertyValueIllegalToHost, 
00330       OFX::Exception::Suite);
00331     void propReset(const char* property) throw(std::bad_alloc, 
00332       OFX::Exception::PropertyUnknownToHost, 
00333       OFX::Exception::PropertyValueIllegalToHost,
00334       OFX::Exception::Suite);
00335 
00336     // set single values
00337     void propSetPointer(const char* property, void *value, int idx, bool throwOnFailure = true) throw(std::bad_alloc, 
00338       OFX::Exception::PropertyUnknownToHost, 
00339       OFX::Exception::PropertyValueIllegalToHost, 
00340       OFX::Exception::Suite);
00341     void propSetString(const char* property, const std::string &value, int idx, bool throwOnFailure = true) throw(std::bad_alloc, 
00342       OFX::Exception::PropertyUnknownToHost, 
00343       OFX::Exception::PropertyValueIllegalToHost, 
00344       OFX::Exception::Suite);
00345     void propSetDouble(const char* property, double value, int idx, bool throwOnFailure = true) throw(std::bad_alloc, 
00346       OFX::Exception::PropertyUnknownToHost, 
00347       OFX::Exception::PropertyValueIllegalToHost, 
00348       OFX::Exception::Suite);
00349     void propSetInt(const char* property, int value, int idx, bool throwOnFailure = true) throw(std::bad_alloc, 
00350       OFX::Exception::PropertyUnknownToHost, 
00351       OFX::Exception::PropertyValueIllegalToHost, 
00352       OFX::Exception::Suite);
00353 
00354     void propSetPointer(const char* property, void *value, bool throwOnFailure = true) throw(std::bad_alloc, 
00355       OFX::Exception::PropertyUnknownToHost, 
00356       OFX::Exception::PropertyValueIllegalToHost, 
00357       OFX::Exception::Suite)
00358     {propSetPointer(property, value, 0, throwOnFailure);}
00359 
00360     void propSetString(const char* property, const std::string &value, bool throwOnFailure = true) throw(std::bad_alloc, 
00361       OFX::Exception::PropertyUnknownToHost, 
00362       OFX::Exception::PropertyValueIllegalToHost, 
00363       OFX::Exception::Suite)
00364     {propSetString(property, value, 0, throwOnFailure);}
00365 
00366     void propSetDouble(const char* property, double value, bool throwOnFailure = true) throw(std::bad_alloc, 
00367       OFX::Exception::PropertyUnknownToHost, 
00368       OFX::Exception::PropertyValueIllegalToHost, 
00369       OFX::Exception::Suite)
00370     {propSetDouble(property, value, 0, throwOnFailure);}
00371 
00372     void propSetInt(const char* property, int value, bool throwOnFailure = true) throw(std::bad_alloc, 
00373       OFX::Exception::PropertyUnknownToHost, 
00374       OFX::Exception::PropertyValueIllegalToHost, 
00375       OFX::Exception::Suite)
00376     {propSetInt(property, value, 0, throwOnFailure);}
00377 
00378 
00380     void       *propGetPointer(const char* property, int idx, bool throwOnFailure = true) const throw(std::bad_alloc, 
00381       OFX::Exception::PropertyUnknownToHost, 
00382       OFX::Exception::PropertyValueIllegalToHost, 
00383       OFX::Exception::Suite);
00384 
00386     std::string propGetString(const char* property, int idx, bool throwOnFailure = true) const throw(std::bad_alloc, 
00387       OFX::Exception::PropertyUnknownToHost, 
00388       OFX::Exception::PropertyValueIllegalToHost, 
00389       OFX::Exception::Suite);
00391     double      propGetDouble(const char* property, int idx, bool throwOnFailure = true) const throw(std::bad_alloc, 
00392       OFX::Exception::PropertyUnknownToHost, 
00393       OFX::Exception::PropertyValueIllegalToHost, 
00394       OFX::Exception::Suite);
00395 
00397     int propGetInt(const char* property, int idx, bool throwOnFailure = true) const throw(std::bad_alloc, 
00398       OFX::Exception::PropertyUnknownToHost, 
00399       OFX::Exception::PropertyValueIllegalToHost, 
00400       OFX::Exception::Suite);
00401 
00403     void* propGetPointer(const char* property, bool throwOnFailure = true) const throw(std::bad_alloc, 
00404       OFX::Exception::PropertyUnknownToHost, 
00405       OFX::Exception::PropertyValueIllegalToHost, 
00406       OFX::Exception::Suite)
00407     {
00408       return propGetPointer(property, 0, throwOnFailure); 
00409     }
00410 
00412     std::string propGetString(const char* property, bool throwOnFailure = true) const throw(std::bad_alloc, 
00413       OFX::Exception::PropertyUnknownToHost, 
00414       OFX::Exception::PropertyValueIllegalToHost, 
00415       OFX::Exception::Suite)
00416     {
00417       return propGetString(property, 0, throwOnFailure); 
00418     }
00419 
00421     double propGetDouble(const char* property, bool throwOnFailure = true) const throw(std::bad_alloc, 
00422       OFX::Exception::PropertyUnknownToHost, 
00423       OFX::Exception::PropertyValueIllegalToHost, 
00424       OFX::Exception::Suite)
00425     {
00426       return propGetDouble(property, 0, throwOnFailure); 
00427     }
00428 
00430     int propGetInt(const char* property, bool throwOnFailure = true) const throw(std::bad_alloc, 
00431       OFX::Exception::PropertyUnknownToHost, 
00432       OFX::Exception::PropertyValueIllegalToHost, 
00433       OFX::Exception::Suite)
00434     {
00435       return propGetInt(property, 0, throwOnFailure); 
00436     }
00437   };
00438 
00439   // forward decl of the image effect
00440   class ImageEffect;
00441 
00443   namespace Memory {
00445     void *alloc(size_t nBytes,
00446       ImageEffect *handle = 0) throw(std::bad_alloc);
00447 
00449     void free(void *ptr) throw();
00450 
00451   };
00452 };
00453 
00454 // undeclare the protected assign and CC macro
00455 #undef mDeclareProtectedAssignAndCC
00456 
00457 #endif

Generated on Thu Oct 9 13:03:49 2008 for OFX Support by  doxygen 1.3.9.1