Wtx ~ Wt Extension Library
WtxLib
ClientFolder.cpp
1 
2 #include <Wt/WString.h>
3 #include <Wt/WObject.h>
4 
5 #include "ClientFolder.h"
6 #include "Util.h"
7 
8 //#define DEBUG_TRACE
9 
10 std::string Wtx::ClientFolder::s_rootPath = "approot/clients";
11 std::string Wtx::ClientFolder::s_idPrefix = " ~ C";
12 int Wtx::ClientFolder::s_idLength = 6;
13 char Wtx::ClientFolder::s_idPadding = '0';
14 std::string Wtx::ClientFolder::s_idSuffix = "";
15 
16 Wtx::ClientFolder::ClientFolder()
17 : Wt::WObject()
18 {
19 #ifdef DEBUG_TRACE
20  std::cout << __FILE__ << ":" << __LINE__
21  << std::endl;
22 #endif
23 
24  m_isValid = false;
25 }
26 
27 Wtx::ClientFolder::ClientFolder
28 (
29  int uid,
30  const std::string & key,
31  const std::string & name
32 )
33 : Wt::WObject(),
34  m_uid( Wtx::itos(uid) ),
35  m_key( key ),
36  m_name( name )
37 {
38 #ifdef DEBUG_TRACE
39  std::cout << __FILE__ << ":" << __LINE__
40  << " uid:" << m_uid
41  << " key:" << m_key
42  << " name:" << m_name
43  << std::endl;
44 #endif
45 
46  m_isValid = true;
47 }
48 
49 Wtx::ClientFolder::ClientFolder
50 (
51  const std::string & uid,
52  const std::string & key,
53  const std::string & name
54 )
55 : Wt::WObject(),
56  m_uid( uid ),
57  m_key( key ),
58  m_name( name )
59 {
60 #ifdef DEBUG_TRACE
61  std::cout << __FILE__ << ":" << __LINE__
62  << " uid:" << m_uid
63  << " key:" << m_key
64  << " name:" << m_name
65  << std::endl;
66 #endif
67 
68  m_isValid = true;
69 }
70 
71 Wtx::ClientFolder::ClientFolder( const ClientFolder & copy )
72 : Wt::WObject(),
73  m_isValid( copy.m_isValid ),
74  m_uid( copy.m_uid ),
75  m_key( copy.m_key ),
76  m_name( copy.m_name )
77 {
78 #ifdef DEBUG_TRACE
79  std::cout << __FILE__ << ":" << __LINE__
80  << " uid:" << m_uid
81  << " key:" << m_key
82  << " name:" << m_name
83  << std::endl;
84 #endif
85 
86 }
87 
89 (
90  const std::string & rootPath,
91  const std::string & idPrefix,
92  int idLength,
93  char idPadding,
94  const std::string & idSuffix
95 )
96 {
97  s_rootPath = rootPath;
98  s_idPrefix = idPrefix;
99  s_idLength = idLength;
100  s_idPadding = idPadding;
101  s_idSuffix = idSuffix;
102 
103 #ifdef DEBUG_TRACE
104  std::cout << __FILE__ << ":" << __LINE__
105  << " rootPath:" << s_rootPath
106  << " idPrefix:" << s_idPrefix
107  << " idLength:" << s_idLength
108  << " idPadding:" << s_idPadding
109  << " idSuffix:" << s_idSuffix
110  << std::endl;
111 #endif
112 
113 }
114 
115 std::string Wtx::ClientFolder::folder( const std::string & base, const std::string & sub )
116 {
117  auto s = sub;
118  if( s != "" )
119  s = "/" + s;
120 
121  return
122  Wt::WString("{1}{2}")
123  .arg( base )
124  .arg( s )
125  .toUTF8()
126  ;
127 }
128 
130 {
131 #ifdef DEBUG_TRACE
132  std::cout << __FILE__ << ":" << __LINE__
133  << " rootPath:" << s_rootPath
134  << std::endl;
135 #endif
136 
137  return s_rootPath;
138 }
139 
141 {
142 #ifdef DEBUG_TRACE
143  std::cout << __FILE__ << ":" << __LINE__
144  << " idPrefix:" << s_idPrefix
145  << std::endl;
146 #endif
147 
148  return s_idPrefix;
149 }
150 
152 {
153 #ifdef DEBUG_TRACE
154  std::cout << __FILE__ << ":" << __LINE__
155  << " idLength:" << s_idLength
156  << std::endl;
157 #endif
158 
159  return s_idLength;
160 }
161 
163 {
164 #ifdef DEBUG_TRACE
165  std::cout << __FILE__ << ":" << __LINE__
166  << " idPadding:" << s_idPadding
167  << std::endl;
168 #endif
169 
170  return s_idPadding;
171 }
172 
174 {
175 #ifdef DEBUG_TRACE
176  std::cout << __FILE__ << ":" << __LINE__
177  << " idSuffix:" << s_idSuffix
178  << std::endl;
179 #endif
180 
181  return s_idSuffix;
182 }
183 
184 
186 {
187 #ifdef DEBUG_TRACE
188  std::cout << __FILE__ << ":" << __LINE__
189  << " isValid:" << m_isValid
190  << std::endl;
191 #endif
192 
193  return m_isValid;
194 }
195 
196 const std::string & Wtx::ClientFolder::uid() const
197 {
198 #ifdef DEBUG_TRACE
199  std::cout << __FILE__ << ":" << __LINE__
200  << " uid:" << m_uid
201  << std::endl;
202 #endif
203 
204  return m_uid;
205 }
206 
207 const std::string & Wtx::ClientFolder::key() const
208 {
209 #ifdef DEBUG_TRACE
210  std::cout << __FILE__ << ":" << __LINE__
211  << " key:" << m_key
212  << std::endl;
213 #endif
214 
215  return m_key;
216 }
217 
218 const std::string & Wtx::ClientFolder::name() const
219 {
220 #ifdef DEBUG_TRACE
221  std::cout << __FILE__ << ":" << __LINE__
222  << " name:" << m_name
223  << std::endl;
224 #endif
225 
226  return m_name;
227 }
228 
229 std::string Wtx::ClientFolder::fileParent( const std::string & subFolder ) const
230 {
231 #ifdef DEBUG_TRACE
232  std::cout << __FILE__ << ":" << __LINE__
233  << " fileParent:" << Wt::WString("{1}/{2}")
234  .arg( fileRoot() )
235  .arg( fileChar() )
236  .toUTF8()
237  << std::endl;
238 #endif
239 
240  return
241  folder
242  (
243  Wt::WString("{1}/{2}")
244  .arg( fileRoot() )
245  .arg( fileChar() )
246  .toUTF8(),
247  subFolder
248  );
249 
250 }
251 
252 std::string Wtx::ClientFolder::filePath( const std::string & subFolder ) const
253 {
254 #ifdef DEBUG_TRACE
255  std::cout << __FILE__ << ":" << __LINE__
256  << " filePath:" << Wt::WString("{1}/{2}")
257  .arg( fileChar () )
258  .arg( fileFolder () )
259  .toUTF8()
260  << std::endl;
261 #endif
262 
263  return
264  folder
265  (
266  Wt::WString("{1}/{2}")
267  .arg( fileChar () )
268  .arg( fileFolder () )
269  .toUTF8(),
270  subFolder
271  );
272 
273 }
274 
275 std::string Wtx::ClientFolder::fileFolder( const std::string & subFolder ) const
276 {
277 #ifdef DEBUG_TRACE
278  std::cout << __FILE__ << ":" << __LINE__
279  << " fileFolder:" << Wt::WString("{1} ({2}){3}")
280  .arg( fileKey () )
281  .arg( fileName () )
282  .arg( fileCode ( subFolder ) )
283  .toUTF8()
284  << std::endl;
285 #endif
286 
287  return
288  folder
289  (
290  Wt::WString("{1} ({2}){3}")
291  .arg( fileKey () )
292  .arg( fileName () )
293  .arg( fileCode () )
294  .toUTF8(),
295  subFolder
296  );
297 
298 }
299 
300 std::string Wtx::ClientFolder::fileAbsolutePath( const std::string & subFolder ) const
301 {
302 #ifdef DEBUG_TRACE
303  std::cout << __FILE__ << ":" << __LINE__
304  << " fileAbsolutePath:" << Wt::WString("{1}/{2}")
305  .arg( fileRoot() )
306  .arg( filePath( subFolder ) )
307  .toUTF8()
308  << std::endl;
309 #endif
310 
311  return
312  Wt::WString("{1}/{2}")
313  .arg( fileRoot() )
314  .arg( filePath( subFolder ) )
315  .toUTF8()
316  ;
317 
318 }
319 
320 std::string Wtx::ClientFolder::fileId() const
321 {
322 #ifdef DEBUG_TRACE
323  std::cout << __FILE__ << ":" << __LINE__
324  << " fileId:" << Wt::WString("{1}")
325  .arg( Wtx::prepend( uid(), idLength(), idPadding() ) )
326  .toUTF8()
327  << std::endl;
328 #endif
329 
330  return
331  Wt::WString("{1}")
332  .arg( Wtx::prepend( uid(), idLength() ) )
333  .toUTF8()
334  ;
335 
336 }
337 
338 std::string Wtx::ClientFolder::fileCode() const
339 {
340 #ifdef DEBUG_TRACE
341  std::cout << __FILE__ << ":" << __LINE__
342  << " fileCode:" << Wt::WString("{1}{2}{3}")
343  .arg( idPrefix() )
344  .arg( fileId() )
345  .arg( idSuffix() )
346  .toUTF8()
347  << std::endl;
348 #endif
349 
350  return
351  Wt::WString("{1}{2}{3}")
352  .arg( idPrefix() )
353  .arg( fileId() )
354  .arg( idSuffix() )
355  .toUTF8()
356  ;
357 
358 }
359 
360 std::string Wtx::ClientFolder::fileName() const
361 {
362 #ifdef DEBUG_TRACE
363  std::cout << __FILE__ << ":" << __LINE__
364  << " fileName:" << Wtx::makeFileName( Wtx::ucase( name() ) )
365  << std::endl;
366 #endif
367 
368  return Wtx::makeFileName( Wtx::ucase( name() ) );
369 }
370 
371 std::string Wtx::ClientFolder::fileKey() const
372 {
373 #ifdef DEBUG_TRACE
374  std::cout << __FILE__ << ":" << __LINE__
375  << " fileKey:" << Wtx::makeFileName( Wtx::ucase( key() ) )
376  << std::endl;
377 #endif
378 
379  return Wtx::makeFileName( Wtx::ucase( key() ) );
380 }
381 
382 std::string Wtx::ClientFolder::fileChar() const
383 {
384 #ifdef DEBUG_TRACE
385  std::cout << __FILE__ << ":" << __LINE__
386  << " fileChar:" << Wtx::makeFileName( Wtx::ucase( key() ) ).substr(0,1)
387  << std::endl;
388 #endif
389 
390  return Wtx::makeFileName( Wtx::ucase( key() ) ).substr(0,1);
391 }
392 
393 std::string Wtx::ClientFolder::fileRoot( const std::string & subFolder ) const
394 {
395 #ifdef DEBUG_TRACE
396  std::cout << __FILE__ << ":" << __LINE__
397  << " fileRoot:" << rootPath()
398  << std::endl;
399 #endif
400 
401  return folder( rootPath(), subFolder );
402 }
403 
bool isValid() const
Is Valid.
std::string fileRoot(const std::string &subFolder="") const
File Root.
static char idPadding()
ID Padding.
std::string ucase(const std::string &value)
Upper Case a string.
Definition: Util.cpp:441
std::string prepend(const std::string &s, int length=0, char pad= '0')
Prepend some number of characters in front of another string.
Definition: Util.cpp:431
std::string filePath(const std::string &subFolder="") const
File Path.
std::string fileFolder(const std::string &subFolder="") const
File Folder.
std::string fileAbsolutePath(const std::string &subFolder="") const
File Absolute Path.
std::string fileChar() const
File Character.
std::string fileId() const
Field ID.
static int idLength()
ID Length.
static std::string & rootPath()
Root Path.
const std::string & key() const
Key Value.
std::string fileName() const
File Name.
const std::string & name() const
Name Value.
std::string itos(int value)
Convert an Integer to a String.
Definition: Util.cpp:311
std::string fileCode() const
File Code.
static std::string & idPrefix()
ID Prefix.
const std::string & uid() const
Unique ID.
static std::string & idSuffix()
ID Suffix.
witty extension library
Definition: Activity.h:51
std::string makeFileName(const std::string &value)
Make File Name.
Definition: Util.cpp:85
static std::string folder(const std::string &base, const std::string &sub)
Folder.
std::string fileParent(const std::string &subFolder="") const
File Parent.
static void setup(const std::string &rootPath, const std::string &idPrefix, int idLength, char idPadding, const std::string &idSuffix)
Setup Global Static.
std::string fileKey() const
File Key.