MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
TypedValue Class Reference

#include <mathtyp.h>

Collaboration diagram for TypedValue:

Classes

class  ErrConstraintViolation
 
class  ErrUnknownType
 
class  ErrUnknownValue
 
class  ErrWrongType
 

Public Types

enum  Type {
  VAR_UNKNOWN = -1, VAR_BOOL, VAR_INT, VAR_REAL,
  VAR_STRING, VAR_LAST
}
 
enum  TypeModifier { MOD_UNKNOWN = -1, MOD_CONST, MOD_LAST }
 

Public Member Functions

 TypedValue (void)
 
 ~TypedValue (void)
 
 TypedValue (const bool &b, bool isConst=false)
 
 TypedValue (const Int &i, bool isConst=false)
 
 TypedValue (const Real &r, bool isConst=false)
 
 TypedValue (const std::string &s, bool isConst=false)
 
 TypedValue (const TypedValue::Type t, bool isConst=false)
 
 TypedValue (const TypedValue &var)
 
TypedValueoperator= (const TypedValue &var)
 
TypedValueCast (const TypedValue &var, bool bErr=false)
 
TypedValue::Type GetType (void) const
 
const char *const GetTypeName (void) const
 
bool Const (void) const
 
bool GetBool (void) const
 
Int GetInt (void) const
 
Real GetReal (void) const
 
const std::string & GetString (void) const
 
void SetType (TypedValue::Type t, bool isConst=false)
 
void SetConst (bool isConst=true, bool bForce=false)
 
const TypedValueSet (const bool &b)
 
const TypedValueSet (const Int &i)
 
const TypedValueSet (const Real &r)
 
const TypedValueSet (const std::string &s)
 
bool operator&& (const TypedValue &v) const
 
bool operator|| (const TypedValue &v) const
 
bool operator> (const TypedValue &v) const
 
bool operator>= (const TypedValue &v) const
 
bool operator== (const TypedValue &v) const
 
bool operator<= (const TypedValue &v) const
 
bool operator< (const TypedValue &v) const
 
bool operator!= (const TypedValue &v) const
 
TypedValue operator+ (const TypedValue &v) const
 
TypedValue operator- (const TypedValue &v) const
 
TypedValue operator* (const TypedValue &v) const
 
TypedValue operator/ (const TypedValue &v) const
 
TypedValue operator% (const TypedValue &v) const
 
const TypedValueoperator+= (const TypedValue &v)
 
const TypedValueoperator-= (const TypedValue &v)
 
const TypedValueoperator*= (const TypedValue &v)
 
const TypedValueoperator/= (const TypedValue &v)
 
const TypedValueoperator%= (const TypedValue &v)
 

Static Public Member Functions

static const char *const GetTypeName (TypedValue::Type t)
 

Protected Attributes

TypedValue::Type type
 
bool bConst
 
union {
   Int   i
 
