41#include <drain/UniTuple.h>
49#include <drain/String.h>
50#include <drain/Sprinter.h>
81 PathSeparatorPolicy(
char separator=
'/',
bool lead=
true,
bool repeated=
false,
bool trail=
true) :
83 set(lead, repeated, trail);
85 throw std::runtime_error(
"PathSeparatorPolict (char separator): separator=0, did you mean empty init (\"\")");
95std::ostream & operator<<(std::ostream & ostr,
const PathSeparatorPolicy & policy) {
96 ostr <<
"Separator='" << policy.character <<
"', policy=" << policy.tuple();
111template <
class T,
char SEP=
'/',
bool ALEAD=
true,
bool AREPEAT=
false,
bool ATRAIL=
true>
112class Path :
public std::list<T> {
120 typedef std::list< path_t > list_t;
139 Path(
typename path_t::const_iterator it,
typename path_t::const_iterator it2){
148 template <
typename ... TT>
156 template <
typename ... TT>
158 Path(
const std::string & arg,
const TT &... args){
164 template <
typename ... TT>
166 Path(
const char * arg,
const TT &... args){
191 template <
typename ... TT>
192 void set(
const TT &... args) {
199 template <
typename T2,
typename ... TT>
200 void append(
const T2 & arg,
const TT &... args) {
206 template <
typename ... TT>
207 void append(
const path_t &p,
const TT &... args) {
208 this->insert(this->end(), p.begin(), p.end());
213 template <
typename ... TT>
214 void append(
char c,
const TT &... args) {
219 template <
typename ... TT>
220 void append(
const char * arg,
const TT &... args) {
225 template <
typename ... TT>
226 void append(
const std::string &arg,
const TT &... args) {
257 this->push_back(elem);
260 else if (this->empty()){
262 this->push_back(elem);
265 else if (this->back().empty()){
268 this->push_back(elem);
273 this->push_back(elem);
276 std::cerr << __FUNCTION__ <<
"? failed in appending: " << sprinter(*
this) <<
'\n';
282 template <
typename T2>
300 return ((this->size()==1) && this->front().empty());
313 return this->front().empty();
329 this->push_front(elem_t());
341 const size_t minLength = COMPLETE ? 0 : 1;
342 while (this->size() > minLength){
344 if (!this->front().empty()){
355 const size_t minLength = COMPLETE ? 0 : 1;
356 while (this->size() > minLength){
358 if (!this->back().empty()){
395 if (this->front().empty()){
396 typename path_t::const_iterator it0 = ++this->begin();
397 typename path_t::const_iterator it = it0;
398 while (it != this->end()) {
419 if (this->back().empty()){
420 typename path_t::const_iterator it0 = --this->end();
421 typename path_t::const_iterator it = it0;
423 while (it != this->begin()) {
468 path_t &
operator=(
const std::string & p){
510 this->insert(this->end(), path.begin(), path.end());
537 std::ostream &
toStream(std::ostream & ostr)
const {
540 ostr << separator.character;
543 layout.arrayChars.separator = separator.character;
555 std::string str()
const {
556 std::stringstream sstr;
562 operator std::string()
const {
566 std::ostream & debug(std::ostream & ostr = std::cout)
const {
568 ostr <<
"Path elems:" << this->size() <<
" sep:" << separator <<
" typeid: " <<
typeid(T).name() <<
"\n";
569 ostr << *
this <<
'\n';
571 for (
typename path_t::const_iterator it = this->begin(); it != this->end(); ++it) {
574 ostr <<
" " << i <<
'\t' << *it <<
'\n';
591 template <typename T2>
592 void _append(const T2 & p){
600 if (start == p.length()){
609 size_t nextSep = p.find(separator.character, start);
612 if (nextSep==std::string::npos){
644template <
class T,
char SEP=
'/',
bool ALEAD=
true,
bool AREPEAT=
false,
bool ATRAIL=
true>
646std::ostream & operator<<(std::ostream & ostr,
const Path<T,SEP,ALEAD,AREPEAT,ATRAIL> & p) {
647 return p.toStream(ostr);
651template <
class T,
char SEP=
'/',
bool ALEAD=
true,
bool AREPEAT=
false,
bool ATRAIL=
true>
653std::istream & operator>>(std::istream &istr, Path<T,SEP,ALEAD,AREPEAT,ATRAIL> & p) {
670template <
class T,
char SEP,
bool ALEAD,
bool AREPEAT,
bool ATRAIL>
671const PathSeparatorPolicy Path<T,SEP,ALEAD,AREPEAT,ATRAIL>::separator(SEP, ALEAD, AREPEAT, ATRAIL);
virtual ~Path()
Why the three above instead of this?
Definition Path.h:185
void simplify()
ORIGINAL. Removes trailing empty elements, except for the root itself.
Definition Path.h:382
void simplifyTail()
Remove duplicates of empty elements from the end.
Definition Path.h:414
void _appendPath(const std::string &p, size_t start=0)
"Default" append function.
Definition Path.h:598
virtual std::ostream & toStream(std::ostream &ostr) const
Path is written like a list, adding the separator between items. Exception: root is displayed as sepa...
Definition Path.h:537
void appendElem(const elem_t &elem)
Main method for adding elements.
Definition Path.h:246
void appendPath(const char *p)
Specialized handler for strings (note, possibly: elem_t==std:string)
Definition Path.h:234
void simplifyHead()
Remove duplicates of empty elements from the start.
Definition Path.h:390
path_t & operator=(const path_t &p)
Assigns a path directly with std::list assignment.
Definition Path.h:444
Path(const char *arg, const TT &... args)
Initialize with a path.
Definition Path.h:166
bool isRoot() const
Returns true, if the path as only one element which is empty. An empty path is not a root.
Definition Path.h:299
Path(const path_t &arg, const TT &... args)
Initialize with a path.
Definition Path.h:150
Path(const path_t &p)
Copy constructor.
Definition Path.h:134
void appendElem(const T2 &elem)
To be specialized in subclasses.
Definition Path.h:284
path_t & operator<<(const elem_t &elem)
Append an element, unless empty string.
Definition Path.h:503
Path(typename path_t::const_iterator it, typename path_t::const_iterator it2)
Secondary copy constructor. Handy for creating a parent path, for example.
Definition Path.h:139
void append(const T2 &arg, const TT &... args)
Append path with element(s), path(s) or string(s).
Definition Path.h:200
Path(const std::string &arg, const TT &... args)
Initialize with a path.
Definition Path.h:158
path_t & operator=(const Path< T2 > &p)
Conversion from str path type.
Definition Path.h:461
path_t & ensureRoot()
Returns true, if the path is not empty and the first element is empty.
Definition Path.h:327
path_t & operator>>(elem_t &e)
Extract last element.
Definition Path.h:524
void trimTail(bool COMPLETE=false)
Removes trailing empty elements. The resulting string presentation will not end with the separator.
Definition Path.h:354
void append()
Terminal function for variadic templates.
Definition Path.h:629
void trimHead(bool COMPLETE=false)
Removes leading empty elements. The resulting string presentation will not start with the separator.
Definition Path.h:340
bool hasRoot() const
Returns true, if the path is not empty and the first element is empty.
Definition Path.h:311
static std::ostream & sequenceToStream(std::ostream &ostr, const T &x, const SprinterLayout &layout)
Convenience: if sequence type (array, list, set, map) not given, assume array.
Definition Sprinter.h:325
Tuple of N elements of type T.
Definition UniTuple.h:65
Definition DataSelector.cpp:1277
Determines if separators will be stored in the path.
Definition Path.h:67
bool & acceptRepeated
If true, allow empty elements in the middle (appearing as repeated separators)
Definition Path.h:76
bool & acceptTrailing
If true, allow trailing empty elements (appearing as repeated separators)
Definition Path.h:79
bool & acceptLeading
If true, allow leading empties (ie leading separators) // Accepts one. to start with.
Definition Path.h:73
Definition Sprinter.h:137