FileInfo.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25  */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30  */
31 #ifndef DRAIN_IMAGE_FILEINFO
32 #define DRAIN_IMAGE_FILEINFO
33 
34 
35 //
36 #include <drain/RegExp.h>
37 
38 #include "BeanLike.h"
39 #include "FilePath.h"
40 #include "Registry.h"
41 
42 
43 namespace drain
44 {
45 
46 
47 
48 class FileInfo {
49 public:
50 
51  FileInfo(const std::string & extRE = "[\\w]+", int flags=REG_ICASE|REG_EXTENDED){
52  setExtensionRegExp(extRE, flags);
53  }
54 
55  void setExtensionRegExp(const std::string & extRE, int flags=REG_ICASE|REG_EXTENDED);
56 
58  inline
59  bool checkPath(const std::string & path) const {
60  if (path == "-")
61  return false;
62  else
63  return checkPath(FilePath(path));
64  }
65 
67 
72  inline
73  bool checkPath(const FilePath & filePath) const {
74  return checkExtension(filePath.extension);
75  }
76 
78 
82  inline
83  bool checkExtension(const std::string & ext) const {
84  return extensionRegexp.test(ext);
85  }
86 
89 
90 
91  //static
92  //const drain::RegExp noExtension;
93 
94 };
95 
96 
97 class FileHandler { // : public BeanLike {
98 
99 public:
100 
101  /*
102  inline
103  FileHandler(const std::string & name) : BeanLike(name){
104  }
105  */
106  //static virtual
107  //const FileInfo & getFileInfo() = 0;
108 
109 };
110 
111 // static
112 // Registry<FileInfo> & getFileInfoRegistry();
113 
114 
115 } // drain
116 
117 #endif /*FILE_H_*/
118 
119 // Drain
Definition: FileInfo.h:97
Definition: FileInfo.h:48
bool checkPath(const std::string &path) const
Accepts or rejects a filename extension.
Definition: FileInfo.h:59
bool checkPath(const FilePath &filePath) const
Accepts or rejects the extension extracted from file path.
Definition: FileInfo.h:73
drain::RegExp extensionRegexp
Regexp to be set inside parentheses.
Definition: FileInfo.h:88
bool checkExtension(const std::string &ext) const
Accepts or rejects a filename extension.
Definition: FileInfo.h:83
Extracts and stores directory path, base filename and extension.
Definition: FilePath.h:58
Definition: RegExp.h:58
bool test(const std::string &str) const
Tests if the regular expression accepts the given std::string.
Definition: RegExp.cpp:128
Definition: DataSelector.cpp:1277