   Real   r
 
v
 
std::string s
 

Detailed Description

Definition at line 43 of file mathtyp.h.

Member Enumeration Documentation

Enumerator
VAR_UNKNOWN 
VAR_BOOL 
VAR_INT 
VAR_REAL 
VAR_STRING 
VAR_LAST 

Definition at line 45 of file mathtyp.h.

Enumerator
MOD_UNKNOWN 
MOD_CONST 
MOD_LAST 

Definition at line 56 of file mathtyp.h.

56  {
57  MOD_UNKNOWN = -1,
58 
59  MOD_CONST,
60 
61  MOD_LAST
62  };

Constructor & Destructor Documentation

TypedValue::TypedValue ( void  )

Definition at line 874 of file mathp.cc.

References NO_OP.

Referenced by operator%(), operator*(), operator+(), operator-(), and operator/().

876 {
877  NO_OP;
878 }
TypedValue::Type type
Definition: mathtyp.h:86
#define NO_OP
Definition: myassert.h:74
bool bConst
Definition: mathtyp.h:87
TypedValue::~TypedValue ( void  )

Definition at line 880 of file mathp.cc.

References NO_OP.

881 {
882  NO_OP;
883 }
#define NO_OP
Definition: myassert.h:74
TypedValue::TypedValue ( const bool b,
bool  isConst = false 
)

Definition at line 885 of file mathp.cc.

References v.

886 : type(TypedValue::VAR_BOOL), bConst(isConst)
887 {
888  v.i = b;
889 }
TypedValue::Type type
Definition: mathtyp.h:86
union TypedValue::@14 v
bool bConst
Definition: mathtyp.h:87
TypedValue::TypedValue ( const Int i,
bool  isConst = false 
)
TypedValue::TypedValue ( const Real r,
bool  isConst = false 
)

Definition at line 897 of file mathp.cc.

References r, and v.

898 : type(TypedValue::VAR_REAL), bConst(isConst)
899 {
900  v.r = r;
901 }
TypedValue::Type type
Definition: mathtyp.h:86
union TypedValue::@14 v
bool bConst
Definition: mathtyp.h:87
Real r
Definition: mathtyp.h:90
TypedValue::TypedValue ( const std::string &  s,
bool  isConst = false 
)

Definition at line 903 of file mathp.cc.

References NO_OP.

904 : type(TypedValue::VAR_STRING), bConst(isConst), s(s)
905 {
906  NO_OP;
907 }
TypedValue::Type type
Definition: mathtyp.h:86
#define NO_OP
Definition: myassert.h:74
bool bConst
Definition: mathtyp.h:87
std::string s
Definition: mathtyp.h:92
TypedValue::TypedValue ( const TypedValue::Type  t,
bool  isConst = false 
)

Definition at line 909 of file mathp.cc.

References MBDYN_EXCEPT_ARGS, s, type, v, VAR_BOOL, VAR_INT, VAR_REAL, and VAR_STRING.

910 : type(t), bConst(isConst)
911 {
912  switch (type) {
914  case TypedValue::VAR_INT:
915  v.i = 0;
916  break;
917 
919  v.r = 0.;
920  break;
921 
923  s = "";
924  break;
925 
926  default:
927  throw ErrUnknownType(MBDYN_EXCEPT_ARGS);
928  }
929 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type type
Definition: mathtyp.h:86
union TypedValue::@14 v
bool bConst
Definition: mathtyp.h:87
std::string s
Definition: mathtyp.h:92
TypedValue::TypedValue ( const TypedValue var)

Definition at line 932 of file mathp.cc.

References ASSERT, i, MBDYN_EXCEPT_ARGS, r, s, type, v, VAR_BOOL, VAR_INT, VAR_REAL, VAR_STRING, and VAR_UNKNOWN.

933 : type(var.type), bConst(false)
934 {
935  switch (type) {
937  ASSERT(var.v.i == 0 || var.v.i == 1);
938  // fallthru
939  case TypedValue::VAR_INT:
940  v.i = var.v.i;
941  break;
942 
944  v.r = var.v.r;
945  break;
946 
948  s = var.s;
949  break;
950 
952  /* allow initialization from unspecified type right now */
953  break;
954 
955  default:
956  throw ErrUnknownType(MBDYN_EXCEPT_ARGS);
957  }
958 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type type
Definition: mathtyp.h:86
Int i
Definition: mathtyp.h:89
union TypedValue::@14 v
bool bConst
Definition: mathtyp.h:87
#define ASSERT(expression)
Definition: colamd.c:977
std::string s
Definition: mathtyp.h:92
Real r
Definition: mathtyp.h:90

Member Function Documentation

TypedValue & TypedValue::Cast ( const TypedValue var,
bool  bErr = false 
)

Definition at line 1032 of file mathp.cc.

References bConst, buf, Const(), GetBool(), GetInt(), GetReal(), GetString(), GetTypeName(), MBDYN_EXCEPT_ARGS, mbdyn_get_line_data(), r, s, Set(), type, VAR_BOOL, VAR_INT, VAR_REAL, and VAR_STRING.

Referenced by Var::Cast(), mp_cast(), and MathParser::stmt().

1033 {
1034  if (Const()) {
1035  throw ErrConstraintViolation(MBDYN_EXCEPT_ARGS);
1036  }
1037 
1038  if (type == TypedValue::VAR_STRING) {
1039  char buf[BUFSIZ];
1040 
1041  switch (var.type) {
1042  case TypedValue::VAR_BOOL:
1043  case TypedValue::VAR_INT:
1044  // TODO: use std::ostringstream?
1045  snprintf(buf, sizeof(buf), "%ld", (long)var.GetInt());
1046  Set(std::string(buf));
1047  break;
1048 
1049  case TypedValue::VAR_REAL:
1050  // TODO: use std::ostringstream?
1051  snprintf(buf, sizeof(buf), "%e", (double)var.GetReal());
1052  Set(std::string(buf));
1053  break;
1054 
1056  this->s = var.GetString();
1057  break;
1058 
1059  default:
1060  throw ErrUnknownType(MBDYN_EXCEPT_ARGS);
1061  }
1062 
1063  } else {
1064  switch (type) {
1065  case TypedValue::VAR_BOOL:
1066  switch (var.type) {
1067  case TypedValue::VAR_BOOL:
1068  break;
1069 
1070  case TypedValue::VAR_INT:
1071  case TypedValue::VAR_REAL:
1072  if (bErr) {
1073  Real r = var.GetReal();
1074  if (r != 0. && r != 1.) {
1075  silent_cerr(" Error: implicit cast "
1076  "of " << var
1077  << " from " << GetTypeName(var.type)
1078  << " to " << GetTypeName(type)
1079  << " alters its value"
1080  << std::endl);
1082  }
1083  }
1084 
1085  silent_cerr("Warning: implicit cast "
1086  "from " << GetTypeName(var.type)
1087  << " to " << GetTypeName(type)
1088  << " may alter its value"
1089  << " at line " << mbdyn_get_line_data()
1090  << std::endl);
1091  break;
1092 
1093  default:
1094  throw ErrWrongType(MBDYN_EXCEPT_ARGS, type, var.type);
1095  }
1096  Set(var.GetBool());
1097  break;
1098 
1099  case TypedValue::VAR_INT:
1100  switch (var.type) {
1101  case TypedValue::VAR_BOOL:
1102  case TypedValue::VAR_INT:
1103  break;
1104 
1105  case TypedValue::VAR_REAL:
1106  if (bErr) {
1107  if (var.GetReal() != Real(var.GetInt())) {
1108  silent_cerr(" Error: implicit cast "
1109  "of " << var
1110  << " from " << GetTypeName(var.type)
1111  << " to " << GetTypeName(type)
1112  << " alters its value"
1113  << std::endl);
1115  }
1116  }
1117 
1118  silent_cerr("Warning: implicit cast "
1119  "from " << GetTypeName(var.type)
1120  << " to " << GetTypeName(type)
1121  << " may alter its value"
1122  << " at line " << mbdyn_get_line_data()
1123  << std::endl);
1124  break;
1125 
1126  default:
1127  throw ErrWrongType(MBDYN_EXCEPT_ARGS, type, var.type);
1128  }
1129  Set(var.GetInt());
1130  break;
1131 
1132  case TypedValue::VAR_REAL:
1133  switch (var.type) {
1134  case TypedValue::VAR_BOOL:
1135  case TypedValue::VAR_INT:
1136  case TypedValue::VAR_REAL:
1137  break;
1138 
1139  default:
1140  throw ErrWrongType(MBDYN_EXCEPT_ARGS, type, var.type);
1141  }
1142  Set(var.GetReal());
1143  break;
1144 
1145  default:
1146  throw ErrUnknownType(MBDYN_EXCEPT_ARGS);
1147  }
1148  }
1149 
1150  bConst = var.Const();
1151  return *this;
1152 }
Real GetReal(void) const
Definition: mathp.cc:1228
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
const TypedValue & Set(const bool &b)
Definition: mathp.cc:1285
TypedValue::Type type
Definition: mathtyp.h:86
const char *const GetTypeName(void) const
Definition: mathp.cc:1176
const std::string & GetString(void) const
Definition: mathp.cc:1247
bool bConst
Definition: mathtyp.h:87
HighParser::ErrOut mbdyn_get_line_data(void)
Definition: parser.cc:603
std::string s
Definition: mathtyp.h:92
Real r
Definition: mathtyp.h:90
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333
Int GetInt(void) const
Definition: mathp.cc:1209
bool GetBool(void) const
Definition: mathp.cc:1188
double Real
Definition: mathtyp.h:39
bool Const(void) const
Definition: mathp.cc:1182

Here is the call graph for this function:

bool TypedValue::Const ( void  ) const

Definition at line 1182 of file mathp.cc.

References bConst.

Referenced by Cast(), Var::Const(), Var::MayChange(), operator%=(), operator*=(), operator+=(), operator-=(), operator/=(), operator=(), Set(), SetConst(), SetType(), and Var::Var().

1183 {
1184  return bConst;
1185 }
bool bConst
Definition: mathtyp.h:87
bool TypedValue::GetBool ( void  ) const

Definition at line 1188 of file mathp.cc.

References MBDYN_EXCEPT_ARGS, type, v, VAR_BOOL, VAR_INT, VAR_REAL, and VAR_STRING.

Referenced by Cast(), EE_Divide::Eval(), MathParser::evalfunc(), HighParser::GetBool(), and operator=().

1189 {
1190  switch (type) {
1191  case TypedValue::VAR_BOOL:
1192  return v.i;
1193 
1194  case TypedValue::VAR_INT:
1195  return v.i ? 1 : 0;
1196 
1197  case TypedValue::VAR_REAL:
1198  return v.r ? 1 : 0;
1199 
1201  throw ErrWrongType(MBDYN_EXCEPT_ARGS, VAR_BOOL, type);
1202 
1203  default:
1204  throw ErrUnknownType(MBDYN_EXCEPT_ARGS);
1205  }
1206 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type type
Definition: mathtyp.h:86
union TypedValue::@14 v
Int TypedValue::GetInt ( void  ) const

Definition at line 1209 of file mathp.cc.

References MBDYN_EXCEPT_ARGS, type, v, VAR_BOOL, VAR_INT, VAR_REAL, and VAR_STRING.

Referenced by Cast(), EE_Modulus::Eval(), EE_Divide::Eval(), EE_Power::Eval(), MathParser::evalfunc(), HighParser::GetInt(), operator%(), operator%=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator/(), operator/=(), operator<<(), operator=(), and MathParser::power_int().

1210 {
1211  switch (type) {
1212  case TypedValue::VAR_BOOL:
1213  case TypedValue::VAR_INT:
1214  return v.i;
1215 
1216  case TypedValue::VAR_REAL:
1217  return Int(v.r);
1218 
1220  throw ErrWrongType(MBDYN_EXCEPT_ARGS, VAR_INT, type);
1221 
1222  default:
1223  throw ErrUnknownType(MBDYN_EXCEPT_ARGS);
1224  }
1225 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type type
Definition: mathtyp.h:86
union TypedValue::@14 v
int Int
Definition: mathtyp.h:40
Real TypedValue::GetReal ( void  ) const

Definition at line 1228 of file mathp.cc.

References MBDYN_EXCEPT_ARGS, type, v, VAR_BOOL, VAR_INT, VAR_REAL, and VAR_STRING.

Referenced by Cast(), EE_Divide::Eval(), EE_Power::Eval(), MathParser::evalfunc(), MathParser::Get(), MathParser::GetLastStmt(), HighParser::GetReal(), HighParser::GetTimeout(), operator!(), operator!=(), operator&&(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator/(), operator/=(), operator<(), operator<<(), operator<=(), operator=(), operator==(), operator>(), operator>=(), operator||(), and MathParser::power_int().

1229 {
1230  switch (type) {
1231  case TypedValue::VAR_BOOL:
1232  case TypedValue::VAR_INT:
1233  return Real(v.i);
1234 
1235  case TypedValue::VAR_REAL:
1236  return v.r;
1237 
1239  throw ErrWrongType(MBDYN_EXCEPT_ARGS, VAR_REAL, type);
1240 
1241  default:
1242  throw ErrUnknownType(MBDYN_EXCEPT_ARGS);
1243  }
1244 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type type
Definition: mathtyp.h:86
union TypedValue::@14 v
double Real
Definition: mathtyp.h:39
const std::string & TypedValue::GetString ( void  ) const

Definition at line 1247 of file mathp.cc.

References MBDYN_EXCEPT_ARGS, s, type, VAR_BOOL, VAR_INT, VAR_REAL, and VAR_STRING.

Referenced by Cast(), MathParser::evalfunc(), HighParser::GetString(), mp_cast(), operator!(), operator+(), operator+=(), operator<<(), operator=(), and MathParser::TokenPop().

1248 {
1249  switch (type) {
1250  case TypedValue::VAR_BOOL:
1251  case TypedValue::VAR_INT:
1252  case TypedValue::VAR_REAL:
1253  throw ErrWrongType(MBDYN_EXCEPT_ARGS, VAR_STRING, type);
1254 
1256  return s;
1257 
1258  default:
1259  throw ErrUnknownType(MBDYN_EXCEPT_ARGS);
1260  }
1261 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type type
Definition: mathtyp.h:86
std::string s
Definition: mathtyp.h:92
TypedValue::Type TypedValue::GetType ( void  ) const
const char *const TypedValue::GetTypeName ( void  ) const

Definition at line 1176 of file mathp.cc.

References type.

Referenced by Cast(), NamedValue::GetTypeName(), MathParser::StaticNameSpace::StaticNameSpace(), and MathParser::stmt().

1177 {
1178  return GetTypeName(type);
1179 }
TypedValue::Type type
Definition: mathtyp.h:86
const char *const GetTypeName(void) const
Definition: mathp.cc:1176
const char *const TypedValue::GetTypeName ( TypedValue::Type  t)
static

Definition at line 1161 of file mathp.cc.

References MBDYN_EXCEPT_ARGS, TypeName_t::name, VAR_BOOL, VAR_INT, VAR_REAL, and VAR_STRING.

1162 {
1163  switch (t) {
1164  case TypedValue::VAR_BOOL:
1165  case TypedValue::VAR_INT:
1166  case TypedValue::VAR_REAL:
1168  return TypeNames[t].name;
1169 
1170  default:
1172  }
1173 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
const char * name
Definition: mathp.cc:832
static const TypeName_t TypeNames[]
Definition: mathp.cc:836
bool TypedValue::operator!= ( const TypedValue v) const

Definition at line 1438 of file mathp.cc.

References GetReal().

1439 {
1440  return (GetReal() != v.GetReal());
1441 }
Real GetReal(void) const
Definition: mathp.cc:1228

Here is the call graph for this function:

TypedValue TypedValue::operator% ( const TypedValue v) const

Definition at line 1517 of file mathp.cc.

References GetInt(), GetType(), MBDYN_EXCEPT_ARGS, TypedValue(), VAR_BOOL, and VAR_INT.

1518 {
1519  // bool is implicitly cast to Int
1521  {
1522  throw ErrWrongType(MBDYN_EXCEPT_ARGS, TypedValue::VAR_INT, v.GetType(), " in right argument");
1523  }
1524 
1526  {
1527  throw ErrWrongType(MBDYN_EXCEPT_ARGS, TypedValue::VAR_INT, GetType(), " in left argument");
1528  }
1529 
1530  return TypedValue(GetInt() % v.GetInt());
1531 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
TypedValue(void)
Definition: mathp.cc:874
Int GetInt(void) const
Definition: mathp.cc:1209

Here is the call graph for this function:

const TypedValue & TypedValue::operator%= ( const TypedValue v)

Definition at line 1634 of file mathp.cc.

References Const(), GetInt(), GetType(), MBDYN_EXCEPT_ARGS, Set(), type, VAR_BOOL, and VAR_INT.

1635 {
1636  if (Const()) {
1637  throw ErrConstraintViolation(MBDYN_EXCEPT_ARGS);
1638  }
1639 
1640  // bool is implicitly cast to Int
1642  {
1643  throw ErrWrongType(MBDYN_EXCEPT_ARGS, TypedValue::VAR_INT, v.GetType(), " in right argument");
1644  }
1645 
1647  {
1648  throw ErrWrongType(MBDYN_EXCEPT_ARGS, TypedValue::VAR_INT, GetType(), " in left argument");
1649  }
1650 
1651  Int i = GetInt() % v.GetInt();
1653  return Set(i);
1654 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
const TypedValue & Set(const bool &b)
Definition: mathp.cc:1285
TypedValue::Type type
Definition: mathtyp.h:86
Int i
Definition: mathtyp.h:89
int Int
Definition: mathtyp.h:40
Int GetInt(void) const
Definition: mathp.cc:1209
bool Const(void) const
Definition: mathp.cc:1182

Here is the call graph for this function:

bool TypedValue::operator&& ( const TypedValue v) const

Definition at line 1396 of file mathp.cc.

References GetReal().

1397 {
1398  return (GetReal() && v.GetReal());
1399 }
Real GetReal(void) const
Definition: mathp.cc:1228

Here is the call graph for this function:

TypedValue TypedValue::operator* ( const TypedValue v) const

Definition at line 1491 of file mathp.cc.

References GetInt(), GetReal(), GetType(), TypedValue(), VAR_BOOL, and VAR_INT.

1492 {
1495  {
1496  // bool is implicitly cast to Int
1497  return TypedValue(GetInt()*v.GetInt());
1498  }
1499 
1500  return TypedValue(GetReal()*v.GetReal());
1501 }
Real GetReal(void) const
Definition: mathp.cc:1228
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
TypedValue(void)
Definition: mathp.cc:874
Int GetInt(void) const
Definition: mathp.cc:1209

Here is the call graph for this function:

const TypedValue & TypedValue::operator*= ( const TypedValue v)

Definition at line 1598 of file mathp.cc.

References Const(), GetInt(), GetReal(), GetType(), MBDYN_EXCEPT_ARGS, Set(), type, VAR_BOOL, VAR_INT, and VAR_REAL.

1599 {
1600  if (Const()) {
1601  throw ErrConstraintViolation(MBDYN_EXCEPT_ARGS);
1602  }
1603 
1606  {
1607  // bool is implicitly cast to Int
1608  return Set(GetInt()*v.GetInt());
1609  }
1610  Real d = GetReal()*v.GetReal();
1612  return Set(d);
1613 }
Real GetReal(void) const
Definition: mathp.cc:1228
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
const TypedValue & Set(const bool &b)
Definition: mathp.cc:1285
TypedValue::Type type
Definition: mathtyp.h:86
Int GetInt(void) const
Definition: mathp.cc:1209
double Real
Definition: mathtyp.h:39
bool Const(void) const
Definition: mathp.cc:1182

Here is the call graph for this function:

TypedValue TypedValue::operator+ ( const TypedValue v) const

Definition at line 1444 of file mathp.cc.

References buf, GetInt(), GetReal(), GetString(), GetType(), MBDYN_EXCEPT_ARGS, TypedValue(), VAR_BOOL, VAR_INT, VAR_REAL, and VAR_STRING.

1445 {
1446  if (GetType() == TypedValue::VAR_STRING) {
1447  char buf[BUFSIZ];
1448 
1449  switch (v.GetType()) {
1450  case TypedValue::VAR_BOOL:
1451  case TypedValue::VAR_INT:
1452  snprintf(buf, sizeof(buf), "%ld", (long)v.GetInt());
1453  return TypedValue(GetString() + buf);
1454 
1455  case TypedValue::VAR_REAL:
1456  snprintf(buf, sizeof(buf), "%e", (double)v.GetReal());
1457  return TypedValue(GetString() + buf);
1458 
1460  return TypedValue(GetString() + v.GetString());
1461 
1462  default:
1463  throw ErrWrongType(MBDYN_EXCEPT_ARGS, GetType(), v.GetType());
1464  }
1465  }
1466 
1469  {
1470  // bool is implicitly cast to Int
1471  return TypedValue(GetInt() + v.GetInt());
1472  }
1473 
1474  return TypedValue(GetReal() + v.GetReal());
1475 }
Real GetReal(void) const
Definition: mathp.cc:1228
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
TypedValue(void)
Definition: mathp.cc:874
const std::string & GetString(void) const
Definition: mathp.cc:1247
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333
Int GetInt(void) const
Definition: mathp.cc:1209

Here is the call graph for this function:

const TypedValue & TypedValue::operator+= ( const TypedValue v)

Definition at line 1534 of file mathp.cc.

References buf, Const(), GetInt(), GetReal(), GetString(), GetType(), MBDYN_EXCEPT_ARGS, s, Set(), type, VAR_BOOL, VAR_INT, VAR_REAL, and VAR_STRING.

1535 {
1536  if (Const()) {
1537  throw ErrConstraintViolation(MBDYN_EXCEPT_ARGS);
1538  }
1539 
1540  if (GetType() == TypedValue::VAR_STRING) {
1541  char buf[BUFSIZ];
1542 
1543  switch (v.GetType()) {
1544  case TypedValue::VAR_BOOL:
1545  case TypedValue::VAR_INT:
1546  snprintf(buf, sizeof(buf), "%ld", (long)v.GetInt());
1547  this->s += buf;
1548  break;
1549 
1550  case TypedValue::VAR_REAL:
1551  snprintf(buf, sizeof(buf), "%e", (double)v.GetReal());
1552  this->s += buf;
1553  break;
1554 
1556  this->s += v.GetString();
1557  break;
1558 
1559  default:
1560  throw ErrWrongType(MBDYN_EXCEPT_ARGS, GetType(), v.GetType());
1561  }
1562 
1563  return *this;
1564  }
1565 
1568  {
1569  // bool is implicitly cast to Int
1570  return Set(GetInt() + v.GetInt());
1571  }
1572 
1573  Real d = GetReal() + v.GetReal();
1575 
1576  return Set(d);
1577 }
Real GetReal(void) const
Definition: mathp.cc:1228
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
const TypedValue & Set(const bool &b)
Definition: mathp.cc:1285
TypedValue::Type type
Definition: mathtyp.h:86
const std::string & GetString(void) const
Definition: mathp.cc:1247
std::string s
Definition: mathtyp.h:92
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333
Int GetInt(void) const
Definition: mathp.cc:1209
double Real
Definition: mathtyp.h:39
bool Const(void) const
Definition: mathp.cc:1182

Here is the call graph for this function:

TypedValue TypedValue::operator- ( const TypedValue v) const

Definition at line 1478 of file mathp.cc.

References GetInt(), GetReal(), GetType(), TypedValue(), VAR_BOOL, and VAR_INT.

1479 {
1482  {
1483  // bool is implicitly cast to Int
1484  return TypedValue(GetInt() - v.GetInt());
1485  }
1486 
1487  return TypedValue(GetReal() - v.GetReal());
1488 }
Real GetReal(void) const
Definition: mathp.cc:1228
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
TypedValue(void)
Definition: mathp.cc:874
Int GetInt(void) const
Definition: mathp.cc:1209

Here is the call graph for this function:

const TypedValue & TypedValue::operator-= ( const TypedValue v)

Definition at line 1580 of file mathp.cc.

References Const(), GetInt(), GetReal(), GetType(), MBDYN_EXCEPT_ARGS, Set(), type, VAR_BOOL, VAR_INT, and VAR_REAL.

1581 {
1582  if (Const()) {
1583  throw ErrConstraintViolation(MBDYN_EXCEPT_ARGS);
1584  }
1585 
1588  {
1589  // bool is implicitly cast to Int
1590  return Set(GetInt() - v.GetInt());
1591  }
1592  Real d = GetReal() - v.GetReal();
1594  return Set(d);
1595 }
Real GetReal(void) const
Definition: mathp.cc:1228
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
const TypedValue & Set(const bool &b)
Definition: mathp.cc:1285
TypedValue::Type type
Definition: mathtyp.h:86
Int GetInt(void) const
Definition: mathp.cc:1209
double Real
Definition: mathtyp.h:39
bool Const(void) const
Definition: mathp.cc:1182

Here is the call graph for this function:

TypedValue TypedValue::operator/ ( const TypedValue v) const

Definition at line 1504 of file mathp.cc.

References GetInt(), GetReal(), GetType(), TypedValue(), VAR_BOOL, and VAR_INT.

1505 {
1508  {
1509  // bool is implicitly cast to Int
1510  return TypedValue(GetInt()/v.GetInt());
1511  }
1512 
1513  return TypedValue(GetReal()/v.GetReal());
1514 }
Real GetReal(void) const
Definition: mathp.cc:1228
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
TypedValue(void)
Definition: mathp.cc:874
Int GetInt(void) const
Definition: mathp.cc:1209

Here is the call graph for this function:

const TypedValue & TypedValue::operator/= ( const TypedValue v)

Definition at line 1616 of file mathp.cc.

References Const(), GetInt(), GetReal(), GetType(), MBDYN_EXCEPT_ARGS, Set(), type, VAR_BOOL, VAR_INT, and VAR_REAL.

1617 {
1618  if (Const()) {
1619  throw ErrConstraintViolation(MBDYN_EXCEPT_ARGS);
1620  }
1621 
1624  {
1625  // bool is implicitly cast to Int
1626  return Set(GetInt()/v.GetInt());
1627  }
1628  Real d = GetReal()/v.GetReal();
1630  return Set(d);
1631 }
Real GetReal(void) const
Definition: mathp.cc:1228
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
const TypedValue & Set(const bool &b)
Definition: mathp.cc:1285
TypedValue::Type type
Definition: mathtyp.h:86
Int GetInt(void) const
Definition: mathp.cc:1209
double Real
Definition: mathtyp.h:39
bool Const(void) const
Definition: mathp.cc:1182

Here is the call graph for this function:

bool TypedValue::operator< ( const TypedValue v) const

Definition at line 1432 of file mathp.cc.

References GetReal().

1433 {
1434  return (GetReal() < v.GetReal());
1435 }
Real GetReal(void) const
Definition: mathp.cc:1228

Here is the call graph for this function:

bool TypedValue::operator<= ( const TypedValue v) const

Definition at line 1426 of file mathp.cc.

References GetReal().

1427 {
1428  return (GetReal() <= v.GetReal());
1429 }
Real GetReal(void) const
Definition: mathp.cc:1228

Here is the call graph for this function:

TypedValue & TypedValue::operator= ( const TypedValue var)

Definition at line 961 of file mathp.cc.

References bConst, buf, Const(), GetBool(), GetInt(), GetReal(), GetString(), MBDYN_EXCEPT_ARGS, s, Set(), type, VAR_BOOL, VAR_INT, VAR_REAL, VAR_STRING, and VAR_UNKNOWN.

962 {
963  if (Const()) {
964  throw ErrConstraintViolation(MBDYN_EXCEPT_ARGS);
965  }
966 
967  bConst = false;
968  if (type == TypedValue::VAR_STRING) {
969  char buf[BUFSIZ];
970 
971  switch (var.type) {
973  case TypedValue::VAR_INT:
974  snprintf(buf, sizeof(buf), "%ld", (long)var.GetInt());
975  Set(std::string(buf));
976  break;
977 
979  snprintf(buf, sizeof(buf), "%e", (double)var.GetReal());
980  Set(std::string(buf));
981  break;
982 
984  this->s = var.GetString();
985  break;
986 
987  default:
988  throw ErrUnknownType(MBDYN_EXCEPT_ARGS);
989  }
990 
991  } else {
992  switch (var.type) {
994  type = var.type;
995  Set(var.GetBool());
996  break;
997 
998  case TypedValue::VAR_INT:
999  type = var.type;
1000  Set(var.GetInt());
1001  break;
1002 
1003  case TypedValue::VAR_REAL:
1004  type = var.type;
1005  Set(var.GetReal());
1006  break;
1007 
1009  if (type != TypedValue::VAR_UNKNOWN) {
1010  throw ErrWrongType(MBDYN_EXCEPT_ARGS, type, var.type);
1011  }
1013  s = var.s;
1014  break;
1015 
1017  if (type != TypedValue::VAR_UNKNOWN) {
1018  throw ErrWrongType(MBDYN_EXCEPT_ARGS, type, var.type);
1019  }
1020  break;
1021 
1022  default:
1023  throw ErrUnknownType(MBDYN_EXCEPT_ARGS);
1024  }
1025  }
1026 
1027  // NOTE: TypedValue does not inherit const'ness
1028  return *this;
1029 }
Real GetReal(void) const
Definition: mathp.cc:1228
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
const TypedValue & Set(const bool &b)
Definition: mathp.cc:1285
TypedValue::Type type
Definition: mathtyp.h:86
const std::string & GetString(void) const
Definition: mathp.cc:1247
bool bConst
Definition: mathtyp.h:87
std::string s
Definition: mathtyp.h:92
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333
Int GetInt(void) const
Definition: mathp.cc:1209
bool GetBool(void) const
Definition: mathp.cc:1188
bool Const(void) const
Definition: mathp.cc:1182

Here is the call graph for this function:

bool TypedValue::operator== ( const TypedValue v) const

Definition at line 1420 of file mathp.cc.

References GetReal().

1421 {
1422  return (GetReal() == v.GetReal());
1423 }
Real GetReal(void) const
Definition: mathp.cc:1228

Here is the call graph for this function:

bool TypedValue::operator> ( const TypedValue v) const

Definition at line 1408 of file mathp.cc.

References GetReal().

1409 {
1410  return (GetReal() > v.GetReal());
1411 }
Real GetReal(void) const
Definition: mathp.cc:1228

Here is the call graph for this function:

bool TypedValue::operator>= ( const TypedValue v) const

Definition at line 1414 of file mathp.cc.

References GetReal().

1415 {
1416  return (GetReal() >= v.GetReal());
1417 }
Real GetReal(void) const
Definition: mathp.cc:1228

Here is the call graph for this function:

bool TypedValue::operator|| ( const TypedValue v) const

Definition at line 1402 of file mathp.cc.

References GetReal().

1403 {
1404  return (GetReal() || v.GetReal());
1405 }
Real GetReal(void) const
Definition: mathp.cc:1228

Here is the call graph for this function:

const TypedValue & TypedValue::Set ( const bool b)

Definition at line 1285 of file mathp.cc.

References Const(), GetType(), MBDYN_EXCEPT_ARGS, v, VAR_BOOL, VAR_INT, VAR_REAL, and VAR_STRING.

Referenced by Cast(), MathParser::GetToken(), operator%=(), operator*=(), operator+=(), operator-=(), operator/=(), operator=(), and Var::SetVal().

1286 {
1287  if (Const()) {
1288  throw ErrConstraintViolation(MBDYN_EXCEPT_ARGS);
1289  }
1290 
1291  switch (GetType()) {
1292  case TypedValue::VAR_BOOL:
1293  case TypedValue::VAR_INT:
1294  v.i = b ? 1 : 0;
1295  break;
1296 
1297  case TypedValue::VAR_REAL:
1298  v.r = b ? 1. : 0.;
1299  break;
1300 
1302  throw ErrWrongType(MBDYN_EXCEPT_ARGS, GetType(), VAR_BOOL);
1303 
1304  default:
1305  throw ErrUnknownType(MBDYN_EXCEPT_ARGS);
1306  }
1307 
1308  return *this;
1309 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
union TypedValue::@14 v
bool Const(void) const
Definition: mathp.cc:1182

Here is the call graph for this function:

const TypedValue& TypedValue::Set ( const Int i)
const TypedValue & TypedValue::Set ( const Real r)

Definition at line 1342 of file mathp.cc.

References Const(), GetType(), MBDYN_EXCEPT_ARGS, r, v, VAR_BOOL, VAR_INT, VAR_REAL, and VAR_STRING.

1343 {
1344  if (Const()) {
1345  throw ErrConstraintViolation(MBDYN_EXCEPT_ARGS);
1346  }
1347 
1348  switch (GetType()) {
1349  case TypedValue::VAR_BOOL:
1350  v.i = r ? 1 : 0;
1351  break;
1352 
1353  case TypedValue::VAR_INT:
1354  v.i = Int(r);
1355  break;
1356 
1357  case TypedValue::VAR_REAL:
1358  v.r = r;
1359  break;
1360 
1362  throw ErrWrongType(MBDYN_EXCEPT_ARGS, GetType(), VAR_REAL);
1363 
1364  default:
1365  throw ErrUnknownType(MBDYN_EXCEPT_ARGS);
1366  }
1367 
1368  return *this;
1369 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
union TypedValue::@14 v
int Int
Definition: mathtyp.h:40
Real r
Definition: mathtyp.h:90
bool Const(void) const
Definition: mathp.cc:1182

Here is the call graph for this function:

const TypedValue & TypedValue::Set ( const std::string &  s)

Definition at line 1372 of file mathp.cc.

References Const(), GetType(), MBDYN_EXCEPT_ARGS, s, VAR_BOOL, VAR_INT, VAR_REAL, and VAR_STRING.

1373 {
1374  if (Const()) {
1375  throw ErrConstraintViolation(MBDYN_EXCEPT_ARGS);
1376  }
1377 
1378  switch (GetType()) {
1379  case TypedValue::VAR_BOOL:
1380  case TypedValue::VAR_INT:
1381  case TypedValue::VAR_REAL:
1382  throw ErrWrongType(MBDYN_EXCEPT_ARGS, GetType(), VAR_STRING);
1383 
1385  this->s = s;
1386  break;
1387 
1388  default:
1389  throw ErrUnknownType(MBDYN_EXCEPT_ARGS);
1390  }
1391 
1392  return *this;
1393 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
std::string s
Definition: mathtyp.h:92
bool Const(void) const
Definition: mathp.cc:1182

Here is the call graph for this function:

void TypedValue::SetConst ( bool  isConst = true,
bool  bForce = false 
)

Definition at line 1275 of file mathp.cc.

References bConst, Const(), and MBDYN_EXCEPT_ARGS.

Referenced by EE_Value::EE_Value(), MathParser::stmt(), Table::Table(), and Var::Var().

1276 {
1277  if (Const() && !isConst && !bForce) {
1278  throw ErrConstraintViolation(MBDYN_EXCEPT_ARGS);
1279  }
1280 
1281  bConst = isConst;
1282 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
bool bConst
Definition: mathtyp.h:87
bool Const(void) const
Definition: mathp.cc:1182

Here is the call graph for this function:

void TypedValue::SetType ( TypedValue::Type  t,
bool  isConst = false 
)

Definition at line 1264 of file mathp.cc.

References bConst, Const(), MBDYN_EXCEPT_ARGS, and type.

Referenced by MathParser::GetToken(), and MathParser::power_int().

1265 {
1266  if (Const()) {
1267  throw ErrConstraintViolation(MBDYN_EXCEPT_ARGS);
1268  }
1269 
1270  type = t;
1271  bConst = isConst;
1272 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type type
Definition: mathtyp.h:86
bool bConst
Definition: mathtyp.h:87
bool Const(void) const
Definition: mathp.cc:1182

Here is the call graph for this function:

Member Data Documentation

bool TypedValue::bConst
protected

Definition at line 87 of file mathtyp.h.

Referenced by Cast(), Const(), operator=(), SetConst(), and SetType().

Int TypedValue::i

Definition at line 89 of file mathtyp.h.

Referenced by TypedValue().

Real TypedValue::r

Definition at line 90 of file mathtyp.h.

Referenced by Cast(), Set(), and TypedValue().

std::string TypedValue::s
protected

Definition at line 92 of file mathtyp.h.

Referenced by Cast(), GetString(), operator+=(), operator=(), Set(), and TypedValue().

union { ... } TypedValue::v

Referenced by GetBool(), GetInt(), GetReal(), Set(), and TypedValue().


The documentation for this class was generated from the following files: