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