1 | // ============================================================ // |
---|
2 | // // |
---|
3 | // File : aw_scalar.cxx // |
---|
4 | // Purpose : Scalar variables (similar to perl scalars) // |
---|
5 | // // |
---|
6 | // Coded by Ralf Westram (coder@reallysoft.de) in June 2011 // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // ============================================================ // |
---|
11 | |
---|
12 | #include "aw_scalar.hxx" |
---|
13 | #include "aw_awar.hxx" |
---|
14 | #include <arb_msg.h> |
---|
15 | |
---|
16 | const char * const AW_scalar::type_name[SCALAR_TYPES] = { "int", "float", "string", "pointer" }; |
---|
17 | const AW_VARIABLE_TYPE AW_scalar::vtype[SCALAR_TYPES] = { AW_INT, AW_FLOAT, AW_STRING, AW_POINTER }; |
---|
18 | |
---|
19 | AW_scalar::AW_scalar(AW_awar *awar) { |
---|
20 | switch (awar->get_type()) { |
---|
21 | case AW_INT: type = INT; value.i = awar->read_int(); break; |
---|
22 | case AW_FLOAT: type = FLOAT; value.f = awar->read_float(); break; |
---|
23 | case AW_STRING: type = STR; value.s = awar->read_string(); break; |
---|
24 | case AW_POINTER: type = PNTR; value.p = awar->read_pointer(); break; |
---|
25 | default : GBK_terminatef("AWAR type %i unhandled", awar->get_type()); break; |
---|
26 | } |
---|
27 | } |
---|
28 | |
---|
29 | GB_ERROR AW_scalar::write_to(class AW_awar *awar) const { |
---|
30 | GB_ERROR error = NULp; |
---|
31 | switch (awar->get_type()) { |
---|
32 | case AW_INT: error = awar->write_int(get_int()); break; |
---|
33 | case AW_FLOAT: error = awar->write_float(get_float()); break; |
---|
34 | case AW_STRING: error = awar->write_string(get_string()); break; |
---|
35 | case AW_POINTER: error = awar->write_pointer(get_pointer()); break; |
---|
36 | default : GBK_terminatef("AWAR type %i unhandled", awar->get_type()); break; |
---|
37 | } |
---|
38 | return error; |
---|
39 | } |
---|
40 | |
---|