QMCPACK
hdf_path Class Reference
+ Collaboration diagram for hdf_path:

Public Member Functions

 hdf_path ()
 Constructs an empty path. More...
 
 hdf_path (std::string_view p)
 Constructs a path whose pathname is the same as that of p. More...
 
hdf_pathappend (std::string_view p)
 Appends elements to the path with a directory separator. More...
 
hdf_pathappend (const hdf_path &p)
 
hdf_pathconcat (std::string_view p)
 Concatenates two paths without introducing a directory separator. More...
 
hdf_pathconcat (const hdf_path &p)
 
hdf_pathoperator/= (std::string_view p)
 Appends elements to the path with a directory separator. More...
 
hdf_pathoperator/= (const hdf_path &p)
 
hdf_pathoperator+= (std::string_view p)
 Concatenates two paths without introducing a directory separator. More...
 
hdf_pathoperator+= (const hdf_path &p)
 
hdf_pathremove_subgroup ()
 Remove last subgroup in path. More...
 
hdf_pathreplace_subgroup (std::string_view p)
 Replace the last subgroup in path. More...
 
const std::string & string () const
 Return std::string for use with HDF5. More...
 
bool has_root_directory () const
 Does the path absolute (true) or relative to the current group in hdf_archive (false)? More...
 

Private Attributes

std::string path_
 

Detailed Description

Definition at line 22 of file hdf_path.h.

Constructor & Destructor Documentation

◆ hdf_path() [1/2]

hdf_path ( )
default

Constructs an empty path.

Referenced by hdf_path::append().

◆ hdf_path() [2/2]

hdf_path ( std::string_view  p)

Constructs a path whose pathname is the same as that of p.

Parameters
ppathname

Definition at line 18 of file hdf_path.cpp.

18 : path_{p} {};
std::string path_
Definition: hdf_path.h:74

Member Function Documentation

◆ append() [1/2]

hdf_path & append ( std::string_view  p)

Appends elements to the path with a directory separator.

Parameters
ppathname

Definition at line 20 of file hdf_path.cpp.

References hdf_path::hdf_path().

Referenced by hdf_path::operator/=(), hdf_path::replace_subgroup(), and TEST_CASE().

20 { return append(hdf_path(p)); }
hdf_path & append(std::string_view p)
Appends elements to the path with a directory separator.
Definition: hdf_path.cpp:20
hdf_path()
Constructs an empty path.

◆ append() [2/2]

hdf_path & append ( const hdf_path p)

Definition at line 22 of file hdf_path.cpp.

References hdf_path::concat(), hdf_path::has_root_directory(), and hdf_path::path_.

23 {
24  if (p.has_root_directory())
25  path_.clear();
26  else if (!path_.empty() && path_.back() != '/')
27  path_.push_back('/');
28  return concat(p);
29 }
std::string path_
Definition: hdf_path.h:74
hdf_path & concat(std::string_view p)
Concatenates two paths without introducing a directory separator.
Definition: hdf_path.cpp:31

◆ concat() [1/2]

hdf_path & concat ( std::string_view  p)

Concatenates two paths without introducing a directory separator.

Parameters
ppathname
Returns
*this

Definition at line 31 of file hdf_path.cpp.

References hdf_path::path_.

Referenced by hdf_path::append(), hdf_path::concat(), hdf_path::operator+=(), and TEST_CASE().

32 {
33  path_.append(p);
34  return *this;
35 }
std::string path_
Definition: hdf_path.h:74

◆ concat() [2/2]

hdf_path & concat ( const hdf_path p)

Definition at line 37 of file hdf_path.cpp.

References hdf_path::concat(), and hdf_path::string().

37 { return concat(p.string()); }
hdf_path & concat(std::string_view p)
Concatenates two paths without introducing a directory separator.
Definition: hdf_path.cpp:31

◆ has_root_directory()

bool has_root_directory ( ) const

Does the path absolute (true) or relative to the current group in hdf_archive (false)?

