00001
00002
00003 #include <iomanip>
00004 #include <iostream>
00005
00006
00007 #include "Registry/Registry.h"
00008 #include "Util/UtilString.h"
00009
00010
00011 #include "AlgAdapt.h"
00012
00013 using namespace std;
00014
00015
00016 Anp::AlgAdapt::AlgAdapt()
00017 :fName("generic")
00018 {
00019 }
00020
00021
00022 Anp::AlgAdapt::~AlgAdapt()
00023 {
00024 }
00025
00026
00027 const vector<double> Anp::AlgAdapt::GetVec(const string &key, const Registry ®) const
00028 {
00029 vector<double> dvec;
00030
00031 const char *value_char = 0;
00032 if(!reg.Get(key.c_str(), value_char))
00033 {
00034 return dvec;
00035 }
00036
00037 if(!value_char)
00038 {
00039 return dvec;
00040 }
00041
00042 vector<string> svec;
00043
00044 UtilString::StringTok(svec, string(value_char), ", ");
00045
00046 dvec = vector<double>(svec.size(), 0.0);
00047
00048 for(unsigned int i = 0; i < svec.size(); ++i)
00049 {
00050 if(!svec[i].empty())
00051 {
00052 dvec[i] = std::atof(svec[i].c_str());
00053 }
00054 else
00055 {
00056 dvec[i] = 0.0;
00057 }
00058 }
00059
00060 return dvec;
00061 }
00062
00063
00064 void Anp::AlgAdapt::PrintVec(const vector<double> &v, ostream &o, const unsigned int w, const unsigned int p) const
00065 {
00066 for(unsigned int i = 0; i < v.size(); ++i)
00067 {
00068 if(i == 0)
00069 {
00070 o << "(";
00071 }
00072 else
00073 {
00074 o << ", ";
00075 }
00076
00077 o << setprecision(p) << setw(w) << v[i];
00078
00079 if(i + 1 == v.size())
00080 {
00081 o << ")" << endl;
00082 }
00083 }
00084 }