00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _CONFIGURATION_H_
00036 #define _CONFIGURATION_H_
00037
00038 #include "source_type.h"
00039 #include "coordinates.h"
00040 #include "avl.h"
00041 #include "expat.h"
00042
00043 #define MAX_XML_PATH 1024
00044
00045 class Configuration {
00046
00047 char _xml_path[MAX_XML_PATH];
00048 Sensor_node *_cur_node;
00049 Sensor_device *_cur_sensor;
00050 int _num_sensors;
00051
00052 static inline void _start_element(void *user_data,
00053 const char *name,
00054 const char **attr) {
00055 Configuration *c = reinterpret_cast<Configuration*>(user_data);
00056 if (c != NULL)
00057 c->on_start_element(name, attr);
00058 };
00059 static inline void _end_element(void *user_data,
00060 const char *name) {
00061 Configuration *c = reinterpret_cast<Configuration*>(user_data);
00062 if (c != NULL)
00063 c->on_end_element(name);
00064 };
00065 static inline void _character_data(void *user_data,
00066 const char *name, int len) {
00067 Configuration *c = reinterpret_cast<Configuration*>(user_data);
00068 if (c != NULL)
00069 c->on_character_data(name, len);
00070 };
00071
00072
00073 int modified;
00074
00075 char name[MAX_NAME];
00076 Coordinates origin;
00077
00078 unsigned int num_types;
00079 Source_type *types;
00080
00081 AVL_tree<unsigned long> nodes;
00082 Source_type_tree *sensors;
00083 Source_type_tree *sources;
00084 AVL_tree<unsigned long> obstructions;
00085 Source_type_tree *materials;
00086
00087 public:
00088 Configuration();
00089 Configuration(char *);
00090 ~Configuration();
00091 void clear();
00092
00093 Coordinates get_origin() { return origin; };
00094 char *get_name() { return name; };
00095 AVL_tree<unsigned long> *get_nodes() { return &nodes; };
00096 Source_type_tree *get_sources() { return sources; };
00097 int modded() { return modified; };
00098
00099 void set_origin(Coordinates c) { origin = c; };
00100 void set_name(const char *n, int len) {
00101 int size = len > MAX_NAME ? MAX_NAME : len;
00102 strncpy(name, n, size);
00103 };
00104
00105 void on_start_element(const char*, const char**);
00106 void on_end_element(const char*);
00107 void on_character_data(const char*, int);
00108
00109 void add_Source_type(char *name);
00110 int Source_type_index(char *name);
00111 char *index_Source_type(int idx);
00112 AVL_tree<unsigned long> *Source_type_tree_index(Source_type_tree *t,
00113 char *type);
00114
00115 int open(char *);
00116 int save(char *);
00117
00118 char *cfg_to_xml();
00119 int xml_to_cfg(char *string);
00120 int read_file(FILE *file);
00121 int write_file(FILE *file);
00122 };
00123
00124
00125 #endif // _CONFIGURATION_H_