1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * OIDtools.cpp --
|
---|
4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
5 | *
|
---|
6 | * PUT COPYRIGHT NOTICE HERE
|
---|
7 | *
|
---|
8 | * $Id: OIDtools.cpp 213 1999-03-29 02:14:31Z sjboddie $
|
---|
9 | *
|
---|
10 | *********************************************************************/
|
---|
11 |
|
---|
12 | /*
|
---|
13 | $Log$
|
---|
14 | Revision 1.4 1999/03/29 02:14:25 sjboddie
|
---|
15 |
|
---|
16 | More changes to browseaction
|
---|
17 |
|
---|
18 | Revision 1.3 1999/03/25 03:13:42 sjboddie
|
---|
19 |
|
---|
20 | More library functions for dealing with OIDs. Many of them just
|
---|
21 | return dummy data at present
|
---|
22 |
|
---|
23 | Revision 1.2 1999/03/05 03:53:53 sjboddie
|
---|
24 |
|
---|
25 | fixed some bugs
|
---|
26 |
|
---|
27 | Revision 1.1 1999/03/04 22:38:20 sjboddie
|
---|
28 |
|
---|
29 | Added subjectbrowseaction. - Doesn't do anything yet.
|
---|
30 |
|
---|
31 | */
|
---|
32 |
|
---|
33 | #include "OIDtools.h"
|
---|
34 |
|
---|
35 |
|
---|
36 | // get first four characters of whatever string is passed in
|
---|
37 | // OID. This returns the CLSU, HASH etc.
|
---|
38 | void get_head (const text_t &OID, text_t &head) {
|
---|
39 |
|
---|
40 | head.clear();
|
---|
41 | if (OID.size() < 4) return;
|
---|
42 | head.appendrange (OID.begin(), (OID.begin() + 4));
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | // returns (in top) the top level of OID (i.e. everything
|
---|
47 | // up until the first dot)
|
---|
48 | void get_top (const text_t &OID, text_t &top) {
|
---|
49 |
|
---|
50 | top.clear();
|
---|
51 | text_t::const_iterator begin = OID.begin();
|
---|
52 | text_t::const_iterator end = OID.end();
|
---|
53 |
|
---|
54 | top.appendrange (begin, findchar(begin, end, '.'));
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | // checks if OID is top level (i.e. contains no dots)
|
---|
59 | bool is_top (const text_t &OID) {
|
---|
60 |
|
---|
61 | if (OID.empty()) return true;
|
---|
62 |
|
---|
63 | text_t::const_iterator here = OID.begin();
|
---|
64 | text_t::const_iterator end = OID.end();
|
---|
65 | here = findchar (here, end, '.');
|
---|
66 |
|
---|
67 | if (here == end) return true;
|
---|
68 | return false;
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 | // is_classification checks OID to see if it's a classification
|
---|
73 | // or a document. I'm not sure how to do this - for now I'll just assume
|
---|
74 | // all documents start with HASH and classifications start with something
|
---|
75 | // else.
|
---|
76 | bool is_classification (const text_t &OID) {
|
---|
77 | text_t head;
|
---|
78 | get_head (OID, head);
|
---|
79 | if (head == "HASH") return false;
|
---|
80 | return true;
|
---|
81 | }
|
---|
82 |
|
---|
83 |
|
---|
84 | // don't know how to do this yet either ...
|
---|
85 | bool contains_text (const text_t &/*OID*/) {
|
---|
86 | return true;
|
---|
87 | }
|
---|
88 |
|
---|
89 |
|
---|
90 | // get_parents_array loads the parents array with all the parents of the
|
---|
91 | // document or classification specified by OID
|
---|
92 | // note that this function doesn't clear the parents array
|
---|
93 | void get_parents_array (const text_t &OID, text_tarray &parents) {
|
---|
94 |
|
---|
95 | text_t::const_iterator here = OID.begin ();
|
---|
96 | text_t::const_iterator end = OID.end ();
|
---|
97 | text_t thisparent;
|
---|
98 |
|
---|
99 | while (here != end) {
|
---|
100 | if (*here == '.') parents.push_back(thisparent);
|
---|
101 | thisparent.push_back(*here);
|
---|
102 | here ++;
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | // get_children_array loads the children array with all the children of the
|
---|
108 | // document or classification specified by OID
|
---|
109 | void get_children_array (const text_t &OID, text_tarray &children) {
|
---|
110 |
|
---|
111 | children.erase(children.begin(), children.end());
|
---|
112 |
|
---|
113 | // just stuff some rubish in for now
|
---|
114 | children.push_back (OID + ".1");
|
---|
115 | children.push_back (OID + ".2");
|
---|
116 | children.push_back (OID + ".3");
|
---|
117 | children.push_back (OID + ".4");
|
---|
118 | children.push_back (OID + ".5");
|
---|
119 | children.push_back (OID + ".6");
|
---|
120 | children.push_back (OID + ".7");
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | // get_parent returns the parent of the document or classification
|
---|
125 | // specified by OID
|
---|
126 | text_t get_parent (text_t OID) {
|
---|
127 |
|
---|
128 | if (OID.empty() || is_top (OID)) return "";
|
---|
129 |
|
---|
130 | text_t::const_iterator begin = OID.begin();
|
---|
131 | text_t::const_iterator here = (OID.end() - 1);
|
---|
132 |
|
---|
133 | while (here >= begin) {
|
---|
134 | OID.pop_back();
|
---|
135 | if (*here == '.') break;
|
---|
136 | here --;
|
---|
137 | }
|
---|
138 | return OID;
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 | // get_first_child loads child with the first
|
---|
143 | // child of OID
|
---|
144 | void get_first_child(const text_t &OID, text_t &child) {
|
---|
145 | // shove something in for now - I think we'll need to
|
---|
146 | // look up db here
|
---|
147 | child.clear();
|
---|
148 | child += OID + ".1";
|
---|
149 | }
|
---|