Returns
does the path begin with '/'

Definition at line 73 of file hdf_path.cpp.

References hdf_path::path_.

Referenced by hdf_path::append(), hdf_path::remove_subgroup(), and TEST_CASE().

73 { return (!path_.empty() && path_[0] == '/'); }
std::string path_
Definition: hdf_path.h:74

◆ operator+=() [1/2]

hdf_path & operator+= ( std::string_view  p)

Concatenates two paths without introducing a directory separator.

Parameters
ppathname
Returns
*this

Definition at line 43 of file hdf_path.cpp.

References hdf_path::concat().

43 { return concat(p); }
hdf_path & concat(std::string_view p)
Concatenates two paths without introducing a directory separator.
Definition: hdf_path.cpp:31

◆ operator+=() [2/2]

hdf_path & operator+= ( const hdf_path p)

Definition at line 45 of file hdf_path.cpp.

References hdf_path::concat().

45 { return concat(p); }
hdf_path & concat(std::string_view p)
Concatenates two paths without introducing a directory separator.
Definition: hdf_path.cpp:31

◆ operator/=() [1/2]

hdf_path & operator/= ( std::string_view  p)

Appends elements to the path with a directory separator.

Parameters
ppathname
Returns
*this

Definition at line 39 of file hdf_path.cpp.

References hdf_path::append().

39 { return append(p); }
hdf_path & append(std::string_view p)
Appends elements to the path with a directory separator.
Definition: hdf_path.cpp:20

◆ operator/=() [2/2]

hdf_path & operator/= ( const hdf_path p)

Definition at line 41 of file hdf_path.cpp.

References hdf_path::append().

41 { return append(p); }
hdf_path & append(std::string_view p)
Appends elements to the path with a directory separator.
Definition: hdf_path.cpp:20

◆ remove_subgroup()

hdf_path & remove_subgroup ( )

Remove last subgroup in path.

Returns
*this

Definition at line 47 of file hdf_path.cpp.

References hdf_path::has_root_directory(), and hdf_path::path_.

Referenced by hdf_path::replace_subgroup(), and TEST_CASE().

48 {
49  // if path == '/' do nothing
50  if (path_.size() == 1 && has_root_directory())
51  return *this;
52 
53  auto pos = path_.find_last_of('/');
54 
55  // don't eliminate root group
56  if (pos == 0 && has_root_directory())
57  pos++;
58 
59  // if path is relative and only one group is present, clear the string
60  if (pos == std::string::npos)
61  path_.clear();
62  else
63  path_.erase(pos, std::string::npos);
64  return *this;
65 }
std::string path_
Definition: hdf_path.h:74
bool has_root_directory() const
Does the path absolute (true) or relative to the current group in hdf_archive (false)?
Definition: hdf_path.cpp:73

◆ replace_subgroup()

hdf_path & replace_subgroup ( std::string_view  p)

Replace the last subgroup in path.

Parameters
psubgroup to replace last in path
Returns
*this

Definition at line 67 of file hdf_path.cpp.

References hdf_path::append(), and hdf_path::remove_subgroup().

Referenced by TEST_CASE().

68 {
70  return append(p);
71 }
hdf_path & append(std::string_view p)
Appends elements to the path with a directory separator.
Definition: hdf_path.cpp:20
hdf_path & remove_subgroup()
Remove last subgroup in path.
Definition: hdf_path.cpp:47

◆ string()

const std::string& string ( ) const
inline

Return std::string for use with HDF5.

Returns
path as a std::string

Definition at line 67 of file hdf_path.h.

References hdf_path::path_.

Referenced by hdf_path::concat(), hdf_archive::push(), TEST_CASE(), and OneBodyDensityMatricesTests< T >::testRegisterAndWrite().

67 { return path_; }
std::string path_
Definition: hdf_path.h:74

Member Data Documentation

◆ path_

std::string path_
private

The documentation for this class was generated from the following files: