1 | /* |
---|
2 | * ====================================================================== |
---|
3 | * Rappture::Path |
---|
4 | * |
---|
5 | * AUTHOR: Derrick Kearney, Purdue University |
---|
6 | * |
---|
7 | * Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
8 | * ---------------------------------------------------------------------- |
---|
9 | * See the file "license.terms" for information on usage and |
---|
10 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
11 | * ====================================================================== |
---|
12 | */ |
---|
13 | |
---|
14 | #ifndef RAPPTURE_PATH_H |
---|
15 | #define RAPPTURE_PATH_H |
---|
16 | |
---|
17 | #include <RpOutcome.h> |
---|
18 | #include <RpInt.h> |
---|
19 | #include <RpChain.h> |
---|
20 | #include <RpSimpleBuffer.h> |
---|
21 | |
---|
22 | |
---|
23 | #ifdef __cplusplus |
---|
24 | extern "C" { |
---|
25 | #endif // ifdef __cplusplus |
---|
26 | |
---|
27 | namespace Rappture { |
---|
28 | |
---|
29 | /** |
---|
30 | * Block of memory that dynamically resizes itself as needed. |
---|
31 | * The buffer also allows caller to massage the data it holds. |
---|
32 | * allows for easy loading of files. |
---|
33 | */ |
---|
34 | |
---|
35 | class Path { |
---|
36 | public: |
---|
37 | Path(); |
---|
38 | Path(const char* bytes); |
---|
39 | Path(const Path& buffer); |
---|
40 | /* |
---|
41 | Path& operator=(const Path& b); |
---|
42 | Path operator+(const Path& b) const; |
---|
43 | Path& operator+=(const Path& b); |
---|
44 | */ |
---|
45 | virtual ~Path(); |
---|
46 | |
---|
47 | const char *ifs(const char *el); // set/get comp separator |
---|
48 | Path& add(const char *el); // turns input into input.number(blah) |
---|
49 | Path& del(); // turns input.number(blah) into input |
---|
50 | bool eof(); |
---|
51 | |
---|
52 | Path& first(); |
---|
53 | Path& prev(); |
---|
54 | Path& next(); |
---|
55 | Path& last(); |
---|
56 | Path& clear(); |
---|
57 | size_t count(); |
---|
58 | |
---|
59 | // turns input.number(blah) into number(blah) |
---|
60 | const char *component(void); // get component of the current component |
---|
61 | void component(const char *p); // set component of the current component |
---|
62 | |
---|
63 | // turns input.number(blah) into blah |
---|
64 | const char *id(void); // get the id of the current component |
---|
65 | void id(const char *p); // set the id of the current component |
---|
66 | |
---|
67 | // turns input.number(blah) into number |
---|
68 | const char *type(void); // get the type of the current component |
---|
69 | void type(const char *p); // set the type of the current component |
---|
70 | |
---|
71 | // turns input.number(blah) into input |
---|
72 | const char *parent(void); // get the parent of the current component |
---|
73 | void parent(const char *p); // set the parent of the current component |
---|
74 | |
---|
75 | // turns input.number2(blah) into 2 |
---|
76 | size_t degree(void); // get the degree of the current component |
---|
77 | void degree(size_t degree); // set the degree of the current component |
---|
78 | |
---|
79 | const char *path(void); // get the path |
---|
80 | void path(const char *p); // set the path |
---|
81 | |
---|
82 | private: |
---|
83 | |
---|
84 | typedef struct { |
---|
85 | const char *type; |
---|
86 | const char *id; |
---|
87 | size_t degree; |
---|
88 | } componentStruct; |
---|
89 | |
---|
90 | void __pathInit(); |
---|
91 | void __pathFree(); |
---|
92 | void __updateBuffer(); |
---|
93 | Rp_Chain *__parse(const char *p); |
---|
94 | componentStruct *__createComponent(const char *p, int start, |
---|
95 | int end, int idOpenParen, int idCloseParen, |
---|
96 | size_t degree); |
---|
97 | void __deleteComponent(componentStruct *c); |
---|
98 | |
---|
99 | char _ifs; |
---|
100 | Rp_Chain *_pathList; |
---|
101 | Rp_ChainLink *_currLink; |
---|
102 | SimpleCharBuffer b; |
---|
103 | SimpleCharBuffer tmpBuf; |
---|
104 | |
---|
105 | }; |
---|
106 | |
---|
107 | } // namespace Rappture |
---|
108 | |
---|
109 | #ifdef __cplusplus |
---|
110 | } |
---|
111 | #endif // ifdef __cplusplus |
---|
112 | |
---|
113 | #endif // RAPPTURE_PATH_H |
---|