/* * DAssignment.cpp * * Created on: Sep 28, 2010 * Author: romanov */ #include "Model/DAssignment.h" #include "DStringUtils.h" #include "DCCDBGlobals.h" #include #include #include using namespace ccdb; using namespace std; ccdb::DAssignment::DAssignment( DObjectsOwner * owner/*=NULL*/, DDataProvider *provider/*=NULL*/ ) :DStoredObject(owner, provider) { mRawData = string(); // data blob mId=0; // id in database mDataBlobId = 0; // blob id in database mVariationId = 0; // database ID of variation mRunRangeId = 0; // database ID of run range mDataVaultId = 0; // database ID of data blob mEventRangeId = 0; // event range ID mRequestedRun = 0; // Run than was requested for user mRunRange = NULL; // Run range object, is NULL if not set mEventRange = NULL; // Event range object, is NULL if not set mVariation = NULL; // Variation object, is NULL if not set mTypeTable = NULL; // Reference to type table } ccdb::DAssignment::~DAssignment() { // TODO Auto-generated destructor stub } bool ccdb::DAssignment::MapData(vector > & mappedData, const vector& data, const vector& columns ) { //check error if(data.size() % columns.size() !=0) { //TODO print error; return false; } //loop int rows = data.size() / columns.size(); vector::const_iterator dataIter= data.begin(); for (int rowIter = 0; rowIter < rows ; rowIter++) { map line; for(vector::const_iterator it=columns.begin(); it > & mappedData, const vector& data, int columnsNum ) { //check error if(data.size() % columnsNum !=0) { //TODO print error; return false; } //loop int rows = data.size() / columnsNum; vector::const_iterator dataIter= data.begin(); for (int rowIter = 0; rowIter < rows ; rowIter++) { vector row; for(int i=0; i = data.end()) { //TODO print error; for now return false; } string cellValue = *dataIter; row.push_back(cellValue); ++dataIter; } mappedData.push_back(row); } return true; } void ccdb::DAssignment::SplitData( vector& outArray,string blob ) { //split blob from DB to tokens and data DStringUtils::Split(blob,outArray, "|"); } unsigned int ccdb::DAssignment::GetVariationId() const { return mVariationId; } void ccdb::DAssignment::SetVariationId( unsigned int val ) { mVariationId = val; } unsigned int ccdb::DAssignment::GetRunRangeId() const { return mRunRangeId; } void ccdb::DAssignment::SetRunRangeId( unsigned int val ) { mRunRangeId = val; } unsigned int ccdb::DAssignment::GetDataVaultId() const { return mDataVaultId; } void ccdb::DAssignment::SetDataVaultId( unsigned int val ) { mDataVaultId = val; } unsigned int ccdb::DAssignment::GetEventRangeId() const { return mEventRangeId; } void ccdb::DAssignment::SetEventRangeId( unsigned int val ) { mEventRangeId = val; } int ccdb::DAssignment::GetRequestedRun() const { return mRequestedRun; } void ccdb::DAssignment::SetRequestedRun( int val ) { mRequestedRun = val; } DRunRange * ccdb::DAssignment::GetRunRange() const { return mRunRange; } void ccdb::DAssignment::SetRunRange( DRunRange * val ) { mRunRange = val; } DEventRange * ccdb::DAssignment::GetEventRange() const { return mEventRange; } void ccdb::DAssignment::SetEventRange( DEventRange * val ) { mEventRange = val; } DVariation * ccdb::DAssignment::GetVariation() const { return mVariation; } void ccdb::DAssignment::SetVariation( DVariation * val ) { mVariation = val; } string ccdb::DAssignment::VectorToBlob(const vector& values) { string result(""); if(values.size() <=0) { //TODO report error return result; } //stringstream sstream; //loop through blob vector::const_iterator iter=values.begin(); while(iter > ccdb::DAssignment::GetMappedData() const { vector > result; GetMappedData(result); return result; } void ccdb::DAssignment::GetMappedData(vector >& mappedData) const { if(mTypeTable == NULL) { //WARNING table type not loaded return; } if(mTypeTable->GetColumns().size()<=0) { //WARNING columns not loaded } //clear before filling mappedData.clear(); //fill data MapData(mappedData, GetVectorData(), mTypeTable->GetColumnNames() ); } std::vector > ccdb::DAssignment::GetData() const { std::vector > result; GetData(result); return result; } void ccdb::DAssignment::GetData(std::vector >& data) const { if(mTypeTable == NULL) { //WARNING table type not loaded return; } if(mTypeTable->GetColumns().size()<=0) { //WARNING columns not loaded } //clear before filling data.clear(); //fill data MapData(data, GetVectorData(), mTypeTable->GetNColumns()); } string ccdb::DAssignment::DecodeBlobSeparator(string str) { return DStringUtils::Replace("&delimeter;", CCDB_DATA_BLOB_DELIMETER, str); } string ccdb::DAssignment::EncodeBlobSeparator(string str) { return DStringUtils::Replace(CCDB_DATA_BLOB_DELIMETER, "&delimeter;", str); } vector ccdb::DAssignment::GetVectorData() const { //Just create vector and run it through GetVectorData(vector& vectorData) vector vect; GetVectorData(vect); return vect; } void ccdb::DAssignment::GetVectorData(vector& vectorData) const { //split data vector values = DStringUtils::Split(mRawData, CCDB_DATA_BLOB_DELIMETER); vectorData.clear(); vector::iterator iter=values.begin(); while(iter