コード例 #1
0
ファイル: main.cpp プロジェクト: aeihu/hacks
bool dumpXML(string& fname)
{
    try {
        TiXmlDocument* doc = new TiXmlDocument (fname.c_str());
        doc->LoadFile ();
        TiXmlElement* root = doc->RootElement ();
        
        cout << root->Value () << endl;

        TiXmlElement* version = root->FirstChildElement ();
        TiXmlAttribute* atti_major = version->FirstAttribute ();
        TiXmlAttribute* atti_minor = version->LastAttribute ();

        TiXmlElement* file = version->FirstChildElement ();
        TiXmlAttribute* atti_size = file->FirstAttribute ();
        TiXmlAttribute* atti_date = file->LastAttribute ();

        cout << version->FirstChild ()->Value() << endl;
        cout << atti_major->Name () << ": " << atti_major->Value () << ", " <<
        atti_minor->Name () << ": " << atti_minor->Value () << endl;
        cout << file->FirstChild ()->Value() << endl;
        cout << atti_size->Name () << ": " << atti_size->Value () << ", " << \
        atti_date->Name () << ": " << atti_date->Value () << endl;

    }
    catch (string& e) {
        return (false);
    }

    return true;
}
コード例 #2
0
// -----------------------------------------------------------------------------
// Obtain the name of the current element's last attribute
// -----------------------------------------------------------------------------
const char* SimXMLDocument::lastAttribute()
{
   // Get the current element
   if(m_paNode.empty())
   {
      return StringTable->EmptyString;
   }
   const int iLastElement = m_paNode.size() - 1;
   TiXmlElement* pNode = m_paNode[iLastElement];
   if(!pNode)
   {
      return StringTable->EmptyString;
   }

   // Gets its last attribute, if any
   m_CurrentAttribute = pNode->LastAttribute();
   if(!m_CurrentAttribute)
   {
      return StringTable->EmptyString;
   }

   return m_CurrentAttribute->Name();
}
コード例 #3
0
//---------------------------------------------------------
int ofxXmlSettings::getNumAttributes(const string& tag, int which){
	vector<string> tokens = tokenize(tag,":");
	TiXmlHandle tagHandle = storedHandle;
	for (int x = 0; x < (int)tokens.size(); x++) {
		if (x == 0)
			tagHandle = tagHandle.ChildElement(tokens.at(x), which);
		else
			tagHandle = tagHandle.FirstChildElement(tokens.at(x));
	}

	if (tagHandle.ToElement()) {
		TiXmlElement* elem = tagHandle.ToElement();

		// Do stuff with the element here
		TiXmlAttribute* first = elem->FirstAttribute();
		if (first) {
			int count = 1;
			for (TiXmlAttribute* curr = first; curr != elem->LastAttribute(); curr = curr->Next())
				count++;
			return count;
		}
	}
	return 0;
}
コード例 #4
0
vector<EncodedAttributeInfo*> LoadSavedDataSources::loadCodedAttributesFromMultipleFiles( string dsName,int rowCount,bool limit )
{
	vector<EncodedAttributeInfo*> codedAtts;
	try
	{
		for (int j = 0 ; j < this->saved_file_names.size() ; j++)
		{
			this->_fileName = ConfigurationReader::ReadConfiguration(ConfigurationReader::configutation::SAVE_DATA_FOLDER) + this->_saved_folder + "\\" + this->saved_file_names[j];
			TiXmlDocument *doc_1 = new TiXmlDocument(this->_fileName.c_str());
			doc_1->LoadFile();
			TiXmlHandle handler(doc_1);
			TiXmlElement *dsElement = handler.FirstChild("DataSources").ToElement();
			dsElement = dsElement->FirstChildElement("DataSource");
			if (strcmp(dsElement->Attribute("Name"),dsName.c_str()) == 0)
			{
				dsElement = dsElement->FirstChildElement("CodedAttribute");
				int attID = dsElement->FirstAttribute()->IntValue();
				int attType = atoi(dsElement->Attribute("Type"));
				string attName = dsElement->Attribute("Name");
				int noVStreams = dsElement->LastAttribute()->IntValue();
				EncodedAttributeInfo* attr;
				switch(attType){
					case 0:
						{
							EncodedIntAttribute *intAtt = new EncodedIntAttribute();
							intAtt->setAttID(attID);
							intAtt->setAttName(attName);
							intAtt->setNoOfVBitStreams(noVStreams,rowCount);
							intAtt->setAttType(getAttType(attType));

							BitStreamInfo** bitStreams = new BitStreamInfo*[noVStreams];
							TiXmlElement *vbs = dsElement->FirstChildElement("VBitStreams")->FirstChildElement("vbitstream");
							for (int k = 0 ; k < noVStreams ; k++)
							{
								BitStreamInfo* bitStr = new VBitStream();
								bitStr->setBitCount(rowCount);
								bitStr->setBitStreamAllocAttID(attID);
								bitStr->setBitStreamAllocAttName(attName);
								string bitStream;
								if (limit)
								{
									bitStream = vbs->GetText();
									long offset = rowCount - this->_rowLimit;
									bitStream = bitStream.substr(offset,this->_rowLimit);
								}
								else bitStream = vbs->GetText();
								dynamic_bitset<> temp(bitStream);
								bitStr->convert(temp);
								bitStreams[k] = bitStr;
								vbs = vbs->NextSiblingElement("vbitstream");
							}
							vector<BitStreamInfo*> tempVB(bitStreams , bitStreams + noVStreams);
							intAtt->setVBitStreams(tempVB);
							attr = intAtt;
							codedAtts.push_back(attr);
							break;
						}
					case 1:
						{
							EncodedDoubleAttribute *doubleAtt = new EncodedDoubleAttribute();
							doubleAtt->setAttID(attID);
							doubleAtt->setAttName(attName);
							doubleAtt->setNoOfVBitStreams(noVStreams,rowCount);
							doubleAtt->setAttType(getAttType(attType));

							BitStreamInfo** bitStreams = new BitStreamInfo*[noVStreams];
							TiXmlElement *vbs = dsElement->FirstChildElement("VBitStreams")->FirstChildElement("vbitstream");
							for (int k = 0 ; k < noVStreams ; k++)
							{
								BitStreamInfo* bitStr = new VBitStream();
								bitStr->setBitCount(rowCount);
								bitStr->setBitStreamAllocAttID(attID);
								bitStr->setBitStreamAllocAttName(attName);
								string bitStream;
								if (limit)
								{
									bitStream = vbs->GetText();
									long offset = rowCount - this->_rowLimit;
									bitStream = bitStream.substr(offset,this->_rowLimit);
								}
								else bitStream = vbs->GetText();
								dynamic_bitset<> temp(bitStream);
								bitStr->convert(temp);
								bitStreams[k] = bitStr;
								vbs = vbs->NextSiblingElement("vbitstream");
							}
							vector<BitStreamInfo*> tempVB(bitStreams , bitStreams + noVStreams);
							doubleAtt->setVBitStreams(tempVB);
							attr = doubleAtt;
							codedAtts.push_back(attr);
							break;
						}
					case 3:
						{
							EncodedMultiCatAttribute *catAtt = new EncodedMultiCatAttribute();
							catAtt->setAttID(attID);
							catAtt->setAttName(attName);
							catAtt->setAttType(getAttType(attType));
							catAtt->setNoOfVBitStreams(noVStreams,rowCount);

							BitStreamInfo** bitStreams = new BitStreamInfo*[noVStreams];
							TiXmlElement *vbs = dsElement->FirstChildElement("VBitStreams")->FirstChildElement("vbitstream");
							for (int k = 0 ; k < noVStreams ; k++)
							{
								BitStreamInfo* bitStr = new VBitStream();
								bitStr->setBitCount(rowCount);
								bitStr->setBitStreamAllocAttID(attID);
								bitStr->setBitStreamAllocAttName(attName);
								string bitStream;
								if (limit)
								{
									bitStream = vbs->GetText();
									long offset = rowCount - this->_rowLimit;
									bitStream = bitStream.substr(offset,this->_rowLimit);
								}
								else bitStream = vbs->GetText();
								dynamic_bitset<> temp(bitStream);
								bitStr->convert(temp);
								bitStreams[k] = bitStr;
								vbs = vbs->NextSiblingElement("vbitstream");
							}
							vector<BitStreamInfo*> tempVB(bitStreams , bitStreams + noVStreams);
							catAtt->setVBitStreams(tempVB);
							attr = catAtt;
							codedAtts.push_back(attr);
							break;
						}
				}
			}
			delete doc_1;
		}
	}
	catch(...)
	{
		error_loading_encoded_data ex;
		string err = ExceptionReader::GetError(SM1017);
		err += "-> Try to load from a multiple attribute data files";
		ex << error_message(err);
		ex << error_code(SM1017);
		BOOST_THROW_EXCEPTION(ex);
	}
	return codedAtts;
}
コード例 #5
0
DataSources* LoadSavedDataSources::loadSavedEncodedDataFromMultipleFiles( bool limit /*= false*/ )
{
	DataSources *dss = new DataSources();
	string metaDataFile = ConfigurationReader::ReadConfiguration(ConfigurationReader::configutation::SAVE_DATA_FOLDER) + this->_saved_folder + "\\" + this->_metaFile + ".xml";
	if (chdir(ConfigurationReader::ReadConfiguration(ConfigurationReader::configutation::SAVE_DATA_FOLDER).c_str()) == -1)
	{
		error_folder_not_exist ex;
		string err = ExceptionReader::GetError(SM1015);
		err += "-> Saved data folder provided in config file is missing";
		ex << error_message(err);
		ex << error_code(SM1015);
		BOOST_THROW_EXCEPTION(ex);
	}
	
	//string metaDataFile = ConfigurationReader::ReadConfiguration(ConfigurationReader::configutation::SAVE_DATA_FOLDER) + this->_saved_folder + "/" + this->_metaFile + ".xml";
	//string encodedDataFile = "../Reports/" + this->_fileName + ".xml";
	//this->_fileName=encodedDataFile;
	//string metaDataFile = "..\\Reports\\" + this->_metaFile + ".xml";
	try
	{
		TiXmlDocument doc(metaDataFile.c_str());
		bool loaded = doc.LoadFile();
		TiXmlHandle handler( &doc );
		if (loaded)
		{
			TiXmlElement *root = handler.FirstChild("DataSources").ToElement();
			int dataSources = root->FirstAttribute()->IntValue();
			for (int i = 0 ; i < dataSources ; i++)
			{
				TiXmlElement *dsElement = root->FirstChildElement("DataSource");
				string dsName = dsElement->FirstAttribute()->Value();
				dsElement = dsElement->FirstChildElement("noOfAttributes");
				int noAtts = atoi(dsElement->GetText());

				//position where attributes from multiple attribute files are loaded.
				dsElement = dsElement->NextSiblingElement("AttributeFiles");
				TiXmlElement* saved_file_att_element = dsElement->FirstChildElement("att_file");
				this->saved_file_names.resize(noAtts);
				int count_att = 0;
				while (saved_file_att_element)
				{
					this->saved_file_names[count_att++] = saved_file_att_element->GetText();
					saved_file_att_element = saved_file_att_element->NextSiblingElement("att_file");
				}

				dsElement = dsElement->NextSiblingElement("noOfRows");
				int noRows = atoi(dsElement->GetText());
				//Following two lines will load the existance bitmap from the saved file.
				//For older versions of saved data files, this won't be working.
				//So for old data file loading, just comment the following two lines.
				//And also make sure to comment the place where the existance_map is added to wrapdatasource object.
				//string existanceMap = dsElement->NextSiblingElement("existanceBitMap")->GetText();
				//dynamic_bitset<> existance_map(existanceMap);

				vector<EncodedAttributeInfo*> codedAtts = loadCodedAttributesFromMultipleFiles(dsName,noRows,limit);
				if (limit)
				{
					if (this->_rowLimit > noRows)
					{
						this->_rowLimit = noRows;
					}
					noRows = this->_rowLimit;
				}

				dsElement = dsElement->NextSiblingElement("DataSourceType");
				WrapDataSource::DATASOURCE sourceType = getDataSourceType(atoi(dsElement->GetText()));
				WrapDataSource *ds = new WrapDataSource();
				ds->setDSName(dsName);
				ds->noOfAttributes(noAtts);
				ds->noOfRows(noRows);
				ds->setSourceType(sourceType);
				//comment this for loading old saved files. 
				//ds->ExistanceDatabitMap(existance_map);
				dsElement = dsElement->NextSiblingElement("CodedAttributes");
				TiXmlElement *attElement = dsElement->FirstChildElement("Attribute");
				int counter = 0;
				while (attElement && (counter <= noAtts))
				{
					int attType = attElement->LastAttribute()->IntValue();
					int attID = attElement->FirstAttribute()->IntValue();
					switch(attType)
					{
					case 0:
						{
							EncodedIntAttribute* intAtt = static_cast<EncodedIntAttribute*>(codedAtts[counter]);
							TiXmlElement *attEl = attElement->FirstChildElement("maxval");
							intAtt->setMaxVal(atol(attEl->GetText()));
							attEl = attElement->FirstChildElement("minval");
							intAtt->setMinVal(atol(attEl->GetText()));
							attEl = attElement->FirstChildElement("SignBitSet");
							//attEl = attElement->FirstChildElement("SignMapVal");
							// 						vector<bool> signMap;
							// 						if (atol(attEl->GetText()) == 0)
							// 						{						
							// 							signMap.resize(noRows);
							// 						}
							// 						//Set sign Bit Map for negative vals.
							// 						else
							// 						{
							// 							signMap.resize(noRows);
							// 						}
							// 						intAtt->setSignBitMap(signMap);

							dynamic_bitset<> signSet((string)attEl->GetText());
							intAtt->setSignBitSet(signSet);
							EncodedAttributeInfo* atts = intAtt;
							codedAtts[counter] = atts;
							break;
						}
					case 1:
						{
							EncodedDoubleAttribute* doubleAtt = static_cast<EncodedDoubleAttribute*>(codedAtts[counter]);
							TiXmlElement *attEl = attElement->FirstChildElement("maxval");
							doubleAtt->setMaxVal(atol(attEl->GetText()));
							attEl = attElement->FirstChildElement("minval");
							doubleAtt->setMinVal(atol(attEl->GetText()));
							attEl = attElement->FirstChildElement("SignBitSet");
							//attEl = attElement->FirstChildElement("SignMapVal");
							// 						vector<bool> signMap;
							// 						if (atol(attEl->GetText()) == 0)
							// 						{						
							// 							signMap.resize(noRows);
							// 						}
							// 						//Set sign Bit Map for negative vals.
							// 						else
							// 						{
							// 							signMap.resize(noRows);
							// 						}
							// 						doubleAtt->SignBitMap(signMap);

							dynamic_bitset<> signSet((string)attEl->GetText());
							doubleAtt->setSignBitSet(signSet);
							attEl = attElement->FirstChildElement("PrecisionVal");
							doubleAtt->Precision(atol(attEl->GetText()));
							EncodedAttributeInfo* atts = doubleAtt;
							codedAtts[counter] = atts;
							break;
						}
					case 3:
						{
							EncodedMultiCatAttribute* catAtt = static_cast<EncodedMultiCatAttribute*>(codedAtts[counter]);
							TiXmlElement *uniqueElement = attElement->FirstChildElement("UniqueValues");
							int noUniques = uniqueElement->LastAttribute()->IntValue();
							vector<string> uniqueVals;
							uniqueVals.resize(noUniques);
							uniqueElement = uniqueElement->FirstChildElement("Val");
							for (int k = 0 ; k < noUniques ; k++)
							{
								string val = uniqueElement->GetText();
								uniqueVals[k] = val;
								uniqueElement = uniqueElement->NextSiblingElement("Val");
							}
							catAtt->setUniqueValList(uniqueVals);
							EncodedAttributeInfo *atts = catAtt;
							codedAtts[counter] = atts;
							break;
						}
					}
					attElement = attElement->NextSiblingElement("Attribute");
					counter++;
				}
				ds->CodedAtts(codedAtts);
				dss->insertDataSources(ds);
			}
		}		
	}
	catch(...)
	{
		error_loading_encoded_data ex;
		string err = ExceptionReader::GetError(SM1017);
		err += "-> Try to load from a single attribute data file";
		ex << error_message(err);
		ex << error_code(SM1017);
		BOOST_THROW_EXCEPTION(ex);
	}
	
	return dss;
}
コード例 #6
0
vector<EncodedAttributeInfo*> LoadSavedDataSources::loadCodedAttributes(string dsName,int rowCount,bool limit){
	TiXmlDocument doc_1(this->_fileName.c_str());
	doc_1.LoadFile();
	TiXmlHandle handler(&doc_1);
	TiXmlElement *dsElement = handler.FirstChild("DataSources").ToElement();
	dsElement = dsElement->FirstChildElement("DataSource");
	vector<EncodedAttributeInfo*> codedAtts;
	try
	{
		while (dsElement)
		{
			if (strcmp(dsElement->Attribute("Name"),dsName.c_str()) == 0)
			{
				dsElement = dsElement->FirstChildElement("CodedAttributes")->FirstChildElement("Attribute");
				while (dsElement)
				{
					int attID = dsElement->FirstAttribute()->IntValue();
					int attType = atoi(dsElement->Attribute("Type"));
					string attName = dsElement->Attribute("Name");
					int noVStreams = dsElement->LastAttribute()->IntValue();
					EncodedAttributeInfo* attr;
					switch(attType){
					case 0:
						{
							EncodedIntAttribute *intAtt = new EncodedIntAttribute();
							intAtt->setAttID(attID);
							intAtt->setAttName(attName);
							intAtt->setNoOfVBitStreams(noVStreams,rowCount);
							intAtt->setAttType(getAttType(attType));

							BitStreamInfo** bitStreams = new BitStreamInfo*[noVStreams];
							TiXmlElement *vbs = dsElement->FirstChildElement("VBitStreams")->FirstChildElement("vbitstream");
							for (int k = 0 ; k < noVStreams ; k++)
							{
								BitStreamInfo* bitStr = new VBitStream();
								bitStr->setBitCount(rowCount);
								bitStr->setBitStreamAllocAttID(attID);
								bitStr->setBitStreamAllocAttName(attName);
								string bitStream;
								if (limit)
								{
									bitStream = vbs->GetText();
									long offset = rowCount - this->_rowLimit;
									bitStream = bitStream.substr(offset,this->_rowLimit);
								}
								else bitStream = vbs->GetText();
								dynamic_bitset<> temp(bitStream);
								bitStr->convert(temp);
								bitStreams[k] = bitStr;
								vbs = vbs->NextSiblingElement("vbitstream");
							}
							vector<BitStreamInfo*> tempVB(bitStreams , bitStreams + noVStreams);
							intAtt->setVBitStreams(tempVB);
							attr = intAtt;
							codedAtts.push_back(attr);
							break;
						}
					case 1:
						{
							EncodedDoubleAttribute *doubleAtt = new EncodedDoubleAttribute();
							doubleAtt->setAttID(attID);
							doubleAtt->setAttName(attName);
							doubleAtt->setNoOfVBitStreams(noVStreams,rowCount);
							doubleAtt->setAttType(getAttType(attType));

							BitStreamInfo** bitStreams = new BitStreamInfo*[noVStreams];
							TiXmlElement *vbs = dsElement->FirstChildElement("VBitStreams")->FirstChildElement("vbitstream");
							for (int k = 0 ; k < noVStreams ; k++)
							{
								BitStreamInfo* bitStr = new VBitStream();
								bitStr->setBitCount(rowCount);
								bitStr->setBitStreamAllocAttID(attID);
								bitStr->setBitStreamAllocAttName(attName);
								string bitStream;
								if (limit)
								{
									bitStream = vbs->GetText();
									long offset = rowCount - this->_rowLimit;
									bitStream = bitStream.substr(offset,this->_rowLimit);
								}
								else bitStream = vbs->GetText();
								dynamic_bitset<> temp(bitStream);
								bitStr->convert(temp);
								bitStreams[k] = bitStr;
								vbs = vbs->NextSiblingElement("vbitstream");
							}
							vector<BitStreamInfo*> tempVB(bitStreams , bitStreams + noVStreams);
							doubleAtt->setVBitStreams(tempVB);
							attr = doubleAtt;
							codedAtts.push_back(attr);
							break;
						}
					case 3:
						{
							EncodedMultiCatAttribute *catAtt = new EncodedMultiCatAttribute();
							catAtt->setAttID(attID);
							catAtt->setAttName(attName);
							catAtt->setAttType(getAttType(attType));
							catAtt->setNoOfVBitStreams(noVStreams,rowCount);

							BitStreamInfo** bitStreams = new BitStreamInfo*[noVStreams];
							TiXmlElement *vbs = dsElement->FirstChildElement("VBitStreams")->FirstChildElement("vbitstream");
							for (int k = 0 ; k < noVStreams ; k++)
							{
								BitStreamInfo* bitStr = new VBitStream();
								bitStr->setBitCount(rowCount);
								bitStr->setBitStreamAllocAttID(attID);
								bitStr->setBitStreamAllocAttName(attName);
								string bitStream;
								if (limit)
								{
									bitStream = vbs->GetText();
									long offset = rowCount - this->_rowLimit;
									bitStream = bitStream.substr(offset,this->_rowLimit);
								}
								else bitStream = vbs->GetText();
								dynamic_bitset<> temp(bitStream);
								bitStr->convert(temp);
								bitStreams[k] = bitStr;
								vbs = vbs->NextSiblingElement("vbitstream");
							}
							vector<BitStreamInfo*> tempVB(bitStreams , bitStreams + noVStreams);
							catAtt->setVBitStreams(tempVB);
							attr = catAtt;
							codedAtts.push_back(attr);
							break;
						}

					}

					dsElement = dsElement->NextSiblingElement("Attribute");
				}
			}
			else{
				dsElement = dsElement->NextSiblingElement("DataSource");
				continue;
			}
		}
	}
	catch(...)
	{
		error_loading_encoded_data ex;
		ex << error_message(ExceptionReader::GetError(SM1017));
		ex << error_code(SM1017);
		BOOST_THROW_EXCEPTION(ex);
	}
	return codedAtts;
}