-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashgets.h
73 lines (59 loc) · 1.59 KB
/
hashgets.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
/**
* @file hashgets.h
* @brief Utilities for reading values of different types from hashes
*
*/
#ifndef __HASHGETS_H
#define __HASHGETS_H
#include <angort/hash.h>
using namespace angort;
inline float hgetfloatdef(Hash *h,const char *s,float def=0){
Value *v = h->getSym(s);
if(v)
return v->toFloat();
else
return def;
}
inline int hgetintdef(Hash *h,const char *s,int def=0){
Value *v = h->getSym(s);
if(v)
return v->toInt();
else
return def;
}
inline const char *hgetstrdef(Hash *h,const char *s,const char *def=NULL){
Value *v = h->getSym(s);
if(v)
return v->toString().get();
else
return def;
}
inline float hgetfloat(Hash *h,const char *s){
Value *v = h->getSym(s);
if(!v)throw RUNT(EX_NOTFOUND,"").set("required key '%s' not found in hash",s);
return v->toFloat();
}
inline int hgetint(Hash *h,const char *s){
Value *v = h->getSym(s);
if(!v)throw RUNT(EX_NOTFOUND,"").set("required key '%s' not found in hash",s);
return v->toInt();
}
inline const char *hgetstr(Hash *h,const char *s){
Value *v = h->getSym(s);
if(!v)throw RUNT(EX_NOTFOUND,"").set("required key '%s' not found in hash",s);
return v->toString().get();
}
inline Value *hgetsym(Hash *h,const char *s){
Value *v = h->getSym(s);
if(!v)throw RUNT(EX_NOTFOUND,"").set("required key '%s' not found in hash",s);
return v;
}
inline Value *hgetsymnocheck(Hash *h,const char *s){
Value *v = h->getSym(s);
if(!v){
static Value vnone;
v = &vnone;
}
return v;
}
#endif /* __HASHGETS_H */