xorp

term.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/term.hh,v 1.18 2008/10/02 21:58:01 bms Exp $
00022 
00023 #ifndef __POLICY_TERM_HH__
00024 #define __POLICY_TERM_HH__
00025 
00026 
00027 
00028 
00029 
00030 
00031 #include "libproto/config_node_id.hh"
00032 
00033 #include "policy/common/policy_exception.hh"
00034 
00035 #include "node_base.hh"
00036 
00043 class Term :
00044     public NONCOPYABLE
00045 {
00046 public:
00047     enum BLOCKS {
00048     SOURCE = 0,
00049     DEST,
00050     ACTION,
00051 
00052     // keep this last
00053     LAST_BLOCK
00054     };
00055 
00056     // the integer is the "line number", the node is the parsed structure [AST]
00057     // of the statement(s) in that line.
00058     typedef ConfigNodeIdMap<Node*> Nodes;
00059 
00063     class term_syntax_error :  public PolicyException {
00064     public:
00065         term_syntax_error(const char* file, size_t line, 
00066               const string& init_why = "")   
00067             : PolicyException("term_syntax_error", file, line, init_why) {}  
00068     };
00069 
00073     Term(const string& name);
00074     ~Term();
00075    
00079     const string& name() const { return _name; }
00080     
00084     void set_term_end();
00085 
00093     void set_block(const uint32_t& block, const ConfigNodeId& order,
00094            const string& statement);
00095 
00102     void del_block(const uint32_t& block, const ConfigNodeId& order);
00103 
00110     void set_block_end(uint32_t block);
00111 
00117     const Element* accept(Visitor& v) {
00118     return v.visit(*this);
00119     }
00120 
00124     Nodes& source_nodes() { return *_source_nodes; }
00125 
00129     Nodes& dest_nodes() { return *_dest_nodes; }
00130 
00134     Nodes& action_nodes() { return *_action_nodes; }
00135 
00142     static string block2str(uint32_t num); 
00143 
00150     const string& from_protocol() const { return (_from_protocol); }
00151 
00157     void set_from_protocol(const string& v) { _from_protocol = v; }
00158 
00159 private:
00160     list<pair<ConfigNodeId, Node*> >::iterator find_out_of_order_node(
00161     const uint32_t& block, const ConfigNodeId& order);
00162 
00163     string _name;
00164 
00165     Nodes* _block_nodes[3];
00166     list<pair<ConfigNodeId, Node*> > _out_of_order_nodes[3];
00167 
00168     Nodes*& _source_nodes; 
00169     Nodes*& _dest_nodes;
00170     Nodes*& _action_nodes;
00171 
00172     string  _from_protocol; // The protocol (in the "from" block)
00173 };
00174 
00175 #endif // __POLICY_TERM_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations