xorp

node.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8:
00003 
00004 // Copyright (c) 2001-2011 XORP, Inc and Others
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License, Version 2, June
00008 // 1991 as published by the Free Software Foundation. Redistribution
00009 // and/or modification of this program under the terms of any other
00010 // version of the GNU General Public License is not permitted.
00011 // 
00012 // This program is distributed in the hope that it will be useful, but
00013 // WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00015 // see the GNU General Public License, Version 2, a copy of which can be
00016 // found in the XORP LICENSE.gpl file.
00017 // 
00018 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00019 // http://xorp.net
00020 
00021 // $XORP: xorp/policy/node.hh,v 1.17 2008/10/02 21:57:58 bms Exp $
00022 
00023 #ifndef __POLICY_NODE_HH__
00024 #define __POLICY_NODE_HH__
00025 
00026 
00027 
00028 
00029 
00030 #include "policy/common/operator_base.hh"
00031 #include "policy/common/varrw.hh"
00032 
00033 #include "node_base.hh"
00034 #include "visitor.hh"
00035 
00039 template<class T>
00040 class NodeAny :
00041     public Node
00042 {
00043 public:
00048     NodeAny(const T& val, unsigned line) : Node(line),  _val(val) {}
00049 
00050     // semicolon for kdoc
00051     DEFINE_VISITABLE();
00052 
00056     const T& val() const { return _val; }
00057 
00058 private:
00059     T _val;
00060 };
00061 
00065 typedef NodeAny<string> NodeVar;
00066 
00072 class NodeElem :
00073     public NONCOPYABLE,
00074     public Node
00075 {
00076 public:
00083     NodeElem(Element* elem, unsigned line) : Node(line), _elem(elem) {}
00084     ~NodeElem() { delete _elem; } 
00085 
00086     DEFINE_VISITABLE();
00087 
00091     const Element& val() const { return *_elem; }
00092 
00093 private:
00094     Element* _elem;
00095 };
00096 
00102 class NodeSet : public Node {
00103 public:
00108     NodeSet(const char* c_str, unsigned line) : Node(line), _setid(c_str) {}
00109 
00110     DEFINE_VISITABLE();
00111 
00115     const string& setid() const { return _setid; }
00116 
00117 private:
00118     string _setid;
00119 };
00120 
00127 class NodeBin :
00128     public NONCOPYABLE,
00129     public Node
00130 {
00131 public:
00140     NodeBin(BinOper* op, Node* left, Node* right, unsigned line) : Node(line),
00141         _op(op), _left(left), _right(right) {}
00142     ~NodeBin() {
00143     delete _op;
00144     delete _left; 
00145     delete _right; 
00146     }
00147 
00148     DEFINE_VISITABLE();
00149 
00153     const BinOper& op() const { return *_op; }
00154 
00158     Node& left() const { return *_left; }
00159 
00163     Node& right() const { return *_right; }
00164 
00165 private:
00166     BinOper* _op;
00167     Node *_left;
00168     Node *_right;
00169 };
00170 
00176 class NodeUn :
00177     public NONCOPYABLE,
00178     public Node
00179 {
00180 public:
00188     NodeUn(UnOper* op, Node* node, unsigned line) : Node(line), _op(op),  _node(node) {}
00189     ~NodeUn() {
00190     delete _op;
00191     delete _node;
00192     }
00193 
00194     DEFINE_VISITABLE();
00195 
00199     const UnOper& op() const { return *_op; }
00200 
00204     Node& node() const { return *_node; }
00205 
00206 private:
00207     UnOper* _op;
00208     Node* _node;
00209 };
00210 
00211 
00215 class NodeAssign :
00216     public NONCOPYABLE,
00217     public Node
00218 {
00219 public:
00228     NodeAssign(const string& varid, BinOper* mod, Node* rvalue, unsigned line)
00229     : Node(line), _varid(varid), _mod(mod), _rvalue(rvalue) {}
00230     ~NodeAssign() { delete _rvalue; delete _mod; }
00231 
00232     DEFINE_VISITABLE();
00233 
00237     const string& varid() const { return _varid; }
00238 
00242     Node& rvalue() const { return *_rvalue; }
00243 
00244     BinOper* mod() const { return _mod; }
00245 
00246 private:
00247     string  _varid;
00248     BinOper*    _mod;
00249     Node*   _rvalue;
00250 };
00251 
00255 class NodeAccept : public Node {
00256 public:
00260     NodeAccept(unsigned line) : Node(line) {}
00261 
00262     DEFINE_VISITABLE();
00263 
00269     virtual bool is_accept_or_reject() const { return (true); }
00270 };
00271 
00275 class NodeReject : public Node {
00276 public:
00280     NodeReject(unsigned line) : Node(line) {}
00281 
00282     DEFINE_VISITABLE();
00283 
00289     virtual bool is_accept_or_reject() const { return (true); }
00290 };
00291 
00295 class NodeProto : public Node {
00296 public:
00301     NodeProto(const string& proto, unsigned line) : Node(line), _proto(proto) {}
00302 
00303     DEFINE_VISITABLE();
00304 
00310     virtual bool is_protocol_statement() const { return (true); }
00311 
00315     const string& proto() const { return _proto; }
00316 
00317 private:
00318     string _proto;
00319 };
00320 
00321 class NodeNext : public Node {
00322 public:
00323     enum Flow {
00324     POLICY = 0,
00325     TERM
00326     };
00327 
00328     NodeNext(unsigned line, Flow f) : Node(line), _flow(f) {}
00329 
00330     DEFINE_VISITABLE();
00331 
00332     Flow flow() const { return _flow; }
00333 
00334 private:
00335     Flow    _flow;
00336 };
00337 
00338 class NodeSubr : public Node {
00339 public:
00340     NodeSubr(unsigned line, string policy) : Node(line), _policy(policy) {}
00341 
00342     DEFINE_VISITABLE();
00343 
00344     string policy() const { return _policy; }
00345 
00346 private:
00347     string  _policy;
00348 };
00349 
00350 #endif // __POLICY_NODE_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations