Katana Plug-in APIs 0.1

FnFileSequence.h

00001 // Copyright (c) 2012 The Foundry Visionmongers Ltd. All Rights Reserved.
00002 
00003 #ifndef FNFILESEQ__H
00004 #define FNFILESEQ__H
00005 
00006 #include <memory>
00007 #include <string>
00008 #include <vector>
00009 
00010 #include <FnAttribute/FnAttribute.h>
00011 #include <FnPlatform/internal/Portability.h>
00012 #include <FnPlatform/internal/UniquePtr.h>
00013 #include <FnPluginSystem/FnPlugin.h>
00014 #include <FnPluginSystem/FnPluginSystem.h>
00015 
00016 #include <FnAsset/FnAssetAPI.h>
00017 #include <FnAsset/suite/FnAssetSuite.h>
00018 
00019 namespace Foundry
00020 {
00021   namespace Katana
00022   {
00023     class FileSequenceArray;
00024 
00067     class FNASSET_API FileSequence
00068     {
00069     public:
00070         FileSequence() {}
00071         FNKAT_DEPRECATED FileSequence(const std::string& /*fileseq*/)
00072         { /* Empty */
00073         }
00074         virtual ~FileSequence()
00075         { /* Empty */
00076         }
00077 
00080         virtual bool isValid() const = 0;
00081 
00083         virtual FileSequence* clone() const = 0;
00084 
00089         virtual void getAsString(std::string& retValue) = 0;
00090 
00096         virtual void getDirectory(std::string& retValue) = 0;
00097 
00103         virtual void getPrefix(std::string& retValue) = 0;
00104 
00110         virtual void getSuffix(std::string& retValue) = 0;
00111 
00117         virtual unsigned int getPadding() = 0;
00118 
00125         virtual void getResolvedPath(const int frame,
00126                                      std::string& retValue) = 0;
00127 
00133         virtual bool hasFrameSet() = 0;
00134 
00140         virtual bool isFrameInFrameSet(const int frame) = 0;
00141 
00147         virtual int getFirstFrameInFrameSet() = 0;
00148 
00154         virtual int getLastFrameInFrameSet() = 0;
00155 
00171         virtual void getNearestFramesInFrameSet(int frame,
00172                                                 bool* hasLeft,
00173                                                 int* nearestLeft,
00174                                                 bool* hasRight,
00175                                                 int* nearestRight) = 0;
00176 
00182         virtual void getFrameListFromFrameSet(std::vector<int>& returnList) = 0;
00183 
00185         static FnPlugStatus setHost(FnPluginHost* host);
00186         static FnPluginHost* getHost();
00187 
00188         static FnFileSequencePluginSuite_v1 createSuite(
00189             FnFileSequenceHandle (*create)(const char*,
00190                                            FnAttributeHandle* errorMessage),
00191             bool (*isFileSequence)(const char*,
00192                                    FnAttributeHandle* errorMessage),
00193             FnAttributeHandle (*buildFileSequenceString)(
00194                 const char* prefix,
00195                 const char* suffix,
00196                 int padding,
00197                 FnAttributeHandle* errorMessage),
00198             FnFileSequenceArrayHandle (*findSequence)(
00199                 const char** fileList,
00200                 unsigned int fileCount,
00201                 FnAttributeHandle* errorMessage));
00202 
00203         static FnFileSequenceHandle newFileSequenceHandle(FileSequence* fs);
00204         static FnFileSequenceArrayHandle newFileSequenceArrayHandle(
00205             FileSequenceArray* fs);
00206 
00207         static unsigned int _apiVersion;
00208         static const char* _apiName;
00209 
00210     private:
00211       static FnPluginHost *_host;
00212 
00214     };
00215 
00221     class FNASSET_API FileSequenceArray
00222     {
00223     public:
00224       FileSequenceArray(std::vector<FileSequence*>& seq, std::vector<std::string>& nonseq) :
00225         _seq(seq),
00226         _nonseq(nonseq)
00227       {
00228         // Empty
00229       }
00230 
00231       virtual ~FileSequenceArray()
00232       {
00233         for (unsigned int i=0; i<_seq.size(); ++i)
00234         {
00235           delete _seq[i];
00236           _seq[i] = 0;
00237         }
00238         _seq.clear();
00239       }
00240 
00244       virtual int getFileSequenceCount()
00245       {
00246         return _seq.size();
00247       }
00248 
00253       virtual FileSequence* getFileSequence(const unsigned int index)
00254       {
00255         return _seq[index];
00256       }
00257 
00261       virtual void getFileNames(std::vector<std::string>& fileNames)
00262       {
00263         fileNames = _nonseq;
00264       }
00265 
00266     private:
00267       std::vector<FileSequence*>        _seq;
00268       std::vector<std::string>          _nonseq;
00269     };
00270 
00273   };  // namespace Katana
00274 }; // namespace Foundry
00275 
00276 namespace FnKat = Foundry::Katana;
00277 
00279 
00280 // Plugin Registering Macro.
00281 
00282 #define DEFINE_FS_PLUGIN(FS_CLASS)                                                              \
00283                                                                                                 \
00284   FnPlugin FS_CLASS##_plugin;                                                                   \
00285                                                                                                 \
00286   FnFileSequenceHandle FS_CLASS##_create(const char* fileseq, FnAttributeHandle *errorMessage)  \
00287   {                                                                                             \
00288     try                                                                                         \
00289     {                                                                                           \
00290       return Foundry::Katana::FileSequence::newFileSequenceHandle(FS_CLASS::create(fileseq));   \
00291     }                                                                                           \
00292     catch (std::exception & e)                                                                  \
00293     {                                                                                           \
00294       Foundry::Katana::Attribute errorAttr = Foundry::Katana::StringAttribute(e.what());        \
00295       *errorMessage = errorAttr.getRetainedHandle();                                            \
00296       return 0x0;                                                                               \
00297     }                                                                                           \
00298   }                                                                                             \
00299                                                                                                 \
00300   bool FS_CLASS##_isFileSequence(const char* fileseq, FnAttributeHandle *errorMessage)          \
00301   {                                                                                             \
00302     try                                                                                         \
00303     {                                                                                           \
00304       return FS_CLASS::isFileSequence(fileseq);                                                 \
00305     }                                                                                           \
00306     catch (std::exception & e)                                                                  \
00307     {                                                                                           \
00308       Foundry::Katana::Attribute errorAttr = Foundry::Katana::StringAttribute(e.what());        \
00309       *errorMessage = errorAttr.getRetainedHandle();                                            \
00310       return false;                                                                             \
00311     }                                                                                           \
00312   }                                                                                             \
00313                                                                                                 \
00314                                                                                                 \
00315   FnAttributeHandle FS_CLASS##_buildFileSequenceString(const char *prefix,                      \
00316                                                        const char *suffix,                      \
00317                                                        int padding,                             \
00318                                                        FnAttributeHandle *errorMessage)         \
00319   {                                                                                             \
00320     try                                                                                         \
00321     {                                                                                           \
00322       std::string prefixStr = std::string(prefix);                                              \
00323       std::string suffixStr  = std::string(suffix);                                             \
00324       std::string fileSeqStr = FS_CLASS::buildFileSequenceString(prefixStr, suffixStr, padding);\
00325       FnAttribute::Attribute resultAttr = FnAttribute::StringAttribute(fileSeqStr.c_str());     \
00326       return resultAttr.getRetainedHandle();                                                    \
00327     }                                                                                           \
00328     catch (std::exception & e)                                                                  \
00329     {                                                                                           \
00330       Foundry::Katana::Attribute errorAttr = Foundry::Katana::StringAttribute(e.what());        \
00331       *errorMessage = errorAttr.getRetainedHandle();                                            \
00332       return 0x0;                                                                               \
00333     }                                                                                           \
00334   }                                                                                             \
00335                                                                                                 \
00336                                                                                                 \
00337   FnFileSequenceArrayHandle FS_CLASS##_findSequence(const char** fileList,                      \
00338                                                     unsigned int fileCount,                     \
00339                                                     FnAttributeHandle *errorMessage)            \
00340   {                                                                                             \
00341     try                                                                                         \
00342     {                                                                                           \
00343       return Foundry::Katana::FileSequence::newFileSequenceArrayHandle(                         \
00344         FS_CLASS::findSequence(fileList, fileCount));                                           \
00345     }                                                                                           \
00346     catch (std::exception & e)                                                                  \
00347     {                                                                                           \
00348       Foundry::Katana::Attribute errorAttr = Foundry::Katana::StringAttribute(e.what());        \
00349       *errorMessage = errorAttr.getRetainedHandle();                                            \
00350       return 0x0;                                                                               \
00351     }                                                                                           \
00352   }                                                                                             \
00353                                                                                                 \
00354   FnFileSequencePluginSuite_v1 FS_CLASS##_suite =                                               \
00355     Foundry::Katana::FileSequence::createSuite(FS_CLASS##_create,                               \
00356                                                FS_CLASS##_isFileSequence,                       \
00357                                                FS_CLASS##_buildFileSequenceString,              \
00358                                                FS_CLASS##_findSequence);                        \
00359                                                                                                 \
00360   const void* FS_CLASS##_getSuite()                                                             \
00361   {                                                                                             \
00362     return &FS_CLASS##_suite;                                                                   \
00363   }                                                                                             \
00364 
00365 
00366 
00367 struct FnFileSequenceStruct
00368 {
00369 public:
00370   FnFileSequenceStruct(Foundry::Katana::FileSequence *context) :
00371     _fileSequence(context)
00372   {
00373     // Empty
00374   }
00375 
00376   ~FnFileSequenceStruct() { /* Empty */ };
00377 
00378   Foundry::Katana::FileSequence& getFileSequence()
00379   {
00380     return *_fileSequence;
00381   }
00382 
00383 private:
00384   FnPlatform::internal::UniquePtr<Foundry::Katana::FileSequence>::type
00385       _fileSequence;
00386 };
00387 
00388 struct FnFileSequenceArrayStruct
00389 {
00390   public:
00391     FnFileSequenceArrayStruct(Foundry::Katana::FileSequenceArray* context) :
00392       _fileSequenceArray(context)
00393     {
00394       // Empty
00395     }
00396 
00397     ~FnFileSequenceArrayStruct()
00398     {
00399       // Empty
00400     }
00401 
00402     Foundry::Katana::FileSequenceArray& getFileSequenceArray()
00403     {
00404       return *_fileSequenceArray;
00405     }
00406 
00407   private:
00408     FnPlatform::internal::UniquePtr<Foundry::Katana::FileSequenceArray>::type
00409         _fileSequenceArray;
00410 };
00411 
00412 
00414 
00415 #endif  // #ifndef FNFILESEQ__H
 All Classes Functions Variables Typedefs Enumerations Enumerator