CFx SDK Documentation  2022 SP0
OdPathUtil.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 #ifndef _Path_Util_H_
25 #define _Path_Util_H_
26 
27 
28 #include "OdString.h"
29 #include "OdArray.h"
30 #include <string.h>
31 
32 
33 namespace OD {
34  class Path;
35 
36  class Path : public OdArray<OdString> {
37  Path& parse(const OdAnsiString& name, const char* delimeters = "/\\");
38  Path& parse(const OdString& name, const OdChar* delimeters = L"/\\");
39  Path& add(const Path& path);
40  Path& add(const OdAnsiString& part);
41  void append(const OdAnsiString& part);
42  void append(const Path& path);
43  public:
44  Path() {}
45  Path(const OdAnsiString& path);
46  Path(const OdString& path);
47  Path(const OdChar* path);
48  Path(const char* path);
49  static const char* Walk(const char* szPath, const char* delimeters = "/\\");
50  Path operator + (const OdAnsiString& path) const;
51  Path operator + (const OdString& path) const;
52  Path operator + (const char* path) const;
53  Path operator + (const OdChar* path) const;
54  Path operator + (const Path& path) const;
55  Path& operator += (const OdAnsiString& path);
56  Path& operator += (const OdString& path);
57  Path& operator += (const char* path);
58  Path& operator += (const OdChar* path);
59  Path& operator += (const Path& path);
60  OdString asStr(bool asdir = false, char sepch = '/') const;
61  };
62 
63 
64  inline void Path::append(const OdAnsiString & part) {
65  if(size()>0 && part=="..") {
66  removeLast();
67  } else {
69  }
70  }
71  inline void Path::append(const Path & path) {
72  for(size_type i=0; i<path.size(); ++i) {
73  append(path[i]);
74  }
75  }
76  inline const char* Path::Walk(const char* path, const char* delimeters) {
77  char ch[] = " ";
78  while((ch[0] = *path)) {
79  if(::strpbrk(delimeters, ch))
80  break;
81  ++path;
82  }
83  return path;
84  }
85  inline Path& Path::parse(const OdAnsiString& path, const char* delimeters) {
86  OdAnsiString astr(path);
87  for(int i=0; !astr.isEmpty(); i=0) {
88  i = astr.findOneOf(delimeters);
89  if(i==0) {
90  astr = astr.right(astr.getLength()-1);
91  continue;
92  }
93  if(i==-1) {
94  append(astr);
95  break;
96  } else {
97  append(astr.left(i));
98  ++i;
99  astr = astr.right(astr.getLength()-i);
100  }
101  }
102  return *this;
103  }
104  inline Path& Path::parse(const OdString& path, const OdChar* delimeters) {
105  return Path::parse(OdAnsiString(OdString(path)), OdAnsiString(OdString(delimeters)));
106  }
107  inline Path::Path(const OdChar* name) { parse(OdString(name)); }
108  inline Path::Path(const char* name) { parse(OdAnsiString(name)); }
109  inline Path::Path(const OdString& path) { parse(path); }
110  inline Path::Path(const OdAnsiString& path) { parse(path); }
111 
112  inline Path& Path::add(const OdAnsiString& part) { append(part); return *this; }
113  inline Path& Path::add(const Path& path) { append(path); return *this; }
114 
115  inline Path Path::operator + (const OdAnsiString& path) const { return Path(*this).add( Path(path) ); }
116  inline Path Path::operator + (const OdString& path) const { return Path(*this).add( Path(path) ); }
117  inline Path Path::operator + (const char* path) const { return Path(*this).add( Path(path) ); }
118  inline Path Path::operator + (const OdChar* path) const { return Path(*this).add( Path(path) ); }
119  inline Path Path::operator + (const Path& path) const { return Path(*this).add( path ); }
120  inline Path& Path::operator +=(const OdAnsiString& path) { return add( Path(path) ); }
121  inline Path& Path::operator +=(const OdString& path) { return add( Path(path) ); }
122  inline Path& Path::operator +=(const char* path) { return add( Path(path) ); }
123  inline Path& Path::operator +=(const OdChar* path) { return add( Path(path) ); }
124  inline Path& Path::operator +=(const Path& path) { return add( path ); }
125 
126  inline OdString Path::asStr(bool asdir, char sepch) const {
127  OdString res, sep(sepch, 1);
128  if(empty())
129  return res;
130  res = at(0);
131  for(size_type i=1; i<size(); ++i) {
132  res += (sep + at(i));
133  }
134  if(asdir)
135  res += sep;
136  return res;
137  }
138 } //namespace OD
139 
140 
141 
142 #endif //#ifndef _Path_Util_H_
wchar_t OdChar
OdString OdString
Definition: OdString.h:1224
static const char * Walk(const char *szPath, const char *delimeters="/\\")
Definition: OdPathUtil.h:76
Path operator+(const OdAnsiString &path) const
Definition: OdPathUtil.h:115
OdString asStr(bool asdir=false, char sepch='/') const
Definition: OdPathUtil.h:126
Path & operator+=(const OdAnsiString &path)
Definition: OdPathUtil.h:120
A::size_type size_type
Definition: OdArray.h:593
bool empty() const
Definition: OdArray.h:901
size_type size() const
Definition: OdArray.h:893
OdString & at(size_type arrayIndex)
Definition: OdArray.h:1140
iterator append()
Definition: OdArray.h:1225
OdArray & removeLast()
Definition: OdArray.h:1242
GLuint const GLchar * name
Definition: gles2_ext.h:265
Definition: OdPathUtil.h:33