xorp

command_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/command_tree.hh,v 1.17 2008/10/02 21:58:22 bms Exp $
00021 
00022 #ifndef __RTRMGR_COMMAND_TREE_HH__
00023 #define __RTRMGR_COMMAND_TREE_HH__
00024 
00025 
00026 
00027 
00028 
00029 class ConfigTreeNode;
00030 class TemplateTreeNode;
00031 
00032 class CommandTreeNode {
00033 public:
00034     CommandTreeNode(const string& name,
00035             const ConfigTreeNode* ctn,
00036             const TemplateTreeNode* ttn);
00037     ~CommandTreeNode();
00038 
00039     void add_child(CommandTreeNode* child);
00040     void set_parent(CommandTreeNode* parent) { _parent = parent; }
00041     CommandTreeNode* parent() const { return _parent; }
00042     const list<CommandTreeNode*>& children() const { return _children; }
00043     string str() const;
00044     const string& name() const { return _name; }
00045     string subtree_str() const;
00046     void set_has_command() { _has_command = true; }
00047     bool has_command() const { return _has_command; }
00048     const ConfigTreeNode* config_tree_node() const { return _config_tree_node; }
00049     const TemplateTreeNode* template_tree_node() const { return _template_tree_node;}
00050     const CommandTreeNode* subroot(list<string> path) const;
00051     const string& help() const;
00052 
00053 private:
00054     string          _name;
00055     bool            _has_command;
00056     CommandTreeNode*        _parent;
00057     const ConfigTreeNode*   _config_tree_node;
00058     const TemplateTreeNode* _template_tree_node;
00059     list<CommandTreeNode*>  _children;
00060 };
00061 
00062 class CommandTree {
00063 public:
00064     CommandTree();
00065     ~CommandTree();
00066 
00067     void push(const string& str);
00068     void pop();
00069     void instantiate(const ConfigTreeNode *ctn, const TemplateTreeNode *ttn,
00070              bool has_command);
00071     void activate_current();
00072     string tree_str() const;
00073     const CommandTreeNode& root_node() const { return _root_node; }
00074 
00075 private:
00076     list<string>    _temp_path;
00077     CommandTreeNode _root_node;
00078     CommandTreeNode*    _current_node;
00079 };
00080 
00081 #endif // __RTRMGR_COMMAND_TREE_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations