-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalue.h
84 lines (71 loc) · 2.33 KB
/
value.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
////////////////////////////////////////////////////////////////////////////////
// DScript Scripting Language
// Copyright (C) 2003 Bryan "daerid" Ross
//
// Permission to copy, use, modify, sell and distribute this software is
// granted provided this copyright notice appears in all copies. This
// software is provided "as is" without express or implied warranty, and
// with no claim as to its suitability for any purpose.
////////////////////////////////////////////////////////////////////////////////
#ifndef __DSCRIPT_VALUE_H__
#define __DSCRIPT_VALUE_H__
////////////////////////////////////////////////////////////////////////////////
// Standard Library Includes
#include <string>
#include <map>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// DScript Includes
#include "instruction.h"
////////////////////////////////////////////////////////////////////////////////
namespace dscript
{
/// This is the actual value data type that DScript works with.
struct value
{
enum ty
{
type_str,
type_int,
type_flt
};
ty type;
value();
value(int i);
value(double d);
value(const std::string& s);
value(string_table::entry s);
value(const value& other);
value& operator = (const value& other);
value& operator = (const std::string& s);
value& operator = (string_table::entry s);
value& operator = (int i);
value& operator = (double d);
std::string to_str() const;
int to_int() const;
double to_flt() const;
void set_type(ty new_type);
void clear() { strval = ""; intval = 0; fltval = 0.0; type = type_str; }
std::string strval;
int intval;
double fltval;
};
typedef std::map<string_table::entry,value,cmp_ste> dictionary_t;
}
inline std::ostream& operator << (std::ostream& out, const dscript::value& v)
{
switch(v.type)
{
case dscript::value::type_str:
out << v.strval;
break;
case dscript::value::type_int:
out << v.intval;
break;
case dscript::value::type_flt:
out << v.fltval;
break;
}
return out;
}
#endif//__DSCRIPT_VALUE_H__