Jpp 21.0.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JSYSTEM::JGlob Struct Reference

Auxiliary class to list files. More...

#include <JGlob.hh>

Inheritance diagram for JSYSTEM::JGlob:
std::vector< std::string >

Public Member Functions

 JGlob ()
 Default constructor.
 
 JGlob (const std::string &pattern)
 Constructor.
 
 JGlob (const std::vector< std::string > &buffer)
 Constructor.
 
const JGloboperator() (const std::string &pattern)
 Get list of files.
 
const JGloboperator() (const std::vector< std::string > &buffer)
 Get list of files.
 
void push_back (const std::string &file_name)
 Push back file.
 

Private Member Functions

void evaluate (const std::string &pattern)
 Process pattern.
 

Private Attributes

glob_t buffer
 

Detailed Description

Auxiliary class to list files.

Definition at line 25 of file JGlob.hh.

Constructor & Destructor Documentation

◆ JGlob() [1/3]

JSYSTEM::JGlob::JGlob ( )
inline

Default constructor.

Definition at line 31 of file JGlob.hh.

32 {}

◆ JGlob() [2/3]

JSYSTEM::JGlob::JGlob ( const std::string & pattern)
inline

Constructor.

Parameters
patternpattern

Definition at line 40 of file JGlob.hh.

41 {
42 (*this)(pattern);
43 }

◆ JGlob() [3/3]

JSYSTEM::JGlob::JGlob ( const std::vector< std::string > & buffer)
inline

Constructor.

Parameters
bufferlist of patterns

Definition at line 51 of file JGlob.hh.

52 {
53 (*this)(buffer);
54 }
glob_t buffer
Definition JGlob.hh:129

Member Function Documentation

◆ operator()() [1/2]

const JGlob & JSYSTEM::JGlob::operator() ( const std::string & pattern)
inline

Get list of files.

Parameters
patternpattern
Returns
list of files

Definition at line 63 of file JGlob.hh.

64 {
65 this->clear();
66
67 evaluate(pattern);
68
69 return *this;
70 }
void evaluate(const std::string &pattern)
Process pattern.
Definition JGlob.hh:109

◆ operator()() [2/2]

const JGlob & JSYSTEM::JGlob::operator() ( const std::vector< std::string > & buffer)
inline

Get list of files.

Parameters
bufferlist of patterns
Returns
list of files

Definition at line 80 of file JGlob.hh.

81 {
82 this->clear();
83
84 for (const std::string& pattern : buffer) {
85 evaluate(pattern);
86 }
87
88 return *this;
89 }

◆ push_back()

void JSYSTEM::JGlob::push_back ( const std::string & file_name)
inline

Push back file.

This method constitutes a light weight wrapper to resolve symbolic links on the fly.

Parameters
file_namefile name

Definition at line 98 of file JGlob.hh.

99 {
100 static_cast<std::vector<std::string>&>(*this).push_back(resolveSymlink(file_name).string());
101 }
std::filesystem::path resolveSymlink(const std::filesystem::path &file_name)
Resolve symbolic links.

◆ evaluate()

void JSYSTEM::JGlob::evaluate ( const std::string & pattern)
inlineprivate

Process pattern.

Parameters
patternpattern

Definition at line 109 of file JGlob.hh.

110 {
111 memset(&buffer, 0, sizeof(buffer));
112
113 const int value = glob(pattern.c_str(), GLOB_TILDE | GLOB_BRACE, NULL, &buffer);
114
115 if (value == 0) {
116
117 for(size_t i = 0; i < buffer.gl_pathc; ++i) {
118 this->push_back(buffer.gl_pathv[i]);
119 }
120
121 } else {
122
123 this->push_back(pattern);
124 }
125
126 globfree(&buffer);
127 }
void push_back(const std::string &file_name)
Push back file.
Definition JGlob.hh:98

Member Data Documentation

◆ buffer

glob_t JSYSTEM::JGlob::buffer
private

Definition at line 129 of file JGlob.hh.


The documentation for this struct was generated from the following file: