xorp

template_tree.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2011 XORP, Inc and Others
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, Version 2, June
00007 // 1991 as published by the Free Software Foundation. Redistribution
00008 // and/or modification of this program under the terms of any other
00009 // version of the GNU General Public License is not permitted.
00010 // 
00011 // This program is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00014 // see the GNU General Public License, Version 2, a copy of which can be
00015 // found in the XORP LICENSE.gpl file.
00016 // 
00017 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00018 // http://xorp.net
00019 
00020 // $XORP: xorp/rtrmgr/template_tree.hh,v 1.27 2008/10/02 21:58:25 bms Exp $
00021 
00022 #ifndef __RTRMGR_TEMPLATE_TREE_HH__
00023 #define __RTRMGR_TEMPLATE_TREE_HH__
00024 
00025 
00026 
00027 
00028 
00029 
00030 #include "path_segment.hh"
00031 #include "rtrmgr_error.hh"
00032 #include "xorp_client.hh"
00033 
00034 
00035 class ModuleCommand;
00036 class TemplateTreeNode;
00037 class ConfPathSegment;
00038 
00039 class TemplateTree {
00040 public:
00041     TemplateTree(const string& xorp_root_dir,
00042          bool verbose)  throw (InitError);
00043     virtual ~TemplateTree();
00044     
00045     bool load_template_tree(const string& config_template_dir,
00046                 string& error_msg);
00047     bool parse_file(const string& filename, 
00048             const string& config_template_dir, string& error_msg);
00049     
00050     void extend_path(const string& segment, bool is_tag);
00051     void pop_path() throw (ParseError);
00052     void push_path(int type, char* initializer);
00053     void add_untyped_node(const string& segment, bool is_tag) throw (ParseError);
00054     void add_node(const string& segment, int type, char* initializer);
00055     const TemplateTreeNode* find_node(const list<string>& path_segments) const;
00056     const TemplateTreeNode* 
00057         find_node_by_type(const list<ConfPathSegment>& path_segments) const;
00058     string path_as_string();
00059     void add_cmd(char* cmd) throw (ParseError);
00060     void add_cmd_action(const string& cmd, const list<string>& action)
00061     throw (ParseError);
00062     string tree_str() const;
00063     void register_module(const string& name, ModuleCommand* mc);
00064     ModuleCommand* find_module(const string& name);
00065     bool check_variable_name(const string& s) const;
00066     TemplateTreeNode* root_node() const { return _root_node; }
00067     const string& xorp_root_dir() const { return _xorp_root_dir; }
00068     bool verbose() const { return _verbose; }
00069 
00070 protected:
00071     TemplateTreeNode* new_node(TemplateTreeNode* parent,
00072                    const string& path,
00073                    const string& varname,
00074                    int type,
00075                    const string& initializer);
00076 
00077     bool expand_template_tree(string& error_msg);
00078     bool check_template_tree(string& error_msg);
00079 
00080 
00081     TemplateTreeNode*   _root_node;
00082     TemplateTreeNode*   _current_node;
00083     map<string, ModuleCommand *> _registered_modules;
00084     list<PathSegment>   _path_segments;
00085     list<size_t>    _segment_lengths;
00086     string      _xorp_root_dir; // The root of the XORP tree
00087     bool        _verbose;   // Set to true if output is verbose
00088 };
00089 
00090 #endif // __RTRMGR_TEMPLATE_TREE_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations