TuttleOFX  1
commonDefinitions.hpp
Go to the documentation of this file.
00001 #ifndef _SEQUENCE_PARSER_COMMON_DEFINITIONS_HPP
00002 #define _SEQUENCE_PARSER_COMMON_DEFINITIONS_HPP
00003 
00004 #include <string>
00005 #include <cstddef>
00006 
00007 #ifdef _MSC_VER
00008 #include <BaseTsd.h>
00009 #else
00010 #include <unistd.h>
00011 #endif
00012 
00013 // compatibility problems...
00014 namespace std {
00015 #ifdef _MSC_VER
00016 typedef SSIZE_T ssize_t;
00017 #else
00018 typedef ::ssize_t ssize_t;
00019 #endif
00020 }
00021 
00022 
00023 
00024 namespace sequenceParser {
00025 
00026 #ifndef PROPERTIES_WIDTH
00027 #define PROPERTIES_WIDTH 3
00028 #endif
00029 
00030 #ifndef NAME_WIDTH
00031 #define NAME_WIDTH 50
00032 #endif
00033 
00034 #ifndef NAME_WIDTH_WITH_DIR
00035 #define NAME_WIDTH_WITH_DIR 80
00036 #endif
00037 
00038 
00039 #ifndef SEQUENCE_PARSER_OUTPUT_COLOR_FILES
00040 #define SEQUENCE_PARSER_OUTPUT_COLOR_FILES
00041 #if (defined __UNIX__ || defined UNIX || defined __LINUX__ || defined LINUX )
00042 static const std::string kColorStd = "\E[0;0m";
00043 static const std::string kColorFolder = "\E[1;34m";
00044 static const std::string kColorFile = "\E[0;32m";
00045 static const std::string kColorSequence = "\E[0;32m";
00046 static const std::string kColorError = "\E[1;31m";
00047 #else
00048 static const std::string kColorStd = "";
00049 static const std::string kColorFolder = "";
00050 static const std::string kColorFile = "";
00051 static const std::string kColorSequence = "";
00052 static const std::string kColorError = "";
00053 #endif
00054 #endif
00055 
00056 typedef std::ssize_t Time;
00057 
00058 /**
00059  * List all recognized pattern types.
00060  */
00061 enum EMaskType
00062 {
00063 
00064         eMaskTypeUndefined = 0,
00065         eMaskTypeDirectory = 1,
00066         eMaskTypeFile = eMaskTypeDirectory * 2,
00067         eMaskTypeSequence = eMaskTypeFile * 2,
00068         eMaskTypeDefault = eMaskTypeSequence
00069 };
00070 
00071 enum EMaskOptions
00072 {
00073 
00074         eMaskOptionsNone = 0, // 0
00075         eMaskOptionsProperties = 1, // show type of FileObject
00076         eMaskOptionsPath = eMaskOptionsProperties * 2, // show path of FileObject
00077         eMaskOptionsAbsolutePath = eMaskOptionsPath * 2, // show absolute path of FileObject
00078         eMaskOptionsRecursive = eMaskOptionsAbsolutePath * 2, // show recurssive listing
00079         eMaskOptionsNegativeIndexes = eMaskOptionsRecursive * 2, // show negative indexes sequences ( seq.-0020.jpg)
00080         eMaskOptionsSequenceBasedOnFilename = eMaskOptionsNegativeIndexes * 2, // list sequence based on a filename of the sequence
00081         eMaskOptionsDotFile = eMaskOptionsSequenceBasedOnFilename * 2, // show files which start with a dot (hidden files)
00082         eMaskOptionsColor = eMaskOptionsDotFile * 2, // output with color
00083         eMaskOptionsDefault = ( eMaskOptionsPath | eMaskOptionsColor )
00084 };
00085 
00086 inline EMaskType operator~(const EMaskType& a )
00087 {
00088         return (EMaskType) ( ~int(a ) );
00089 }
00090 
00091 inline EMaskType operator&=( EMaskType& a, const EMaskType& b )
00092 {
00093         return a = (EMaskType) (int(b ) & int(a ) );
00094 }
00095 
00096 inline EMaskType operator|=( EMaskType& a, const EMaskType& b )
00097 {
00098         return a = (EMaskType) (int(b ) | int(a ) );
00099 }
00100 
00101 inline EMaskType operator|( const EMaskType& a, const EMaskType& b )
00102 {
00103         return (EMaskType) (int(b ) | int(a ) );
00104 }
00105 
00106 inline EMaskOptions operator|=( EMaskOptions& a, const EMaskOptions& b )
00107 {
00108         a = (EMaskOptions) (int(b ) | int(a ) );
00109         return a;
00110 }
00111 
00112 inline EMaskOptions operator|( const EMaskOptions& a, const EMaskOptions& b )
00113 {
00114         return (EMaskOptions) (int(b ) | int(a ) );
00115 }
00116 
00117 inline EMaskOptions remove( EMaskOptions& a, const EMaskOptions& b )
00118 {
00119         a = (EMaskOptions) (int(~b ) & int(a ) );
00120         return a;
00121 }
00122 
00123 template<typename T>
00124 inline T greatestCommonDivisor( T a, T b )
00125 {
00126         T r;
00127         if( b == 0 )
00128                 return 0;
00129         while( ( r = a % b ) != 0 )
00130         {
00131                 a = b;
00132                 b = r;
00133         }
00134         return b;
00135 }
00136 
00137 }
00138 
00139 
00140 #endif