libvot  0.1.3
A C++11 multithread library for image retrieval
io_utils.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2015, Tianwei Shen
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 
8 * Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11 * Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15 * Neither the name of libvot nor the names of its
16  contributors may be used to endorse or promote products derived from
17  this software without specific prior written permission.
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 */
31 
38 #ifndef IO_UTILS_HEADER
39 #define IO_UTILS_HEADER
40 
41 #include <vector>
42 
43 namespace tw
44 {
48  template<typename T> T* allocate_2d(T ***arr, int row, int col);
49 
54  template<typename T> void free_2d(T ***array, T *data);
55 
61  class IO
62  {
63  private:
64  IO() {}
65  public:
66  template <class charType>
67  static void TrimLeft(std::basic_string<charType> & str, const char *chars2remove = NULL);
68  template <class charType>
69  static void TrimRight(std::basic_string<charType> & str, const char *chars2remove = NULL);
70  template <class charType>
71  static void Trim(std::basic_string<charType> & str, const char *chars2remove = NULL); // it consists TrimLeft and TrimRight
72  static bool IsEmptyString(const std::string & str); // judge whether the string is empty
73  static int ExtractLines(const char *input_file_path, std::vector<std::string> & lines);
74  static bool IsFileExist(const char *filename);
75  static std::string JoinPath(std::string folder, std::string filename);
76 
77  static std::pair<std::string, std::string> SplitPath(std::string path);
78  static std::pair<std::string, std::string> SplitPathExt(std::string path);
79  static std::string GetFilename(std::string path);
80 
81  static bool Mkdir(const std::string path);
82  static size_t GetAvailMem();
83  };
84 
85 } // end of namespace tw
86 
87 #endif // IO_UTILS_HEADER
static std::pair< std::string, std::string > SplitPath(std::string path)
separate the folder from the filename
Definition: io_utils.cpp:251
static size_t GetAvailMem()
return the total availbale memory that can be used
Definition: io_utils.cpp:300
static std::pair< std::string, std::string > SplitPathExt(std::string path)
separate the basename from the file type (extension)
Definition: io_utils.cpp:261
static std::string GetFilename(std::string path)
get filename without folder path and suffix file format
Definition: io_utils.cpp:271
T * allocate_2d(T ***array, int row, int col)
Definition: io_utils.cpp:71
static bool IsEmptyString(const std::string &str)
Definition: io_utils.cpp:189
static bool IsFileExist(const char *filename)
judge whether the file exists
Definition: io_utils.cpp:227
static void TrimRight(std::basic_string< charType > &str, const char *chars2remove=NULL)
trim the right of a string
Definition: io_utils.cpp:144
To safely read and write files.
Definition: io_utils.h:61
namespace tw is mostly related to some utility functions developed by the repository owner...
Definition: opencv_libvot_api.cpp:12
static int ExtractLines(const char *input_file_path, std::vector< std::string > &lines)
extract lines from a text file
Definition: io_utils.cpp:203
static void TrimLeft(std::basic_string< charType > &str, const char *chars2remove=NULL)
trim the left of a string
Definition: io_utils.cpp:101
void free_2d(T ***array, T *data)
Definition: io_utils.cpp:82
static void Trim(std::basic_string< charType > &str, const char *chars2remove=NULL)
Definition: io_utils.cpp:183
static bool Mkdir(const std::string path)
make a directory
Definition: io_utils.cpp:278
static std::string JoinPath(std::string folder, std::string filename)
join a filename with a directory name
Definition: io_utils.cpp:233