TuttleOFX  1
FileObject.hpp
Go to the documentation of this file.
00001 #ifndef _SEQUENCE_PARSER_FILEOBJECT_HPP_
00002 #define _SEQUENCE_PARSER_FILEOBJECT_HPP_
00003 
00004 #include <boost/filesystem.hpp>
00005 #include <commonDefinitions.hpp>
00006 
00007 
00008 namespace sequenceParser {
00009 
00010 /**
00011  * @brief A container for files, directories and sequences.
00012  */
00013 class FileObject : private boost::noncopyable
00014 {
00015 public:
00016 
00017         FileObject()
00018         {
00019                 _directory.clear();
00020                 _type = eMaskTypeUndefined;
00021                 _options = eMaskOptionsNone;
00022                 setColorActive( _options & eMaskOptionsColor );
00023         }
00024 
00025         FileObject( const EMaskOptions options )
00026         {
00027                 _directory.clear();
00028                 _type = eMaskTypeUndefined;
00029                 _options = options;
00030                 setColorActive( _options & eMaskOptionsColor );
00031         }
00032 
00033         /**
00034          * @brief Construct a FileObject with given informations.
00035          */
00036         FileObject( const boost::filesystem::path& directory, const EMaskType& type, const EMaskOptions& options )
00037         {
00038                 init( directory, type, options );
00039         }
00040 
00041         FileObject( const FileObject& other )
00042         {
00043                 operator=( other );
00044         }
00045         
00046         FileObject& operator=( const FileObject& other )
00047         {
00048                 _directory = other._directory;
00049                 _type = other._type;
00050                 _options = other._options;
00051                 _kColorStd = other._kColorStd;
00052                 _kColorFolder = other._kColorFolder;
00053                 _kColorFile = other._kColorFile;
00054                 _kColorSequence = other._kColorSequence;
00055                 _kColorError = other._kColorError;
00056                 return *this;
00057         }
00058         
00059         virtual ~FileObject();
00060 
00061 #ifndef SWIG
00062         friend std::ostream& operator<<( std::ostream& os, const FileObject& fo );
00063 #endif
00064 
00065         virtual std::ostream& getCout( std::ostream& os ) const = 0;
00066 
00067         /**
00068          * @todo: can we remove this?
00069          */
00070         virtual std::vector<boost::filesystem::path> getFiles() const = 0;
00071 
00072         /// @todo
00073         // virtual std::string getName() const = 0;
00074         //  boost::filesystem::path getAbsoluteName() const
00075         //  {
00076         //      return getDirectory() / getName();
00077         //  }
00078 
00079         inline boost::filesystem::path getDirectory() const
00080         {
00081                 return _directory;
00082         }
00083 
00084         inline boost::filesystem::path getAbsoluteDirectory() const
00085         {
00086                 return boost::filesystem::absolute( _directory );
00087         }
00088 
00089         inline void setDirectory( const boost::filesystem::path& p )
00090         {
00091                 _directory = p;
00092         }
00093 
00094         void setDirectoryFromPath( const boost::filesystem::path& p );
00095 
00096         EMaskOptions getMaskOptions() const
00097         {
00098                 return _options;
00099         }
00100 
00101         EMaskType getMaskType() const
00102         {
00103                 return _type;
00104         }
00105 
00106         virtual inline void clear()
00107         {
00108                 _directory.clear();
00109                 _type = eMaskTypeDefault;
00110                 _options = eMaskOptionsDefault;
00111         }
00112         
00113         virtual FileObject* clone() const = 0;
00114         
00115 private:
00116 
00117         void init( const boost::filesystem::path& directory, const EMaskType& type, const EMaskOptions& options )
00118         {
00119                 _directory = directory;
00120                 _type = type;
00121                 _options = options;
00122                 setColorActive( _options & eMaskOptionsColor );
00123         }
00124 
00125         void setColorActive( bool activate = false )
00126         {
00127                 if( activate )
00128                 {
00129                         _kColorStd = kColorStd;
00130                         _kColorFolder = kColorFolder;
00131                         _kColorFile = kColorFile;
00132                         _kColorSequence = kColorSequence;
00133                         _kColorError = kColorError;
00134                 }
00135                 else
00136                 {
00137                         _kColorStd = "";
00138                         _kColorFolder = "";
00139                         _kColorFile = "";
00140                         _kColorSequence = "";
00141                         _kColorError = "";
00142                 }
00143         }
00144 
00145 protected:
00146 
00147         inline bool showProperties() const
00148         {
00149                 return _options & eMaskOptionsProperties;
00150         }
00151 
00152         inline bool showRelativePath() const
00153         {
00154                 return _options & eMaskOptionsPath;
00155         }
00156 
00157         inline bool showAbsolutePath() const
00158         {
00159                 return _options & eMaskOptionsAbsolutePath;
00160         }
00161 
00162 protected:
00163         boost::filesystem::path _directory; ///< directory
00164         EMaskType _type; ///< specify type of object
00165         
00166         ///@todo Remove this from here!
00167         ///@{
00168         EMaskOptions _options; ///< specify output options of object, common for each objects
00169         std::string _kColorStd;
00170         std::string _kColorFolder;
00171         std::string _kColorFile;
00172         std::string _kColorSequence;
00173         std::string _kColorError;
00174         ///@}
00175 };
00176 
00177 #ifndef SWIG
00178 inline FileObject* new_clone( const FileObject& a )
00179 {
00180         return a.clone();
00181 }
00182 #endif
00183 
00184 
00185 }
00186 
00187 #endif
00188 
00189