xorp

source_match_code_generator.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/source_match_code_generator.hh,v 1.14 2008/10/02 21:58:00 bms Exp $
00022 
00023 #ifndef __POLICY_SOURCE_MATCH_CODE_GENERATOR_HH__
00024 #define __POLICY_SOURCE_MATCH_CODE_GENERATOR_HH__
00025 
00026 
00027 
00028 
00029 
00030 
00031 #include "policy/common/policy_exception.hh"
00032 
00033 #include "code_generator.hh"
00034 
00043 class SourceMatchCodeGenerator :
00044     public NONCOPYABLE,
00045     public CodeGenerator
00046 {
00047 public:
00048     // bool == tag used
00049     // uint32_t actual tag
00050     typedef pair<bool, uint32_t> Taginfo;
00051     typedef vector<Taginfo> Tags;
00052 
00056     class NoProtoSpec : public PolicyException {
00057     public:
00058         NoProtoSpec(const char* file, size_t line, const string& init_why = "")
00059             : PolicyException("NoProtoSpec", file, line, init_why) {} 
00060     };
00061 
00065     class ProtoRedefined : public PolicyException {
00066     public:
00067         ProtoRedefined(const char* file, size_t line, const string& init_why = "")
00068             : PolicyException("ProtoRedefined", file, line, init_why) {} 
00069     };
00070 
00071 
00076     SourceMatchCodeGenerator(uint32_t tagstart, const VarMap& varmap,
00077                  PolicyMap& pmap, 
00078                 map<string, set<uint32_t> >& ptags);
00079 
00080     const Element* visit_policy(PolicyStatement& policy);
00081     const Element* visit_term(Term& term);
00082     const Element* visit_proto(NodeProto& node);
00083 
00091     vector<Code*>& codes();
00092 
00099     const Tags& tags() const;
00100 
00105     uint32_t next_tag() const;
00106 
00107 protected:
00108     const string& protocol();
00109 
00110 private:
00111     typedef map<string,Code*> CodeMap;
00112 
00113     void do_term(Term& term);
00114 
00118     void addTerm();
00119 
00120     uint32_t            _currtag;
00121     string          _protocol;
00122     CodeMap         _codes;
00123     // FIXME: who deletes these on exception ?
00124     vector<Code*>       _codes_vect; 
00125     Tags            _tags;
00126     map<string, set<uint32_t> >& _protocol_tags;
00127     bool            _protocol_statement;
00128     string          _policy;
00129 };
00130 
00131 #endif // __POLICY_SOURCE_MATCH_CODE_GENERATOR_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations