Jpp 21.0.0-rc.1-88-g0130508c4
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 24 of file JGlob.hh.

Constructor & Destructor Documentation

◆ JGlob() [1/3]

JSYSTEM::JGlob::JGlob ( )
inline

Default constructor.

Definition at line 30 of file JGlob.hh.

31 {}

◆ JGlob() [2/3]

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

Constructor.

Parameters
patternpattern

Definition at line 39 of file JGlob.hh.

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

◆ JGlob() [3/3]

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

Constructor.

Parameters
bufferlist of patterns

Definition at line 50 of file JGlob.hh.

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

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 62 of file JGlob.hh.

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

◆ 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 79 of file JGlob.hh.

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

◆ 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 97 of file JGlob.hh.

98 {
99 using namespace std::filesystem;
100
101 path ps(file_name);
102
103 if (is_symlink(ps)) {
104 ps = read_symlink(ps);
105 }
106
107 static_cast<std::vector<std::string>&>(*this).push_back(ps.string());
108 }

◆ evaluate()

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

Process pattern.

Parameters
patternpattern

Definition at line 116 of file JGlob.hh.

117 {
118 memset(&buffer, 0, sizeof(buffer));
119
120 const int value = glob(pattern.c_str(), GLOB_TILDE | GLOB_BRACE, NULL, &buffer);
121
122 if (value == 0) {
123
124 for(size_t i = 0; i < buffer.gl_pathc; ++i) {
125 this->push_back(buffer.gl_pathv[i]);
126 }
127
128 } else {
129
130 this->push_back(pattern);
131 }
132
133 globfree(&buffer);
134 }
void push_back(const std::string &file_name)
Push back file.
Definition JGlob.hh:97

Member Data Documentation

◆ buffer

glob_t JSYSTEM::JGlob::buffer
private

Definition at line 136 of file JGlob.hh.


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