fw4spl
Folder.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWDATA_LOCATION_FOLDER_HPP__
8 #define __FWDATA_LOCATION_FOLDER_HPP__
9 
10 #include "fwData/config.hpp"
11 #include "fwData/factory/new.hpp"
12 #include "fwData/location/ILocation.hpp"
13 
14 #include <boost/filesystem.hpp>
15 
16 fwCampAutoDeclareDataMacro((fwData)(location)(Folder), FWDATA_API);
17 
18 namespace fwData
19 {
20 namespace location
21 {
25 class FWDATA_CLASS_API Folder : public ILocation
26 {
27 public:
28 
30  (Folder)(ILocation),
31  ((::fwData::factory::New< Folder >, () ))
32  ((FolderFactory, ((::boost::filesystem::path))((bool)(false)) ))
33  );
34 
35  fwCampMakeFriendDataMacro((fwData)(location)(Folder));
36 
38  FWDATA_API Folder( ::fwData::Object::Key key );
39 
41  FWDATA_API virtual ~Folder();
42 
44  FWDATA_API void shallowCopy( const Object::csptr& _source ) override;
45 
47  FWDATA_API void cachedDeepCopy(const Object::csptr& _source, DeepCopyCacheType& cache) override;
48 
50  FWDATA_API void setFolder( PathType folder);
51 
53  FWDATA_API PathType getFolder() const;
54 
56  FWDATA_API void setRecursive( bool recursive);
57 
59  FWDATA_API bool getRecursive();
60 
61 protected:
62 
63  FWDATA_API static sptr FolderFactory(PathType path, bool recursive = false );
64 
66  PathType m_folder;
67 
70 
71 };
72 
79 template<class RW> // reader or writer class should only need to implement get/setLocation
81 {
86  enableFolder(RW* rw) :
87  m_rw(rw)
88  {
89  SLM_ASSERT("m_rw not instanced", m_rw);
90  }
91 
93  void setFolder(ILocation::PathType folder)
94  {
95  getLocation<Folder>(m_rw)->setFolder(folder);
96  }
97 
99  ILocation::PathType getFolder()
100  {
101  return getLocation<Folder>(m_rw)->getFolder();
102  }
103 
105  void setRecursive( bool val)
106  {
107  getLocation<Folder>(m_rw)->setRecursive(val);
108  }
109 
112  {
113  return getLocation<Folder>(m_rw)->getRecursive();
114  }
115 
116  private:
118  enableFolder();
119 
121  RW* m_rw;
122 
123 };
124 
125 }
126 }
127 
128 #endif /* __FWDATA_LOCATION_FOLDER_HPP__ */
This class defines a folder location.
Definition: Folder.hpp:25
bool getRecursive()
Get the flag if folder location is recursive.
Definition: Folder.hpp:111
ILocation::PathType getFolder()
Get folder filesystem path.
Definition: Folder.hpp:99
#define fwCoreClassDefinitionsWithNFactoriesMacro(_classinfo_, _factories_args_)
Generate common construction methods for classes with several factories.
PathType m_folder
Folder path
Definition: Folder.hpp:66
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
enableFolder(RW *rw)
constructor
Definition: Folder.hpp:86
void setFolder(ILocation::PathType folder)
Set folder filesystem path.
Definition: Folder.hpp:93
void setRecursive(bool val)
Set the flag if folder location is recursive.
Definition: Folder.hpp:105
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
Abstract class to define a location ( fileSystem, directory(IES) etc.... )
Definition: ILocation.hpp:28
bool m_isRecursive
Flag if folder is recursive.
Definition: Folder.hpp:69
This class is derived by reader/writer.
Definition: Folder.hpp:80
Contains the representation of the data objects used in the framework.