NumCpp  2.9.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Filesystem.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <fstream>
31 #include <string>
32 
33 namespace nc
34 {
35  namespace filesystem
36  {
37  //================================================================================
39  class File
40  {
41  public:
42  //============================================================================
43  // Method Description:
48  explicit File(const std::string& filename) :
49  fullFilename_(filename)
50  {
51  const size_t dot = filename.find_last_of('.');
52 
53  filename_ = filename.substr(0, dot);
54 
55  if (dot != std::string::npos)
56  {
57  extension_ = filename.substr(dot + 1, std::string::npos);
58  }
59 
60  std::ifstream f(filename.c_str());
61  exists_ = f.good();
62  }
63 
64  //============================================================================
65  // Method Description:
70  bool exists() const noexcept
71  {
72  return exists_;
73  }
74 
75  //============================================================================
76  // Method Description:
81  const std::string& ext() const noexcept
82  {
83  return extension_;
84  }
85 
86  //============================================================================
87  // Method Description:
92  std::string fullName() const
93  {
94  return filename_ + "." + extension_;
95  }
96 
97  //============================================================================
98  // Method Description:
103  bool hasExt() const
104  {
105  return !extension_.empty();
106  }
107 
108  //============================================================================
109  // Method Description:
114  const std::string& name() const noexcept
115  {
116  return filename_;
117  }
118 
119  //============================================================================
120  // Method Description:
126  std::string withExt(const std::string& ext)
127  {
128  extension_ = ext;
129  return fullName();
130  }
131 
132  private:
133  //================================Attributes==================================
134  std::string fullFilename_{ "" };
135  std::string filename_{ "" };
136  std::string extension_{ "" };
137  bool exists_{ false };
138  };
139  } // namespace filesystem
140 } // namespace nc
Provides simple filesystem functions.
Definition: Filesystem.hpp:40
std::string fullName() const
Definition: Filesystem.hpp:92
const std::string & name() const noexcept
Definition: Filesystem.hpp:114
bool hasExt() const
Definition: Filesystem.hpp:103
bool exists() const noexcept
Definition: Filesystem.hpp:70
File(const std::string &filename)
Definition: Filesystem.hpp:48
const std::string & ext() const noexcept
Definition: Filesystem.hpp:81
std::string withExt(const std::string &ext)
Definition: Filesystem.hpp:126
dtype f(GeneratorType &generator, dtype inDofN, dtype inDofD)
Definition: f.hpp:58
Definition: Coordinate.hpp:45
NdArray< dtype > dot(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: dot.hpp:47