Debian Codegraph @

src/mas/any.cpp

raw symbols SCIP
1 /***************************************************************************
2 any.cpp - description
3 -------------------
4 begin : nov 29th, 2005
5 copyright : (C) 2005-2010 by Duong Khang NGUYEN
6 email : neoneurone @ gmail com
7 author : Victor STINNER
8
9 $Id: any.cpp 448 2010-05-09 15:18:32Z neoneurone $
10 ***************************************************************************/
11
12 /***************************************************************************
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * any later version. *
18 * *
19 ***************************************************************************/
20
21
22 #include "any.h"
23 #include "agent.h" ///< For debug macros
24
25 #include <cassert>
26 #include <iostream>
27
28
29 /*=====================================================================*/
30 Any::Any( int value ):
31 _type(ANY_INT),
32 _intValue(value)
33 {}
34
35
36 /*=====================================================================*/
37 Any::Any( unsigned int value ):
38 _type(ANY_UINT),
39 _uintValue(value)
40 {}
41
42
43 /*=====================================================================*/
44 Any::Any( double value ):
45 _type(ANY_DOUBLE),
46 _doubleValue(value)
47 {}
48
49
50 /*=====================================================================*/
51 Any::Any( const std::string& value ):
52 _type(ANY_STRING),
53 _stringValue(value)
54 {}
55
56
57 /*=====================================================================*/
58 MAS_ANY_TYPE
59 Any::getType() const
60 {
61 return _type;
62 }
63
64
65 /*=====================================================================*/
66 int
67 Any::getInt() const
68 {
69 assert (_type == ANY_INT);
70 return _intValue;
71 }
72
73
74 /*=====================================================================*/
75 unsigned int
76 Any::getUInt() const
77 {
78 assert (_type == ANY_UINT);
79 return _uintValue;
80 }
81
82
83 /*=====================================================================*/
84 double
85 Any::getDouble() const
86 {
87 assert (_type == ANY_DOUBLE);
88 return _doubleValue;
89 }
90
91
92 /*=====================================================================*/
93 const std::string&
94 Any::getString() const
95 {
96 assert (_type == ANY_STRING);
97 return _stringValue;
98 }
99
100
101 /*=====================================================================*/
102 std::ostream&
103 operator<< (std::ostream &os, const Any &any)
104 {
105 switch (any.getType())
106 {
107 case ANY_INT:
108 MAS_DEBUG( "(int)" );
109 os << any.getInt();
110 break;
111 case ANY_UINT:
112 MAS_DEBUG( "(uint)" );
113 os << any.getUInt();
114 break;
115 case ANY_DOUBLE:
116 MAS_DEBUG( "(double)" );
117 os << any.getDouble();
118 break;
119 case ANY_STRING:
120 MAS_DEBUG( "(str)" );
121 os << '"' << any.getString() << '"';
122 break;
123 }
124 return os;
125 }