/********************************************************************** * * OIDtools.cpp -- * Copyright (C) 1999 The New Zealand Digital Library Project * * PUT COPYRIGHT NOTICE HERE * * $Id: OIDtools.cpp 213 1999-03-29 02:14:31Z sjboddie $ * *********************************************************************/ /* $Log$ Revision 1.4 1999/03/29 02:14:25 sjboddie More changes to browseaction Revision 1.3 1999/03/25 03:13:42 sjboddie More library functions for dealing with OIDs. Many of them just return dummy data at present Revision 1.2 1999/03/05 03:53:53 sjboddie fixed some bugs Revision 1.1 1999/03/04 22:38:20 sjboddie Added subjectbrowseaction. - Doesn't do anything yet. */ #include "OIDtools.h" // get first four characters of whatever string is passed in // OID. This returns the CLSU, HASH etc. void get_head (const text_t &OID, text_t &head) { head.clear(); if (OID.size() < 4) return; head.appendrange (OID.begin(), (OID.begin() + 4)); } // returns (in top) the top level of OID (i.e. everything // up until the first dot) void get_top (const text_t &OID, text_t &top) { top.clear(); text_t::const_iterator begin = OID.begin(); text_t::const_iterator end = OID.end(); top.appendrange (begin, findchar(begin, end, '.')); } // checks if OID is top level (i.e. contains no dots) bool is_top (const text_t &OID) { if (OID.empty()) return true; text_t::const_iterator here = OID.begin(); text_t::const_iterator end = OID.end(); here = findchar (here, end, '.'); if (here == end) return true; return false; } // is_classification checks OID to see if it's a classification // or a document. I'm not sure how to do this - for now I'll just assume // all documents start with HASH and classifications start with something // else. bool is_classification (const text_t &OID) { text_t head; get_head (OID, head); if (head == "HASH") return false; return true; } // don't know how to do this yet either ... bool contains_text (const text_t &/*OID*/) { return true; } // get_parents_array loads the parents array with all the parents of the // document or classification specified by OID // note that this function doesn't clear the parents array void get_parents_array (const text_t &OID, text_tarray &parents) { text_t::const_iterator here = OID.begin (); text_t::const_iterator end = OID.end (); text_t thisparent; while (here != end) { if (*here == '.') parents.push_back(thisparent); thisparent.push_back(*here); here ++; } } // get_children_array loads the children array with all the children of the // document or classification specified by OID void get_children_array (const text_t &OID, text_tarray &children) { children.erase(children.begin(), children.end()); // just stuff some rubish in for now children.push_back (OID + ".1"); children.push_back (OID + ".2"); children.push_back (OID + ".3"); children.push_back (OID + ".4"); children.push_back (OID + ".5"); children.push_back (OID + ".6"); children.push_back (OID + ".7"); } // get_parent returns the parent of the document or classification // specified by OID text_t get_parent (text_t OID) { if (OID.empty() || is_top (OID)) return ""; text_t::const_iterator begin = OID.begin(); text_t::const_iterator here = (OID.end() - 1); while (here >= begin) { OID.pop_back(); if (*here == '.') break; here --; } return OID; } // get_first_child loads child with the first // child of OID void get_first_child(const text_t &OID, text_t &child) { // shove something in for now - I think we'll need to // look up db here child.clear(); child += OID + ".1"; }