Content-Based Networking Simulation Library Documentation (v. 1.2.1)

WorkloadParser.h

00001 // -*- C++ -*-
00002 //
00003 //  This file is part of CBNSIM, the Content-Based Networking
00004 //  Simulation Library.
00005 //
00006 //  Authors: See the file AUTHORS for full details.
00007 //
00008 //  Copyright (C) 2002-2004 University of Colorado
00009 //
00010 //  This program is free software; you can redistribute it and/or
00011 //  modify it under the terms of the GNU General Public License
00012 //  as published by the Free Software Foundation; either version 2
00013 //  of the License, or (at your option) any later version.
00014 //
00015 //  This program is distributed in the hope that it will be useful,
00016 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //  GNU General Public License for more details.
00019 //
00020 //  You should have received a copy of the GNU General Public License
00021 //  along with this program; if not, write to the Free Software
00022 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
00023 //  USA, or send email to serl@cs.colorado.edu.
00024 //
00025 // $Id: WorkloadParser.h,v 1.2 2004/01/08 07:01:50 rutherfo Exp $
00026 //
00027 #ifndef CBNSIM_WORKLOADPARSER_H
00028 #define CBNSIM_WORKLOADPARSER_H
00029 
00030 #include <istream>
00031 #include <map>
00032 #include <set>
00033 #include <siena/types.h>
00034 #include <vector>
00035 #include "cbnsim/WorkloadEvent.h"
00036 #include "cbnsim/WorkloadEventParser.h"
00037 #include "cbnsim/parse_exception.h"
00038 
00039 namespace cbnsim
00040 {
00046   class WorkloadParser
00047   {
00048   public:
00049     enum TOK { AMP,
00050                BOOL,
00051                COMMA,
00052                DOUBLE,
00053                END,
00054                ID,
00055                INTEGER,
00056                LINK,
00057                NODE,
00058                OP,
00059                PIPE,
00060                SEMICOLON,
00061                SIM_LENGTH,
00062                STRING,
00063                TIME_UNIT,
00064                TOK_COUNT };
00065   
00066   private:
00067     typedef std::pair<unsigned int,unsigned int> Link;
00068     typedef std::map<Link,unsigned int> LinkMap;
00069     typedef std::set<Link> LinkSet;
00070 
00071     class Node
00072     {
00073     public:
00074       unsigned int id, x, y;
00075       Node( unsigned int p_id, unsigned int p_x, unsigned int p_y )
00076         : id( p_id ), x( p_x ), y( p_y ) {}
00077     };
00078     typedef std::map<unsigned int,Node> NodeMap;
00079   
00080     WorkloadEvent               *m_event_ptr;
00081     std::map<std::string,WorkloadEventParser*> m_event_parsers;
00082     std::istream*               m_in;
00083     LinkMap                     m_link_map;
00084     LinkSet                     m_link_set;
00085     NodeMap                     m_nodes;
00086     double                      m_time_unit;
00087     TOK                         m_tok;
00088     unsigned int                m_sim_length;
00089     std::string                 m_val;
00090 
00091     void                        link_list() throw ( parse_exception );
00092 
00093     void                        node_list() throw ( parse_exception );
00094 
00095     void                        sim_length() throw ( parse_exception );
00096 
00097     void                        time_unit() throw ( parse_exception );
00098 
00099   public:
00100     WorkloadParser();
00101   
00102     virtual ~WorkloadParser();
00103   
00104     void                        add( WorkloadEventParser* ep )
00105     { m_event_parsers.insert( make_pair( ep->event_name(), ep ) ); }
00106 
00107     void                        advance() throw ( parse_exception );
00108 
00109     void                        eat( TOK tok ) throw ( parse_exception );
00110 
00111     bool                        eat_bool() throw ( parse_exception );
00112 
00113     std::string                 eat_id() throw ( parse_exception );
00114 
00115     int                         eat_integer() throw ( parse_exception );
00116 
00117     double                      eat_double() throw ( parse_exception );
00118 
00119     siena::operator_id          eat_op() throw ( parse_exception );
00120 
00121     std::string                 eat_string() throw ( parse_exception );
00122 
00123     const std::set< std::pair<unsigned int, unsigned int> >& get_links() const
00124     { return m_link_set; }
00125     
00126     unsigned int                get_link_weight( unsigned int from, unsigned int to ) const;
00127 
00128     unsigned int                get_node_count() const;
00129 
00130     unsigned int                get_node_x( unsigned int id ) const;
00131 
00132     unsigned int                get_node_y( unsigned int id ) const;
00133 
00134     unsigned int                get_sim_length() const;
00135 
00136     double                      get_time_unit() const;
00137 
00138     bool                        isbool() const;
00139 
00140     bool                        isdouble() const;
00141   
00142     bool                        isid() const;
00143 
00144     bool                        isinteger() const;
00145 
00146     bool                        isop() const;
00147 
00148     bool                        isstring() const;
00149 
00150     unsigned int                get_link_count() const;
00151 
00152     const WorkloadEvent*        next_event() throw ( parse_exception );
00153 
00154     void                        parse_topology() throw ( parse_exception );
00155 
00156     void                        set_istream( std::istream& in ) { m_in = &in; }
00157 
00158     TOK                         tok() { return m_tok; }
00159 
00160     const std::string&          val() { return m_val; }
00161   };
00162 };
00163 #endif