From: Mark J. <mar...@us...> - 2006-12-22 04:16:10
|
Update of /cvsroot/xlw/xlw/xlw In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv27301/xlw Modified Files: ArgList.h ArgList.cpp Log Message: changed to make lists work with VC6 also introduced "add" method to make it easy to build up arg lists for returning data Index: ArgList.h =================================================================== RCS file: /cvsroot/xlw/xlw/xlw/ArgList.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** ArgList.h 10 Dec 2006 01:18:40 -0000 1.2 --- ArgList.h 22 Dec 2006 04:16:07 -0000 1.3 *************** *** 39,42 **** --- 39,44 ---- std::string ErrorIdentifier); + ArgumentList(std::string name); + enum ArgumentType *************** *** 58,64 **** CellMatrix GetCellsArgumentValue(const std::string& ArgumentName); - #if !(defined(_MSC_VER)) || _MSC_VER > 1250 // get a proper compiler ArgumentList GetArgumentListArgumentValue(const std::string& ArgumentName); ! #endif --- 60,65 ---- CellMatrix GetCellsArgumentValue(const std::string& ArgumentName); ArgumentList GetArgumentListArgumentValue(const std::string& ArgumentName); ! *************** *** 70,74 **** // creating the same argumnet list // useful for checking the class works! ! private: --- 71,86 ---- // creating the same argumnet list // useful for checking the class works! ! ! // data insertions ! ! void add(const std::string& ArgumentName, const std::string& value); ! void add(const std::string& ArgumentName, double value); ! void add(const std::string& ArgumentName, const MyArray& value); ! void add(const std::string& ArgumentName, const MyMatrix& value); ! void add(const std::string& ArgumentName, bool value); ! void add(const std::string& ArgumentName, const CellMatrix& values); ! void addList(const std::string& ArgumentName, const CellMatrix& values); ! void add(const std::string& ArgumentName, const ArgumentList& values); ! private: *************** *** 80,87 **** std::map<std::string,MyMatrix> MatrixArguments; std::map<std::string,std::string> StringArguments; ! ! #if !(defined(_MSC_VER)) || _MSC_VER > 1250 // get a proper compiler ! std::map<std::string,ArgumentList> ListArguments; ! #endif --- 92,96 ---- std::map<std::string,MyMatrix> MatrixArguments; std::map<std::string,std::string> StringArguments; ! std::map<std::string,CellMatrix> ListArguments; *************** *** 95,99 **** void GenerateThrow(std::string message, unsigned long row, unsigned long column); void UseArgumentName(const std::string& ArgumentName); // private as no error checking performed ! }; --- 104,108 ---- void GenerateThrow(std::string message, unsigned long row, unsigned long column); void UseArgumentName(const std::string& ArgumentName); // private as no error checking performed ! void RegisterName(const std::string& ArgumentName, ArgumentType type); }; Index: ArgList.cpp =================================================================== RCS file: /cvsroot/xlw/xlw/xlw/ArgList.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** ArgList.cpp 10 Dec 2006 01:18:40 -0000 1.2 --- ArgList.cpp 22 Dec 2006 04:16:07 -0000 1.3 *************** *** 104,107 **** --- 104,191 ---- + void ArgumentList::add(const std::string& ArgumentName, const std::string& value) + { + ArgumentType thisOne = string; + std::pair<std::string, ArgumentType> thisPair(ArgumentName,thisOne); + ArgumentNames.push_back(thisPair); + + std::pair<std::string,std::string> valuePair(ArgumentName,value); + StringArguments.insert(valuePair); + + RegisterName(ArgumentName, thisOne); + } + + void ArgumentList::add(const std::string& ArgumentName, double value) + { + ArgumentType thisOne = number; + std::pair<std::string, ArgumentType> thisPair(ArgumentName,thisOne); + ArgumentNames.push_back(thisPair); + + std::pair<std::string,double> valuePair(ArgumentName,value); + DoubleArguments.insert(valuePair); + + RegisterName(ArgumentName, thisOne); + + } + + void ArgumentList::add(const std::string& ArgumentName, const MyArray& value) + { + ArgumentType thisOne = vector; + std::pair<std::string, ArgumentType> thisPair(ArgumentName,thisOne); + ArgumentNames.push_back(thisPair); + ArrayArguments.insert(std::make_pair(ArgumentName,value)); + + RegisterName(ArgumentName, thisOne); + } + + void ArgumentList::add(const std::string& ArgumentName, const MyMatrix& value) + { + ArgumentType thisOne = matrix; + std::pair<std::string, ArgumentType> thisPair(ArgumentName,thisOne); + ArgumentNames.push_back(thisPair); + MatrixArguments.insert(std::make_pair(ArgumentName,value)); + + RegisterName(ArgumentName, thisOne); + } + + void ArgumentList::add(const std::string& ArgumentName, bool value) + { + ArgumentType thisOne = boolean; + std::pair<std::string, ArgumentType> thisPair(ArgumentName,thisOne); + ArgumentNames.push_back(thisPair); + BoolArguments.insert(std::make_pair(ArgumentName,value)); + + RegisterName(ArgumentName, thisOne); + + } + + void ArgumentList::add(const std::string& ArgumentName, const CellMatrix& values) + { + ArgumentType thisOne = cells; + std::pair<std::string, ArgumentType> thisPair(ArgumentName,thisOne); + ArgumentNames.push_back(thisPair); + CellArguments.insert(std::make_pair(ArgumentName,values)); + + RegisterName(ArgumentName, thisOne); + + } + + + void ArgumentList::addList(const std::string& ArgumentName, const CellMatrix& values) + { + ArgumentType thisOne = list; + std::pair<std::string, ArgumentType> thisPair(ArgumentName,thisOne); + ArgumentNames.push_back(thisPair); + ListArguments.insert(std::make_pair(ArgumentName,values)); + + + RegisterName(ArgumentName, thisOne); + } + + void ArgumentList::add(const std::string& ArgumentName, const ArgumentList& values) + { + CellMatrix cellValues(values.AllData()); + addList(ArgumentName,cellValues); + } ArgumentList::ArgumentList(CellMatrix cells, *************** *** 179,192 **** if (cellBelow.IsANumber()) { ! double value = cellBelow.NumericValue(); ! ! ArgumentType thisOne = number; ! ! std::pair<std::string, ArgumentType> thisPair(thisName,thisOne); ! ArgumentNames.push_back(thisPair); ! ! std::pair<std::string,double> valuePair(thisName,value); ! ! DoubleArguments.insert(valuePair); column++; --- 263,267 ---- if (cellBelow.IsANumber()) { ! add(thisName, cellBelow.NumericValue()); column++; *************** *** 197,211 **** if (cellBelow.IsBoolean()) { ! ! bool value = cellBelow.BooleanValue(); ! ! ArgumentType thisOne = boolean; ! ! std::pair<std::string, ArgumentType> thisPair(thisName,thisOne); ! ArgumentNames.push_back(thisPair); ! ! std::pair<std::string,bool> valuePair(thisName,value); ! ! BoolArguments.insert(valuePair); column++; --- 272,276 ---- if (cellBelow.IsBoolean()) { ! add(thisName, cellBelow.BooleanValue()); column++; *************** *** 227,256 **** if (cellBelow.StringValueLowerCase() == "list") { - #ifdef VC6 - throw("if you want list arguments don't use vc6."); - #else ArgumentList value(extracted,ErrorId+":"+thisName); ! ArgumentType thisOne = list; ! ! std::pair<std::string, ArgumentType> thisPair(thisName,thisOne); ! ArgumentNames.push_back(thisPair); - std::pair<std::string,ArgumentList> valuePair(thisName,value); - - ListArguments.insert(valuePair); - #endif } if (cellBelow.StringValueLowerCase() == "cells") { ! ArgumentType thisOne = ArgumentList::cells; ! ! std::pair<std::string, ArgumentType> thisPair(thisName,thisOne); ! ArgumentNames.push_back(thisPair); ! ! std::pair<std::string,CellMatrix> valuePair(thisName,extracted); ! ! CellArguments.insert(valuePair); } --- 292,304 ---- if (cellBelow.StringValueLowerCase() == "list") { ArgumentList value(extracted,ErrorId+":"+thisName); ! addList(thisName, extracted); //note not value } if (cellBelow.StringValueLowerCase() == "cells") { ! add(thisName,extracted); } *************** *** 261,278 **** throw("Non numerical value in matrix argument :"+thisName+ " "+ErrorId); - ArgumentType thisOne = matrix; - MJMatrix value(extracted.RowsInStructure(),extracted.ColumnsInStructure()); for (unsigned long i=0; i < extracted.RowsInStructure(); i++) for (unsigned long j=0; j < extracted.ColumnsInStructure(); j++) ! value(i,j) = extracted(i,j); ! ! std::pair<std::string, ArgumentType> thisPair(thisName,thisOne); ! ArgumentNames.push_back(thisPair); ! std::pair<std::string,MJMatrix> valuePair(thisName,value); - MatrixArguments.insert(valuePair); } --- 309,320 ---- throw("Non numerical value in matrix argument :"+thisName+ " "+ErrorId); MJMatrix value(extracted.RowsInStructure(),extracted.ColumnsInStructure()); for (unsigned long i=0; i < extracted.RowsInStructure(); i++) for (unsigned long j=0; j < extracted.ColumnsInStructure(); j++) ! ChangingElement(value,i,j) = extracted(i,j); ! add(thisName,value); } *************** *** 287,292 **** { cellBelow.clear(); ! ArgumentType thisOne = vector; ! if (row+2>= rows) throw(ErrorId+" data expected below array "+thisName); --- 329,333 ---- { cellBelow.clear(); ! if (row+2>= rows) throw(ErrorId+" data expected below array "+thisName); *************** *** 307,318 **** } - - std::pair<std::string, ArgumentType> thisPair(thisName,thisOne); - ArgumentNames.push_back(thisPair); - - std::pair<std::string,MyArray> valuePair(thisName,theArray); - - ArrayArguments.insert(valuePair); rowsDown = maxi(rowsDown,size+2); --- 348,353 ---- } + add(thisName,theArray); rowsDown = maxi(rowsDown,size+2); *************** *** 322,335 **** { std::string value = cellBelow.StringValueLowerCase(); ! ! ArgumentType thisOne = string; ! ! std::pair<std::string, ArgumentType> thisPair(thisName,thisOne); ! ArgumentNames.push_back(thisPair); ! ! std::pair<std::string,std::string> valuePair(thisName,value); ! ! StringArguments.insert(valuePair); ! column++; --- 357,361 ---- { std::string value = cellBelow.StringValueLowerCase(); ! add(thisName,value); column++; *************** *** 352,364 **** GenerateThrow("extraneous data "+ErrorId,i,j); }} ! {for (unsigned long i=0; i < ArgumentNames.size(); i++) ! { ! if (!(Names.insert(ArgumentNames[i]).second) ) ! throw("Same argument name used twice "+ArgumentNames[i].first+" "+ErrorId); - ArgumentsUsed.insert(std::pair<std::string,bool>(ArgumentNames[i].first,false)); - } - } } --- 378,391 ---- GenerateThrow("extraneous data "+ErrorId,i,j); }} + } ! void ArgumentList::RegisterName(const std::string& ArgumentName, ArgumentType type) ! { ! ArgumentNames.push_back(std::make_pair(ArgumentName,type)); ! if (!(Names.insert(*ArgumentNames.rbegin()).second) ) ! throw("Same argument name used twice "+ArgumentName); ! ! ArgumentsUsed.insert(std::pair<std::string,bool>(ArgumentName,false)); } *************** *** 458,467 **** } ! #ifndef VC6 ArgumentList ArgumentList::GetArgumentListArgumentValue(const std::string& ArgumentName_) { std::string ArgumentName(ArgumentName_); MakeLowerCase(ArgumentName); ! std::map<std::string, ArgumentList>::const_iterator it = ListArguments.find(ArgumentName); if (it == ListArguments.end()) --- 485,494 ---- } ! ArgumentList ArgumentList::GetArgumentListArgumentValue(const std::string& ArgumentName_) { std::string ArgumentName(ArgumentName_); MakeLowerCase(ArgumentName); ! std::map<std::string, CellMatrix>::const_iterator it = ListArguments.find(ArgumentName); if (it == ListArguments.end()) *************** *** 469,475 **** UseArgumentName(ArgumentName); ! return it->second; } - #endif CellMatrix ArgumentList::GetCellsArgumentValue(const std::string& ArgumentName_) --- 496,501 ---- UseArgumentName(ArgumentName); ! return ArgumentList(it->second,ArgumentName); } CellMatrix ArgumentList::GetCellsArgumentValue(const std::string& ArgumentName_) *************** *** 513,516 **** --- 539,546 ---- } + ArgumentList::ArgumentList(std::string name) : StructureName(name) + { + + } CellMatrix ArgumentList::AllData() const *************** *** 550,554 **** for (unsigned long i=0; i < it->second.rows(); i++) for (unsigned long j=0; j < it->second.columns(); j++) ! tmp(i+3,j)=it->second(i,j); results.PushBottom(tmp); }} --- 580,584 ---- for (unsigned long i=0; i < it->second.rows(); i++) for (unsigned long j=0; j < it->second.columns(); j++) ! tmp(i+3,j)=Element(it->second,i,j); results.PushBottom(tmp); }} *************** *** 585,604 **** results.PushBottom(tmp); }} ! #ifndef VC6 ! {for (std::map<std::string,ArgumentList>::const_iterator it= ListArguments.begin(); it != ListArguments.end(); it++) { ! CellMatrix cells(it->second.AllData()); ! ! CellMatrix tmp(3,2); ! tmp(0,0) = it->first; ! tmp(1,0) = std::string("list"); ! tmp(2,0) = static_cast<double>(cells.RowsInStructure()); ! tmp(2,1) = static_cast<double>(cells.ColumnsInStructure()); ! tmp.PushBottom(cells); ! ! results.PushBottom(tmp); }} ! #endif --- 615,633 ---- results.PushBottom(tmp); }} ! ! {for (std::map<std::string,CellMatrix>::const_iterator it= ListArguments.begin(); it != ListArguments.end(); it++) { ! CellMatrix tmp(3+it->second.RowsInStructure(),maxi(2UL,it->second.ColumnsInStructure())); ! tmp(0,0) = it->first; ! tmp(1,0) = std::string("list"); ! tmp(2,0) = static_cast<double>(it->second.RowsInStructure()); ! tmp(2,1) = static_cast<double>(it->second.ColumnsInStructure()); ! for (unsigned long i=0; i < it->second.RowsInStructure(); i++) ! for (unsigned long j=0; j < it->second.ColumnsInStructure(); j++) ! tmp(i+3,j)=it->second(i,j); ! results.PushBottom(tmp); }} ! |