00001 00002 // $Id: floatBuilder.cxx,v 1.1 2007/02/09 04:44:14 fmwk Exp $ 00003 // 00005 // 00006 // messier@indiana.edu 00008 #include "XMLInterface/floatBuilder.h" 00009 #include "XMLInterface/Stack.h" 00010 #include "XMLInterface/ChString.h" 00011 #include <vector> 00012 #include <iostream> 00013 00014 // Create and instance to be used by the XML parser 00015 static xmli::floatBuilder gsBuilder("float"); 00016 00017 //...................................................................... 00018 00019 xmli::floatBuilder::floatBuilder(const char* tag) : xmli::Builder(tag) { } 00020 00021 //...................................................................... 00022 00023 void xmli::floatBuilder::Build(const xmli::AttributeList& /*attr*/, 00024 const std::string& buffer) 00025 { 00026 //====================================================================== 00027 // Build a vector<float> from XML data and add it to the stack 00028 // attr - unused 00029 // buffer - list of space-separated floating point numbers 00030 //====================================================================== 00031 float f; 00032 std::vector<std::string> vs; 00033 std::vector<float> vf; 00034 00035 // Split the string in to sub fields and extra the values from each 00036 // sub-field 00037 xmli::ChString::Split(buffer.c_str()," ,\n\t\r",vs); 00038 std::vector<std::string>::iterator itr(vs.begin()); 00039 std::vector<std::string>::iterator itrEnd(vs.end()); 00040 for (; itr!=itrEnd; ++itr) { 00041 f = atof(itr->c_str()); 00042 vf.push_back(f); 00043 } 00044 00045 // Add this vector of floatean values into the "global" stack 00046 xmli::Stack<std::vector<float> >::Instance().push(vf); 00047 } 00048
1.3.9.1