Changeset 15598 for gsdl/trunk/lib/dbclass.cpp
- Timestamp:
- 2008-05-20T15:00:37+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/lib/dbclass.cpp
r15442 r15598 25 25 26 26 #include "dbclass.h" 27 #include "OIDtools.h" 27 28 28 29 29 30 dbclass::~dbclass() {} 31 32 33 // replaces the .fc, .lc, .pr, .rt, .ns and .ps syntax (first child, 34 // last child, parent, root, next sibling, previous sibling) 35 // it expects child, parent, etc. to exist if syntax has been used 36 // so you should test before using 37 text_t dbclass::translate_OID (const text_t &inOID, infodbclass &info) 38 { 39 if (inOID.size() < 4) return inOID; 40 if (findchar (inOID.begin(), inOID.end(), '.') == inOID.end()) return inOID; 41 42 text_t OID = inOID; 43 text_tarray tailarray; 44 text_t tail = substr (OID.end()-3, OID.end()); 45 if (tail == ".rt") { 46 get_top (inOID, OID); 47 return OID; 48 } 49 while (tail == ".fc" || tail == ".lc" || tail == ".pr" || 50 tail == ".ns" || tail == ".ps") { 51 tailarray.push_back(tail); 52 OID.erase (OID.end()-3, OID.end()); 53 tail = substr (OID.end()-3, OID.end()); 54 if (tail == ".rt") { 55 get_top (inOID, OID); 56 return OID; 57 } 58 } 59 60 if (tailarray.empty()) return inOID; 61 text_tarray::const_iterator begin = tailarray.begin(); 62 text_tarray::const_iterator here = tailarray.end() - 1; 63 64 while (here >= begin) { 65 66 if (*here == ".fc") 67 get_first_child (OID, info); 68 else if (*here == ".lc") 69 get_last_child (OID, info); 70 else if (*here == ".pr") 71 OID = get_parent (OID); 72 else if (*here == ".ns") 73 get_next_sibling (OID, info); 74 else if (*here == ".ps") 75 get_previous_sibling (OID, info); 76 77 if (here == begin) 78 break; 79 --here; 80 } 81 82 return OID; 83 } 84 85 86 void dbclass::get_first_child (text_t &OID, infodbclass &info) 87 { 88 text_t firstchild; 89 if (getinfo (OID, info)) { 90 text_t &contains = info["contains"]; 91 if (!contains.empty()) { 92 text_t parent = OID; 93 getdelimitstr (contains.begin(), contains.end(), ';', firstchild); 94 if (firstchild.empty()) OID = contains; 95 else OID = firstchild; 96 if (*(OID.begin()) == '"') translate_parent (OID, parent); 97 } 98 } 99 } 100 101 102 void dbclass::get_last_child (text_t &OID, infodbclass &info) 103 { 104 text_tarray children; 105 if (getinfo (OID, info)) { 106 text_t &contains = info["contains"]; 107 if (!contains.empty()) { 108 text_t parent = OID; 109 splitchar (contains.begin(), contains.end(), ';', children); 110 OID = children.back(); 111 if (*(OID.begin()) == '"') translate_parent (OID, parent); 112 } 113 } 114 } 115 116 117 void dbclass::get_next_sibling (text_t &OID, infodbclass &info) 118 { 119 text_tarray siblings; 120 text_t parent = get_parent (OID); 121 122 if (getinfo (parent, info)) { 123 text_t &contains = info["contains"]; 124 if (!contains.empty()) { 125 splitchar (contains.begin(), contains.end(), ';', siblings); 126 text_tarray::const_iterator here = siblings.begin(); 127 text_tarray::const_iterator end = siblings.end(); 128 text_t shrunk_OID = OID; 129 shrink_parent (shrunk_OID); 130 while (here != end) { 131 if (*here == shrunk_OID && (here+1 != end)) { 132 OID = *(here+1); 133 if (*(OID.begin()) == '"') translate_parent (OID, parent); 134 break; 135 } 136 ++here; 137 } 138 } 139 } 140 } 141 142 143 void dbclass::get_previous_sibling (text_t &OID, infodbclass &info) 144 { 145 text_tarray siblings; 146 text_t parent = get_parent (OID); 147 148 if (getinfo (parent, info)) { 149 text_t &contains = info["contains"]; 150 if (!contains.empty()) { 151 splitchar (contains.begin(), contains.end(), ';', siblings); 152 text_tarray::const_iterator here = siblings.begin(); 153 text_tarray::const_iterator end = siblings.end(); 154 text_t shrunk_OID = OID; 155 shrink_parent (shrunk_OID); 156 while (here != end) { 157 if (*here == shrunk_OID && (here != siblings.begin())) { 158 OID = *(here-1); 159 if (*(OID.begin()) == '"') translate_parent (OID, parent); 160 break; 161 } 162 ++here; 163 } 164 } 165 } 166 }
Note:
See TracChangeset
for help on using the changeset viewer.