vegastrike
0.5.1.r1
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
xml_support.h
Go to the documentation of this file.
1
#ifndef _XML_SUPPORT_H_
2
#define _XML_SUPPORT_H_
3
4
#include "config.h"
5
#include <stdio.h>
6
#include <string>
7
#ifndef WIN32
8
#include <sstream>
9
#endif
10
#include "
hashtable.h
"
11
#include <vector>
12
#include <expat.h>
13
#include <iostream>
//needed for cout calls in config_xml.cpp (and other places too i'm sure)
14
#include "gfx/vec.h"
15
16
#if defined (_MSC_VER) && defined (_WIN32) && (_MSC_VER >= 1400)
17
//Disable useless "sprintf depricated" errors in Visual Studio 2005 Express.
18
#pragma warning(disable : 4996)
19
#endif
20
21
#define ARRAY_LENGTH( a ) ( sizeof (a)/sizeof (a[0]) )
22
23
std::string
strtoupper
(
const
std::string &foo );
24
std::string
strtolower
(
const
std::string &foo );
25
26
namespace
XMLSupport
27
{
28
struct
Attribute
29
{
30
std::string
name
;
31
std::string
value
;
32
Attribute
( std::string
name
, std::string
value
) : name( name )
33
, value( value )
34
{}
35
};
36
37
class
AttributeList
:
public
std::vector< Attribute >
38
{
39
public
:
AttributeList
(
const
XML_Char **atts );
40
};
41
float
parse_floatf
(
const
std::string &str );
42
double
parse_float
(
const
std::string &str );
43
void
parse_floatfv
(
const
std::string &str,
int
max, ... );
44
void
parse_floatv
(
const
std::string &str,
int
max, ... );
45
std::string
replace_space
(
const
std::string &str );
46
int
parse_int
(
const
std::string &str );
47
bool
parse_bool
(
const
std::string &str );
48
bool
parse_option_ispresent
(
const
std::string &str,
49
const
std::string &opt,
50
const
std::string &sep =
",\r\n"
,
51
const
std::string &vsep =
"="
);
52
std::string
parse_option_value
(
const
std::string &str,
53
const
std::string &opt,
54
const
std::string &defvalue,
55
const
std::string &sep =
",\r\n"
,
56
const
std::string &vsep =
"="
);
57
std::string
escaped_string
(
const
std::string &str );
58
59
class
EnumMap
60
{
61
//static inline double parse_float (const string &str) {return ::parse_float (str)};
62
Hashtable< std::string, const int, 1001 >
forward;
63
Hashtable< std::string, const std::string, 1001 >
reverse;
64
public
:
65
66
struct
Pair
67
{
68
std::string
name
;
69
int
val
;
70
Pair
(
const
std::string c,
int
v )
71
{
72
name
= c;
73
val
= v;
74
}
75
};
76
77
EnumMap
(
const
Pair *data,
unsigned
int
num );
78
79
int
lookup
(
const
std::string &str )
const
;
80
const
std::string&
lookup
(
int
val )
const
;
81
};
82
83
/*
84
* string tostring(int num);
85
* string tostring(float num);
86
*/
87
//#ifdef WIN32
88
inline
std::string
tostring5
(
unsigned
short
num )
89
{
90
char
tmp[256];
91
sprintf( tmp,
"%.5d"
, num );
92
return
std::string( tmp );
93
}
94
inline
std::string
tostring
(
int
num )
95
{
96
char
tmp[256];
97
sprintf( tmp,
"%d"
, num );
98
return
std::string( tmp );
99
}
100
inline
std::string
tostring
(
unsigned
int
num )
101
{
102
char
tmp[256];
103
sprintf( tmp,
"%u"
, num );
104
return
std::string( tmp );
105
}
106
inline
std::string
tostring
(
long
num )
107
{
108
char
tmp[256];
109
sprintf( tmp,
"%ld"
, num );
110
return
std::string( tmp );
111
}
112
inline
std::string
tostring
(
float
num )
113
{
114
char
tmp[256];
115
sprintf( tmp,
"%g"
, num );
116
return
std::string( tmp );
117
}
118
inline
std::string
floattostringh
(
float
f
)
119
{
120
char
c[128];
121
sprintf( c,
"%2.2f"
, f );
122
return
std::string( c );
123
}
124
inline
std::string
VectorToString
(
const
Vector &v )
125
{
126
std::string ret(
floattostringh
( v.i ) );
127
if
(v.i != v.j || v.j != v.k)
128
ret += std::string(
","
)+
floattostringh
( v.j )+std::string(
","
)+
floattostringh
( v.k );
129
return
ret;
130
}
131
/*#else
132
* inline template<class T> string tostring(T num) {
133
* return string(((ostrstream*)&(ostrstream() << num << '\0'))->str());
134
*
135
* }
136
#endif*/
137
}
138
#endif
139
src
xml_support.h
Generated on Fri Feb 14 2014 09:03:12 for vegastrike by
1.8.4