Line data Source code
1 : /*******************************************************************************
2 : * *
3 : * Cosmos:(C)oncept et (O)utils (S)tatistique pour les (Mo)deles *
4 : * (S)tochastiques *
5 : * *
6 : * Copyright (C) 2009-2012 LSV & LACL *
7 : * Authors: Paolo Ballarini BenoƮt Barbot & Hilal Djafri *
8 : * Website: http://www.lsv.ens-cachan.fr/Software/cosmos *
9 : * *
10 : * This program is free software; you can redistribute it and/or modify *
11 : * it under the terms of the GNU General Public License as published by *
12 : * the Free Software Foundation; either version 3 of the License, or *
13 : * (at your option) any later version. *
14 : * *
15 : * This program is distributed in the hope that it will be useful, *
16 : * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 : * GNU General Public License for more details. *
19 : * *
20 : * You should have received a copy of the GNU General Public License along *
21 : * with this program; if not, write to the Free Software Foundation, Inc., *
22 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
23 : * file casesWriter.hpp *
24 : * Created by Benoit Barbot on 11/09/13. *
25 : *******************************************************************************
26 : */
27 :
28 : #ifndef Cosmos_casesWriter_h
29 : #define Cosmos_casesWriter_h
30 :
31 : #include <string>
32 : #include <vector>
33 : #include <ostream>
34 : #include <map>
35 : #include <stdio.h>
36 : #include <string.h>
37 : #include <functional>
38 :
39 : struct cmp_str
40 : {
41 43368 : bool operator()(const std::string a,const std::string b)const{
42 43368 : return a.compare(b) < 0;
43 : }
44 : };
45 :
46 : /**
47 : * \brief A class allowing to generate efficient switch case pattern in the
48 : * generated code. It allows to merge identical case together and thus
49 : * reduce the size of the generated code
50 : */
51 :
52 668 : class casesHandler {
53 : public:
54 : //! Build a new cases handler over a given variable.
55 : casesHandler(std::string svar);
56 : void addCase(int c,const std::string &st,const std::string &comment="");
57 : void addDefault(const std::string &st);
58 : void writeCases(std::ostream &s);
59 : private:
60 : int maxc;
61 : std::string defaultvalue;
62 : const std::string scase;
63 : bool hasDefault;
64 : std::map<const std::string,int,cmp_str> cases;
65 : std::map<int,std::string> mapping;
66 : std::map<int,std::string> mapcomment;
67 : };
68 :
69 : std::ostream& operator<<(std::ostream& os, casesHandler& obj);
70 :
71 :
72 :
73 :
74 : #endif
|