xorp

template_base_command.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_base_command.hh,v 1.13 2008/10/02 21:58:25 bms Exp $
00021 
00022 #ifndef __RTRMGR_TEMPLATE_BASE_COMMAND_HH__
00023 #define __RTRMGR_TEMPLATE_BASE_COMMAND_HH__
00024 
00025 
00026 
00027 
00028 
00029 
00030 #include "libxorp/callback.hh"
00031 #include "rtrmgr_error.hh"
00032 #include "config_operators.hh"
00033 
00034 class TemplateTree;
00035 class TemplateTreeNode;
00036 class ConfigTreeNode;
00037 
00038 class BaseCommand {
00039 public:
00040     BaseCommand(TemplateTreeNode& template_tree_node, const string& cmd_name);
00041     virtual ~BaseCommand();
00042 
00043     virtual bool expand_actions(string& error_msg) = 0;
00044     virtual bool check_referred_variables(string& error_msg) const = 0;
00045 
00046     virtual string str() const;
00047     TemplateTreeNode& template_tree_node() { return _template_tree_node; }
00048     const TemplateTreeNode& template_tree_node() const { return _template_tree_node; }
00049 
00050 protected:
00051     string      _cmd_name;
00052     TemplateTreeNode&   _template_tree_node;
00053 };
00054 
00055 class DummyBaseCommand : public BaseCommand {
00056 public:
00057     DummyBaseCommand(TemplateTreeNode& template_tree_node,
00058              const string& cmd_name)
00059     : BaseCommand(template_tree_node, cmd_name) {}
00060     virtual ~DummyBaseCommand() {}
00061 
00062     virtual bool expand_actions(string& error_msg) {
00063     UNUSED(error_msg);
00064     return (true);
00065     }
00066 
00067     virtual bool check_referred_variables(string& error_msg) const {
00068     UNUSED(error_msg);
00069     return (true);
00070     }
00071 
00072 private:
00073 };
00074 
00075 class AllowCommand : public BaseCommand {
00076 public:
00077     AllowCommand(TemplateTreeNode& template_tree_node, const string& cmd_name);
00078 
00079     virtual void add_action(const list<string>& action) throw (ParseError) = 0;
00080     virtual bool verify_variables(const ConfigTreeNode& ctn,
00081                   string& error_msg) const = 0;
00082 
00083     virtual string str() const = 0;
00084 };
00085 
00086 class AllowOptionsCommand : public AllowCommand {
00087 public:
00088     AllowOptionsCommand(TemplateTreeNode& template_tree_node,
00089             const string& cmd_name);
00090 
00091     virtual bool expand_actions(string& error_msg);
00092     virtual bool check_referred_variables(string& error_msg) const;
00093     virtual void add_action(const list<string>& action) throw (ParseError);
00094     virtual bool verify_variables(const ConfigTreeNode&     ctn,
00095                   string& error_msg) const;
00096 
00097     virtual string str() const;
00098 
00099 private:
00100     typedef map<string, string> Filter; // Map between a value and help string
00101     map<string, Filter> _filters;   // Map between a varname and a filter
00102 };
00103 
00104 class AllowOperatorsCommand : public AllowCommand {
00105 public:
00106     AllowOperatorsCommand(TemplateTreeNode& template_tree_node,
00107               const string& cmd_name);
00108 
00109     virtual bool expand_actions(string& error_msg);
00110     virtual bool check_referred_variables(string& error_msg) const;
00111     virtual void add_action(const list<string>& action) throw (ParseError);
00112     virtual bool verify_variables(const ConfigTreeNode&     ctn,
00113                   string& error_msg) const;
00114     virtual bool verify_variable_by_value(const ConfigTreeNode& ctn,
00115                       const string& value,
00116                       string& error_msg) const;
00117     virtual list<ConfigOperator> allowed_operators() const;
00118 
00119     virtual string str() const;
00120 
00121 private:
00122     string      _varname;
00123     list<ConfigOperator>    _allowed_operators;
00124 };
00125 
00126 class AllowRangeCommand : public AllowCommand {
00127 public:
00128     AllowRangeCommand(TemplateTreeNode& template_tree_node,
00129               const string& cmd_name);
00130 
00131     virtual bool expand_actions(string& error_msg);
00132     virtual bool check_referred_variables(string& error_msg) const;
00133     virtual void add_action(const list<string>& action) throw (ParseError);
00134     virtual bool verify_variables(const ConfigTreeNode& ctn,
00135                   string& error_msg) const;
00136 
00137     virtual string str() const;
00138 
00139 private:
00140     // Map between the pair of [lower, upper] boundaries and the help string
00141     typedef map<pair<int64_t, int64_t>, string> Filter;
00142     map<string, Filter> _filters;   // Map between a varname and a filter
00143 };
00144 
00145 #endif // __RTRMGR_TEMPLATE_BASE_COMMAND_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations