Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsNode.h
Go to the documentation of this file.
1 
13 #ifndef WS_NODE_H__
14 #define WS_NODE_H__
15 
16 #include <boost/lexical_cast.hpp>
17 #include <algorithm>
18 
20 #include <Include/WsGlobalConfig.h>
21 #include "WsAbstractNode.h"
22 
23 
27 class WsNode: public WsAbstractNode {
28 
29 public:
30 
38  struct compareNodes {
39  bool operator ()(NodePtr lhs, NodePtr rhs) {
40  int lsortNumber, rsortNumber;
41  /* Get the sort order (asc or desc) */
42  std::string sortOrder = lhs.get()->getParent()->getProperties().get()->get("global", "sort_order", "asc");
43  try {
44  /* Get the sort number of lhs and rhs from the configuration file of the node */
45  lsortNumber = boost::lexical_cast<int>(lhs->getProperty("global", "sort_number", "-1"));
46  rsortNumber = boost::lexical_cast<int>(rhs->getProperty("global", "sort_number", "-1"));
47  if (lsortNumber == rsortNumber) {
48  if (sortOrder == "asc")
49  return lhs.get()->getName() < rhs.get()->getName() ;
50  return lhs.get()->getName() > rhs.get()->getName() ;
51  }
52  if (sortOrder == "asc")
53  return lsortNumber > rsortNumber;
54  return lsortNumber < rsortNumber;
55  } catch (boost::bad_lexical_cast&) {
56  LOG(ERROR) << "WsNode :: Cannot cast sort number, check config file values";
57  }
58  }
59  };
60 
66  WsNode(const path& fullPath, const path& rootPath);
67 
71  WsNode();
72 
76  virtual ~WsNode();
77 
81  const path& getPath();
82 
86  const path& getFullPath();
87 
91  string getName(const bool noExt = false);
92 
96  const string getDisplayName(const bool noExt = false );
97 
101  int addChildDirectory(NodePtr f);
102 
106  int addChildFile(NodePtr f);
107 
111  int addChildNode(NodePtr f);
112 
116  void setParent(NodePtr n);
117 
121  NodePtr getParent();
122 
126  const vector<NodePtr> getFiles();
127 
131  const vector<NodePtr> getDirectories();
132 
136  const vector<NodePtr> getAll();
137 
141  NodePtr getNodeByName(const std::string& name);
142 
146  bool getDisplayInMenu();
147 
151  void setProperties(NodePropertiesPtr properties);
152 
157 
161  std::string getProperty(const std::string& section, const std::string& id, const std::string& def, bool recurse = false);
162 
163 
167  void sort();
168 
172  virtual bool isDirectory() = 0;
173 
177  virtual bool isRegularFile() = 0;
178 
182  const time_t& getModifyDate();
183 
187  const time_t& getCreateDate();
188 
192  void setCreateDate(const time_t& t);
193 
197  void setModifyDate(const time_t& t);
198 
202  void setSize(const uintmax_t& size);
203 
207  virtual const uintmax_t getSize() = 0;
208 
212  NodePtr eatPath(const std::string& path);
213 
214 protected:
222  time_t m_createTime;
226  time_t m_modifyTime;
227 
228  boost::mutex* m_mutexSort;
229 
230 };
231 
232 #endif
boost::shared_ptr< WsAbstractNode > NodePtr
WsNode()
Definition: WsNode.cpp:17
NodePtr eatPath(const std::string &path)
resolves the path and returns the node reprenseted by this path The path should be starting from the ...
Definition: WsNode.cpp:207
const string getDisplayName(const bool noExt=false)
returns the display name of the node
Definition: WsNode.cpp:111
const time_t & getCreateDate()
WsAbstractNode::getCreateDate()
Definition: WsNode.cpp:244
std::string getProperty(const std::string &section, const std::string &id, const std::string &def, bool recurse=false)
get a node property reprensented by section/id If no value found, the value def is returned ...
Definition: WsNode.cpp:180
const path & getFullPath()
returns the full path of the node
Definition: WsNode.cpp:99
Contains Abstract metods on nodes and variables.
void setModifyDate(const time_t &t)
sets the modification date of the file. This method does not change the actual modification date of t...
Definition: WsNode.cpp:254
int addChildNode(NodePtr f)
add a Node to the combined vect WsAbstractNode::m_combinedVect
Definition: WsNode.cpp:73
Represents a node on disk.
Definition: WsNode.h:27
boost::mutex * m_mutexSort
Definition: WsNode.h:228
const vector< NodePtr > getFiles()
returns the list of all the file contained in the directory represented by this
Definition: WsNode.cpp:118
void sort()
sort the nodes using the sort number or the name if not provided
Definition: WsNode.cpp:192
virtual ~WsNode()
Definition: WsNode.cpp:24
NodePropertiesPtr getProperties()
get the properties of the node If the properties are not set (no conf found, or node retrieved from s...
Definition: WsNode.cpp:175
void setProperties(NodePropertiesPtr properties)
set the properties of the node. The properties are a WsAbstractProperties object. ...
Definition: WsNode.cpp:165
#define LOG
Definition: WsLogger.h:22
const time_t & getModifyDate()
returns the modification date of the file reprenseted by the node
Definition: WsNode.cpp:239
virtual bool isRegularFile()=0
returns true if Node is a WsFileNode, false otherwise
bool operator()(NodePtr lhs, NodePtr rhs)
Definition: WsNode.h:39
const vector< NodePtr > getAll()
combine the vector of files and directories into a single one
Definition: WsNode.cpp:130
int addChildDirectory(NodePtr f)
adds a node as a child directory The Directory is added to the WsAbstractNode::m_dirVect ...
Definition: WsNode.cpp:47
NodePropertiesPtr m_properties
Definition: WsNode.h:218
bool getDisplayInMenu()
returns true if the item should be displayed in the menu. This value is set in the configuration file...
Definition: WsNode.cpp:156
virtual const uintmax_t getSize()=0
returns the file size. If the Node is a WsDirNode, 0 is returned. if the global property dir_size is ...
void setParent(NodePtr n)
sets the parent of the node represented by this
Definition: WsNode.cpp:83
const path & getPath()
returns the relative path of the node
Definition: WsNode.cpp:94
NodePtr getParent()
returns the parent node of this
Definition: WsNode.cpp:88
boost::shared_ptr< WsNodeProperties > NodePropertiesPtr
string getName(const bool noExt=false)
returns the name of the node
Definition: WsNode.cpp:104
void setSize(const uintmax_t &size)
sets the file size in the node. Typically called by WsFileSystemTree when building the FileSystemTree...
Definition: WsNode.cpp:170
virtual bool isDirectory()=0
returns true if Node is a WsDirNode, false otherwise
const vector< NodePtr > getDirectories()
returns the list of all the file contained in the file reprensented by this
Definition: WsNode.cpp:124
time_t m_modifyTime
Definition: WsNode.h:226
Compares two nodes and returns true or false depending on : If Sort order is asc in the node configur...
Definition: WsNode.h:38
void setCreateDate(const time_t &t)
sets the creation date of the file. This method does not change the actual creation date of the file ...
Definition: WsNode.cpp:249
NodePtr getNodeByName(const std::string &name)
Searches for the NodePtr reprenting the filename.
Definition: WsNode.cpp:138
Abstract Node class.
int addChildFile(NodePtr f)
adds a node as a child file The Directory is added to the WsAbstractNode::m_fileVect ...
Definition: WsNode.cpp:60
#define ERROR
Definition: WsLogger.h:42
time_t m_createTime
Definition: WsNode.h:222