bookmark_tree.h

Go to the documentation of this file.
00001 #ifndef BOOKMARK_TREE_CLASS
00002 #define BOOKMARK_TREE_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : bookmark_tree                                                     *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *  Purpose:                                                                   *
00010 *                                                                             *
00011 *    Parses a link database in HOOPLE format into tree structure.             *
00012 *                                                                             *
00013 *******************************************************************************
00014 * Copyright (c) 2005-$now By Author.  This program is free software; you can  *
00015 * redistribute it and/or modify it under the terms of the GNU General Public  *
00016 * License as published by the Free Software Foundation; either version 2 of   *
00017 * the License or (at your option) any later version.  This is online at:      *
00018 *     http://www.fsf.org/copyleft/gpl.html                                    *
00019 * Please send any updates to: fred@gruntose.com                               *
00020 \*****************************************************************************/
00021 
00022 #include <basis/istring.h>
00023 #include <data_struct/amorph.h>
00024 #include <nodes/symbol_tree.h>
00025 
00026 // forward.
00027 class inner_mark_tree;
00028 class link_record;
00029 class listo_links;
00030 class symbol_int;
00031 class string_table;
00032 
00034 
00035 class bookmark_tree
00036 {
00037 public:
00038   bookmark_tree();
00039   virtual ~bookmark_tree();
00040   IMPLEMENT_CLASS_NAME("bookmark_tree");
00041 
00042   int read_csv_file(const istring &input_filename);
00043     // reads the file contents of "input_filename" into this tree.
00044 
00045   static void break_name(const istring &to_break, istring &name,
00046           istring &nick);
00047     // breaks a category name into the two components, if they exist.
00048 
00049   static bool magic_category_comparison(const istring &a, const istring &b);
00050     // compares the two strings "a" and "b" and returns true if either the
00051     // main name or the nickname matches either.
00052 
00053   inner_mark_tree *process_category(const string_array &items);
00054 
00055   void process_link(const string_array &items);
00056 
00057   void process_comment(const istring &current_line_in);
00058 
00059   inner_mark_tree *find_parent(const istring &parent_name);
00060     // locates the parent called "parent_name" given the context that
00061     // we've saved about the last parent.
00062 
00063   // these provide access to the information held about the tree...
00064 
00065   inner_mark_tree &access_root();  // allows access to the root of the tree.
00066 
00067   int link_count() const { return _link_count; }
00068 
00069   int category_count() const { return _category_count; }
00070 
00071 // public data members...  currently this is used outside the class.
00072   int _line_number;  // the current line in the database.
00073 
00074 private:
00075   inner_mark_tree *_mark_tree;  // our tree of categories.
00076   int _link_count;  // number of links.
00077   int _category_count;  // number of categories.
00078   inner_mark_tree *_last_parent;  // the last parent we saw.
00079   inner_mark_tree *_last_node;  // the last node we touched.
00080   symbol_int *_links_seen;  // URLs we've seen.
00081   string_table *_category_names;  // used to enforce uniqueness of categories.
00082 };
00083 
00085 
00086 class link_record
00087 {
00088 public:
00089   istring _description;
00090   istring _url;
00091   int _uid;
00092 
00093   link_record(const istring &description, const istring &url, int uid)
00094       : _description(description), _url(url), _uid(uid) {}
00095 };
00096 
00098 
00099 class listo_links : public amorph<link_record>
00100 {
00101 public:
00102   listo_links();
00103 
00104   void add(link_record *new_rec, bool sort = true);
00105 
00106 private:
00107   int _next_index;  // tracks where we've added unsorted items.
00108 };
00109 
00111 
00112 class inner_mark_tree : public nodes::symbol_tree
00113 {
00114 public:
00115   listo_links _links;  // the list held at this node.
00116   int _uid;  // the unique identifier of this node.
00117 
00118   inner_mark_tree(const istring &node_name, int uid, int max_bits = 2)
00119   : nodes::symbol_tree(node_name, max_bits), _uid(uid) {}
00120 
00121 };
00122 
00124 
00125 #endif
00126 

Generated on Thu Nov 20 04:28:43 2008 for HOOPLE Libraries by  doxygen 1.5.1