- Give code a round of indentation. Thank astyle, not me.

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@837 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-08-09 14:38:45 +00:00
parent aaf8e068d3
commit d3c7b46853
108 changed files with 3196 additions and 3180 deletions

View file

@ -31,12 +31,10 @@
using namespace sgpem;
XMLSerializer::~XMLSerializer()
{
}
{}
XMLSerializer::XMLSerializer()
{
}
{}
@ -45,13 +43,14 @@ void XMLSerializer::save_snapshot(const Glib::ustring& filename, const History&
/* COMPAT: Do not genrate nodes for formatting spaces */
LIBXML_TEST_VERSION
xmlKeepBlanksDefault(0);
xmlDocPtr doc;
doc = xmlNewDoc((const xmlChar *)"1.0");
if(doc!=NULL){
if (doc != NULL)
{
fill_doc(doc, hist);
int nwritten = xmlSaveFormatFile (filename.c_str(), doc, 1);
if(nwritten<0)
if (nwritten < 0)
{
throw SerializerError("Error writing xml doc to output stream.");
}
@ -60,48 +59,49 @@ void XMLSerializer::save_snapshot(const Glib::ustring& filename, const History&
{
throw SerializerError("Internal Error creating xml doc.");
}
/* Clean up everything else before quitting. */
xmlCleanupParser();
}
void XMLSerializer::restore_snapshot(const Glib::ustring& filename, History& hist) throw(SerializerError)
{
// TODO - all to do!!
// DEBUG - remove me when finished
// TODO - all to do!!
// DEBUG - remove me when finished
#ifdef LIBXML_SAX1_ENABLED
xmlDocPtr doc;
LIBXML_TEST_VERSION
xmlKeepBlanksDefault(0);
xmlDocPtr doc;
/*
* build an XML tree from a the file;
*/
doc = xmlParseFile(filename.c_str());
if (doc == NULL) {
xmlCleanupParser();
throw SerializerError("Parsing Error: doc is invalid.");
}
LIBXML_TEST_VERSION
xmlKeepBlanksDefault(0);
clear_history(hist);
XMLSerializerFactory fact(hist);
// read all elements and fill hist
read_doc(doc, fact);
// frees all xml related data
xmlFreeDoc(doc);
/* Clean up everything else before quitting. */
/*
* build an XML tree from a the file;
*/
doc = xmlParseFile(filename.c_str());
if (doc == NULL)
{
xmlCleanupParser();
throw SerializerError("Parsing Error: doc is invalid.");
}
clear_history(hist);
XMLSerializerFactory fact(hist);
// read all elements and fill hist
read_doc(doc, fact);
// frees all xml related data
xmlFreeDoc(doc);
/* Clean up everything else before quitting. */
xmlCleanupParser();
#else
/*
* the library has been compiled without some of the old interfaces
*/
#error Compilation of LIBXML with SAX1 support must be enabled
/*
* the library has been compiled without some of the old interfaces
*/
#error Compilation of LIBXML with SAX1 support must be enabled
#endif /* LIBXML_SAX1_ENABLED */
}
@ -112,57 +112,57 @@ void XMLSerializer::restore_snapshot(const Glib::ustring& filename, History& his
const Glib::ustring XMLSerializer::get_filename_extension()
{
return Glib::ustring("xsgp");
return Glib::ustring("xsgp");
}
const Glib::ustring XMLSerializer::get_filename_description()
{
return Glib::ustring("SGPEMv2 XML savefile");
return Glib::ustring("SGPEMv2 XML savefile");
}
void XMLSerializer::fill_doc(xmlDocPtr doc, const History& hist)
{
xmlNodePtr root_node = NULL;/* node pointers */
/*
* Creates a new document, a node and set it as a root node
*/
root_node = xmlNewNode(NULL, (const xmlChar *) "sgpem");
xmlDocSetRootElement(doc, root_node);
xmlNodePtr root_node = NULL;/* node pointers */
/*
* Creates a new document, a node and set it as a root node
*/
root_node = xmlNewNode(NULL, (const xmlChar *) "sgpem");
xmlDocSetRootElement(doc, root_node);
/*
* Creates a DTD declaration. Isn't mandatory.
*/
xmlDtdPtr dtd = xmlCreateIntSubset(doc, (const xmlChar *) "sgpem", NULL, (const xmlChar *) "sgpem.dtd");
/*
* Creates a DTD declaration. Isn't mandatory.
*/
xmlDtdPtr dtd = xmlCreateIntSubset(doc, (const xmlChar *) "sgpem", NULL, (const xmlChar *) "sgpem.dtd");
XMLVisitor xvisit(root_node);
xvisit.from_history(hist);
/*
//
// xmlNewChild() creates a new node, which is "attached" as child node
// of root_node node.
//
xmlNodePtr resources_node = xmlNewChild(root_node, NULL, (const xmlChar *) "resources", NULL);
//
// The same as above, but the new child node doesn't have a content
//
xmlNodePtr schedulables_node = xmlNewChild(root_node, NULL, (const xmlChar *) "schedulables", NULL);
XMLVisitor xvisit(root_node);
xvisit.from_history(hist);
/*
//
// xmlNewChild() creates a new node, which is "attached" as child node
// of root_node node.
//
xmlNodePtr resources_node = xmlNewChild(root_node, NULL, (const xmlChar *) "resources", NULL);
//
// The same as above, but the new child node doesn't have a content
//
xmlNodePtr schedulables_node = xmlNewChild(root_node, NULL, (const xmlChar *) "schedulables", NULL);
fill_resources(resources_node, hist);
fill_schedulables(schedulables_node, hist);
*/
fill_resources(resources_node, hist);
fill_schedulables(schedulables_node, hist);
*/
}
/*
void XMLSerializer::fill_resources(xmlNodePtr resources_node, const History& hist)
{
const Environment& env = hist.get_last_environment();
const Environment::Resources& rvect = env.get_resources();
typedef Environment::Resources::const_iterator res_iterator;
res_iterator iter = rvect.begin();
res_iterator end = rvect.end();
while(iter!=end)
@ -177,13 +177,13 @@ void XMLSerializer::fill_resources(xmlNodePtr resources_node, const History& his
void XMLSerializer::fill_schedulables(xmlNodePtr schedulables_node, const History& hist)
{
const Environment& env = hist.get_last_environment();
const Environment::Processes& pvect = env.get_processes();
typedef std::vector<Process*>::const_iterator proc_iterator;
proc_iterator iter = pvect.begin();
proc_iterator end = pvect.end();
while(iter!=end)
@ -198,71 +198,74 @@ void XMLSerializer::fill_schedulables(xmlNodePtr schedulables_node, const Histor
void XMLSerializer::clear_history(History& hist)
{
const Environment& env = hist.get_last_environment();
const Environment& env = hist.get_last_environment();
const Environment::Processes& pvect = env.get_processes();
typedef std::vector<Process*>::const_iterator proc_iterator;
proc_iterator iter = pvect.begin();
while(iter!=pvect.end())
{
hist.remove(*(*iter));
iter = pvect.begin();
}
const Environment::Processes& pvect = env.get_processes();
typedef std::vector<Process*>::const_iterator proc_iterator;
const Environment::Resources& rvect = env.get_resources();
typedef Environment::Resources::const_iterator res_iterator;
res_iterator riter = rvect.begin();
while(riter!=rvect.end())
{
hist.remove((*riter).first);
riter = rvect.begin();
}
proc_iterator iter = pvect.begin();
while (iter != pvect.end())
{
hist.remove(*(*iter));
iter = pvect.begin();
}
const Environment::Resources& rvect = env.get_resources();
typedef Environment::Resources::const_iterator res_iterator;
res_iterator riter = rvect.begin();
while (riter != rvect.end())
{
hist.remove((*riter).first);
riter = rvect.begin();
}
}
void XMLSerializer::read_doc(xmlDocPtr doc, XMLSerializerFactory& fact) throw(SerializerError)
{
/*
* Check the document is of the right kind
*/
xmlNodePtr root;
root = xmlDocGetRootElement(doc);
if (root == NULL) {
xmlFreeDoc(doc);
xmlCleanupParser();
throw SerializerError("Reading Error: xml doc is empty.");
}
/*
* Check the document is of the right kind
*/
xmlNodePtr root;
root = xmlDocGetRootElement(doc);
if (root == NULL)
{
xmlFreeDoc(doc);
xmlCleanupParser();
throw SerializerError("Reading Error: xml doc is empty.");
}
xmlNodePtr cur;
cur = root->children;
while(cur!=NULL)
xmlNodePtr cur;
cur = root->children;
while (cur != NULL)
{
Glib::ustring name((const char *)cur->name);
if (name == "resources")
{
Glib::ustring name((const char *)cur->name);
if(name=="resources")
{
read_resources(cur, fact);
}
if(name=="schedulables")
{
read_schedulables(cur, fact);
}
cur = cur->next;
read_resources(cur, fact);
}
if (name == "schedulables")
{
read_schedulables(cur, fact);
}
cur = cur->next;
}
}
XMLSerializerFactory::Parameters* read_properties(xmlAttrPtr prop)
{
if(prop==NULL)
if (prop == NULL)
return NULL;
XMLSerializerFactory::Parameters* par=new XMLSerializerFactory::Parameters();
while (prop != NULL) {
if(prop->children && xmlNodeIsText(prop->children)){
XMLSerializerFactory::Parameters* par = new XMLSerializerFactory::Parameters();
while (prop != NULL)
{
if (prop->children && xmlNodeIsText(prop->children))
{
xmlChar *key = xmlNodeGetContent (prop->children);
// xmlChar *key = xmlNodeListGetString(doc, prop->children, 1);
if(key!=NULL)
if (key != NULL)
{
std::pair<Glib::ustring, Glib::ustring> key_value(Glib::ustring((const char *)prop->name), Glib::ustring((const char *)key));
par->insert(key_value);
@ -276,129 +279,129 @@ XMLSerializerFactory::Parameters* read_properties(xmlAttrPtr prop)
void XMLSerializer::read_resources(xmlNodePtr resources_node, XMLSerializerFactory& fact)
{
xmlNodePtr cur;
cur = resources_node->children;
while(cur!=NULL)
xmlNodePtr cur;
cur = resources_node->children;
while (cur != NULL)
{
Glib::ustring node_name((const char *)cur->name);
if (node_name == "resource")
{
Glib::ustring node_name((const char *)cur->name);
if(node_name=="resource")
xmlAttrPtr prop = cur->properties;
XMLSerializerFactory::Parameters* par = read_properties(prop);
if (par != NULL)
{
xmlAttrPtr prop = cur->properties;
XMLSerializerFactory::Parameters* par=read_properties(prop);
if(par!=NULL)
{
fact.factory_method(Glib::ustring("Resource"), *par);
}
// fact.create_resource(*par);
fact.factory_method(Glib::ustring("Resource"), *par);
}
cur = cur->next;
// fact.create_resource(*par);
}
cur = cur->next;
}
}
void XMLSerializer::read_schedulables(xmlNodePtr schedulables_node, XMLSerializerFactory& fact)
{
if(schedulables_node==NULL)
return;
xmlNodePtr cur;
cur = schedulables_node->children;
while(cur!=NULL)
{
Glib::ustring node_name((const char *)cur->name);
if(node_name=="process")
{
xmlAttrPtr prop = cur->properties;
XMLSerializerFactory::Parameters* par=read_properties(prop);
if(par!=NULL)
{
fact.factory_method(Glib::ustring("Process"), *par);
}
// pass the "threads node"
read_threads(cur->children, fact);
}
if (schedulables_node == NULL)
return;
cur = cur->next;
xmlNodePtr cur;
cur = schedulables_node->children;
while (cur != NULL)
{
Glib::ustring node_name((const char *)cur->name);
if (node_name == "process")
{
xmlAttrPtr prop = cur->properties;
XMLSerializerFactory::Parameters* par = read_properties(prop);
if (par != NULL)
{
fact.factory_method(Glib::ustring("Process"), *par);
}
// pass the "threads node"
read_threads(cur->children, fact);
}
cur = cur->next;
}
}
void XMLSerializer::read_threads(xmlNodePtr threads_node, XMLSerializerFactory& fact)
{
if(threads_node==NULL)
return;
xmlNodePtr cur;
cur = threads_node->children;
while(cur!=NULL)
{
Glib::ustring node_name((const char *)cur->name);
if(node_name=="thread")
{
xmlAttrPtr prop = cur->properties;
XMLSerializerFactory::Parameters* par=read_properties(prop);
if(par!=NULL)
{
fact.factory_method(Glib::ustring("Thread"), *par);
}
// pass the "requests node"
read_requests(cur->children, fact);
}
if (threads_node == NULL)
return;
cur = cur->next;
xmlNodePtr cur;
cur = threads_node->children;
while (cur != NULL)
{
Glib::ustring node_name((const char *)cur->name);
if (node_name == "thread")
{
xmlAttrPtr prop = cur->properties;
XMLSerializerFactory::Parameters* par = read_properties(prop);
if (par != NULL)
{
fact.factory_method(Glib::ustring("Thread"), *par);
}
// pass the "requests node"
read_requests(cur->children, fact);
}
cur = cur->next;
}
}
void XMLSerializer::read_requests(xmlNodePtr requests_node, XMLSerializerFactory& fact)
{
if(requests_node==NULL)
{
return;
}
xmlNodePtr cur;
cur = requests_node->children;
while(cur!=NULL)
{
Glib::ustring node_name((const char *)cur->name);
if(node_name=="request")
{
xmlAttrPtr prop = cur->properties;
XMLSerializerFactory::Parameters* par=read_properties(prop);
if(par!=NULL)
{
fact.factory_method(Glib::ustring("Request"), *par);
}
// pass the "subrequest nodes"
read_subrequests(cur->children, fact);
}
if (requests_node == NULL)
{
return;
}
cur = cur->next;
xmlNodePtr cur;
cur = requests_node->children;
while (cur != NULL)
{
Glib::ustring node_name((const char *)cur->name);
if (node_name == "request")
{
xmlAttrPtr prop = cur->properties;
XMLSerializerFactory::Parameters* par = read_properties(prop);
if (par != NULL)
{
fact.factory_method(Glib::ustring("Request"), *par);
}
// pass the "subrequest nodes"
read_subrequests(cur->children, fact);
}
cur = cur->next;
}
}
void XMLSerializer::read_subrequests(xmlNodePtr subrequest_node, XMLSerializerFactory& fact)
{
if(subrequest_node==NULL)
{
return;
}
xmlNodePtr cur;
cur = subrequest_node;
while(cur!=NULL)
{
Glib::ustring node_name((const char *)cur->name);
if(node_name=="subrequest")
{
xmlAttrPtr prop = cur->properties;
XMLSerializerFactory::Parameters* par=read_properties(prop);
if(par!=NULL)
{
fact.factory_method(Glib::ustring("SubRequest"), *par);
}
}
if (subrequest_node == NULL)
{
return;
}
cur = cur->next;
xmlNodePtr cur;
cur = subrequest_node;
while (cur != NULL)
{
Glib::ustring node_name((const char *)cur->name);
if (node_name == "subrequest")
{
xmlAttrPtr prop = cur->properties;
XMLSerializerFactory::Parameters* par = read_properties(prop);
if (par != NULL)
{
fact.factory_method(Glib::ustring("SubRequest"), *par);
}
}
cur = cur->next;
}
}
/* comment */