CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
OdPathUtil.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, 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 Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2024 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
35namespace OD {
36 class Path;
37
38 class Path : public OdArray<OdString> {
39 Path& parse(const OdAnsiString& name, const char* delimeters = "/\\");
40 Path& parse(const OdString& name, const OdChar* delimeters = L"/\\");
41 Path& add(const Path& path);
42 Path& add(const OdAnsiString& part);
43 void append(const OdAnsiString& part);
44 void append(const Path& path);
45 public:
46 Path() {}
47 Path(const OdAnsiString& path);
48 Path(const OdString& path);
49 Path(const OdChar* path);
50 Path(const char* path);
51 static const char* Walk(const char* szPath, const char* delimeters = "/\\");
52 Path operator + (const OdAnsiString& path) const;
53 Path operator + (const OdString& path) const;
54 Path operator + (const char* path) const;
55 Path operator + (const OdChar* path) const;
56 Path operator + (const Path& path) const;
57 Path& operator += (const OdAnsiString& path);
58 Path& operator += (const OdString& path);
59 Path& operator += (const char* path);
60 Path& operator += (const OdChar* path);
61 Path& operator += (const Path& path);
62 OdString asStr(bool asdir = false, char sepch = '/') const;
63 };
64
65
66 inline void Path::append(const OdAnsiString & part) {
67 if(size()>0 && part==".." && last() != "..") {
68 removeLast();
69 } else {
71 }
72 }
73 inline void Path::append(const Path & path) {
74 for(size_type i=0; i<path.size(); ++i) {
75 append(path[i]);
76 }
77 }
78 inline const char* Path::Walk(const char* path, const char* delimeters) {
79 char ch[] = " ";
80 while((ch[0] = *path)) {
81 if(::strpbrk(delimeters, ch))
82 break;
83 ++path;
84 }
85 return path;
86 }
87 inline Path& Path::parse(const OdAnsiString& path, const char* delimeters) {
88 OdAnsiString astr(path);
89 for(int i=0; !astr.isEmpty(); i=0) {
90 i = astr.findOneOf(delimeters);
91 if(i==0) {
92 astr = astr.right(astr.getLength()-1);
93 continue;
94 }
95 if(i==-1) {
96 append(astr);
97 break;
98 } else {
99 append(astr.left(i));
100 ++i;
101 astr = astr.right(astr.getLength()-i);
102 }
103 }
104 return *this;
105 }
106 inline Path& Path::parse(const OdString& path, const OdChar* delimeters) {
107 return Path::parse(OdAnsiString(OdString(path)), OdAnsiString(OdString(delimeters)));
108 }
109 inline Path::Path(const OdChar* name) { parse(OdString(name)); }
110 inline Path::Path(const char* name) { parse(OdAnsiString(name)); }
111 inline Path::Path(const OdString& path) { parse(path); }
112 inline Path::Path(const OdAnsiString& path) { parse(path); }
113
114 inline Path& Path::add(const OdAnsiString& part) { append(part); return *this; }
115 inline Path& Path::add(const Path& path) { append(path); return *this; }
116
117 inline Path Path::operator + (const OdAnsiString& path) const { return Path(*this).add( Path(path) ); }
118 inline Path Path::operator + (const OdString& path) const { return Path(*this).add( Path(path) ); }
119 inline Path Path::operator + (const char* path) const { return Path(*this).add( Path(path) ); }
120 inline Path Path::operator + (const OdChar* path) const { return Path(*this).add( Path(path) ); }
121 inline Path Path::operator + (const Path& path) const { return Path(*this).add( path ); }
122 inline Path& Path::operator +=(const OdAnsiString& path) { return add( Path(path) ); }
123 inline Path& Path::operator +=(const OdString& path) { return add( Path(path) ); }
124 inline Path& Path::operator +=(const char* path) { return add( Path(path) ); }
125 inline Path& Path::operator +=(const OdChar* path) { return add( Path(path) ); }
126 inline Path& Path::operator +=(const Path& path) { return add( path ); }
127
128 inline OdString Path::asStr(bool asdir, char sepch) const {
129 OdString res, sep(sepch, 1);
130 if(empty())
131 return res;
132 res = at(0);
133 for(size_type i=1; i<size(); ++i) {
134 res += (sep + at(i));
135 }
136 if(asdir)
137 res += sep;
138 return res;
139 }
140} //namespace OD
141
142
143
144#endif //#ifndef _Path_Util_H_
wchar_t OdChar
OdString OdString
Definition OdString.h:1258
static const char * Walk(const char *szPath, const char *delimeters="/\\")
Definition OdPathUtil.h:78
Path operator+(const OdAnsiString &path) const
Definition OdPathUtil.h:117
OdString asStr(bool asdir=false, char sepch='/') const
Definition OdPathUtil.h:128
Path & operator+=(const OdAnsiString &path)
Definition OdPathUtil.h:122
bool empty() const
Definition OdArray.h:1264
OdArray(size_type physicalLength, int growLength=8)
Definition OdArray.h:1941
OdArray & removeLast()
Definition OdArray.h:1908
size_type size() const
Definition OdArray.h:1254
typename A::size_type size_type
Definition OdArray.h:837
OdString & at(size_type arrayIndex)
Definition OdArray.h:1664
iterator append()
Definition OdArray.h:1887
OdString & last()
Definition OdArray.h:1732
GLuint const GLchar * name
Definition gles2_ext.h:265