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