00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <xercesc/sax2/DefaultHandler.hpp>
00020 #include <xercesc/framework/XMLFormatter.hpp>
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <wchar.h>
00024 #include <vector>
00025
00026 extern "C" {
00027 #include "class.h"
00028 #include "load.h"
00029 #include "globals.h"
00030 #include "module.h"
00031 #include "convert.h"
00032 #include "random.h"
00033 #include "output.h"
00034 #include "unit.h"
00035 }
00036 #include "gridlabd.h"
00037
00038 XERCES_CPP_NAMESPACE_USE
00039
00040 using std::vector;
00041
00042 typedef enum {
00043 EMPTY = 0,
00044 LOAD,
00045 MODULE_STATE,
00046 MODULE_PROP,
00047 OBJECT_STATE,
00048 OBJECT_PROP,
00049 GLOBAL_STATE,
00050 GLOBAL_PROP,
00051 CLOCK_STATE,
00052 CLOCK_PROP
00053 } gld_state;
00054
00055 class gldStack{
00056 public:
00057 gldStack(){next = NULL; clear();}
00058 gldStack(gldStack *ptr){next = ptr; clear();}
00059 ~gldStack(){if(next != NULL) delete next;}
00060
00061 void clear(){object_type[0] = 0; object_id[0] = 0; object_name[0] = 0; keyword[0] = 0;}
00062 char object_type[64];
00063 char object_id[64];
00064 char object_name[64];
00065 char keyword[64];
00066 gldStack *next;
00067 };
00068
00069 class gld_loadHndl : public DefaultHandler, public XMLFormatTarget {
00070 public:
00071 gld_loadHndl();
00072 gld_loadHndl(const char* const, const XMLFormatter::UnRepFlags, const bool);
00073 virtual ~gld_loadHndl();
00074
00075 bool did_load(){return load_state;}
00076
00077 void writeChars(const XMLByte* const toWrite);
00078 virtual void writeChars(const XMLByte* const toWrite, const unsigned int count, XMLFormatter* const formatter);
00079
00080 virtual void setDocumentLocator(const Locator *const locator);
00081 virtual void endDocument();
00082 virtual void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname);
00083 virtual void characters(const XMLCh* const chars, const unsigned int length);
00084 virtual void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
00085 virtual void processingInstruction(const XMLCh* const target, const XMLCh* const data);
00086 virtual void startDocument();
00087 virtual void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes);
00088
00089 virtual void warning(const SAXParseException& exc);
00090 virtual void error(const SAXParseException& exc);
00091 virtual void fatalError(const SAXParseException& exc);
00092
00093 virtual void notationDecl(const XMLCh* const name, const XMLCh* const publicId, const XMLCh* const systemId);
00094
00095
00096 char *build_object_vect(int start, int end);
00097 void parse_property(char *buffer);
00098 private :
00099 XMLFormatter fFormatter;
00100 bool fExpandNS ;
00101
00102 gld_state stack_state;
00103 Locator const *locator;
00104 char errmsg[1024];
00105 MODULE *module;
00106 CLASS *oclass;
00107 OBJECT *obj;
00108 PROPERTY *prop;
00109 char propname[256];
00110
00111 char *read_module_prop(char *buffer, size_t len);
00112 char *read_global_prop(char *buffer, size_t len);
00113 char *read_object_prop(char *buffer, size_t len);
00114 char *read_clock_prop(char *buffer, size_t len);
00115
00116 char *start_element_empty(char *buffer, size_t len, const Attributes& attributes);
00117 char *start_element_load(char *buffer, size_t len, const Attributes& attributes);
00118 char *start_element_module(char *buffer, size_t len, const Attributes& attributes);
00119 char *start_element_module_prop(char *buffer, size_t len, const Attributes& attributes);
00120 char *start_element_module_build_object(const Attributes &attributes);
00121 char *start_element_object(char *buffer, size_t len, const Attributes& attributes);
00122 char *start_element_object_prop(char *buffer, size_t len, const Attributes& attributes);
00123 char *start_element_global(char *buffer, size_t len, const Attributes& attributes);
00124 char *start_element_global_prop(char *buffer, size_t len, const Attributes& attributes);
00125 char *start_element_clock(char *buffer, size_t len, const Attributes& attributes);
00126 char *start_element_clock_prop(char *buffer, size_t len, const Attributes& attributes);
00127
00128 char *end_element_empty(char *buffer, size_t len);
00129 char *end_element_load(char *buffer, size_t len);
00130 char *end_element_module(char *buffer, size_t len);
00131 char *end_element_module_prop(char *buffer, size_t len);
00132 char *end_element_object(char *buffer, size_t len);
00133 char *end_element_object_prop(char *buffer, size_t len);
00134 char *end_element_global(char *buffer, size_t len);
00135 char *end_element_global_prop(char *buffer, size_t len);
00136 char *end_element_clock(char *buffer, size_t len);
00137 char *end_element_clock_prop(char *buffer, size_t len);
00138
00139 int depth;
00140
00141 char module_name[64];
00142
00143
00144
00145
00146 int first, last;
00147 bool load_ready;
00148 bool load_state;
00149 int object_count, class_count;
00150
00151 vector<OBJECT *> obj_vect;
00152 gldStack *stack_ptr;
00153 };