int GrandChildProcess::execute() { printStarted(); std::ifstream in; in.open(m_fileName.c_str()); if (!in.good()) { return 0; } FileRecord fr; // TODO: se hace la suma de las valorizaciones aqui o en ChildProcess? double totalSum = 0.0; std::string line; while(getline(in, line)) { //cout << "line:" << line << endl; _vstring parts = Utils::split(line, ';'); if (validLine(parts, fr)) { if (fr.idTipoFondo == m_fundType) { // Process as RF if (m_isFixedRent) { // Check if idTipoInstrumentoFinanciero matches with the // required rentType if (fr.m_rentType == "RF") { double t = fr.cantidad / (1.0 + (fr.tasa / 360.0) * fr.diasAlVencimiento / 100.0); totalSum += t; } } // Process as RV else { // Check if idTipoInstrumentoFinanciero matches with the // required rentType if (fr.m_rentType == "RV") { totalSum += (fr.cantidad * fr.precio); } } } } } in.close(); m_parentPipe.writeString( m_fundType + std::string(",") + (m_isFixedRent ? "RF" : "RV") + std::string(",") + Utils::double2string(totalSum) ); m_parentPipe.closeAll(); printFinished(); return 0; }
void ConfigFile::parseLine(const std::string &line, size_t const lineNo) { if (line.find('=') == line.npos) std::cout << "CFG: Couldn't find separator on line: " << T_to_string(lineNo) << "\n" << std::endl; if (!validLine(line)) std::cout << "CFG: Bad format for line: " << T_to_string(lineNo) << "\n" << std::endl; extractContents(line); }
void IniParser::Load( const std::string &filename) throw (IniParseException){ std::ifstream ifs(filename.c_str()); FileLineType fileLines; if ( !ifs.is_open()) throw IniParseException( filename + " Not found "); for ( std::string line; std::getline(ifs,line);){ fileLines.push_back(line); } ifs.close(); if ( fileLines.size() == 0 ) throw IniParseException( filename + " is empty"); std::string section; int index = 0; for ( FileLineType::iterator itr = fileLines.begin(); itr != fileLines.end(); ++itr ) { index++; std::string curLine = *itr; // Check for the empty line. if( curLine.find_first_not_of(' ') == curLine.npos) continue; // Erase leading white spaces curLine.erase(0, curLine.find_first_not_of("\t ")); if ( curLine[0] == ';' ) continue; if ( curLine[0] == '[' || curLine[curLine.size() - 1] == ']' ) { std::string::size_type left = curLine.find('['); std::string::size_type right = curLine.find(']'); if ( std::string::npos != left && std::string::npos != right){ section = curLine.substr(left + 1, right - 1); std::pair<SectionMapType::iterator, bool> ret; ret = m_sectionMap.insert(std::make_pair(section, KeyValueMapType())); if ( ret.second == false ) throw IniParseException("Duplicate section", index); } else throw IniParseException("Invalid section entry line", index); continue; } if (curLine.find(';') != curLine.npos)// Remove comment if any curLine.erase(curLine.find(';')); if ( validLine( curLine) == false ) throw IniParseException("Invalid line", index); std::string::size_type delPos = curLine.find('='); if ( delPos == std::string::npos) { throw IniParseException("Delimiter is missing ", index); } std::string key = curLine.substr(0, delPos);// Get the key std::string value = curLine.substr(delPos + 1);// Get the value if ( key.empty() || value.empty()) throw IniParseException("Invalid line", index); SectionMapType::iterator found = m_sectionMap.find(section); if ( found == m_sectionMap.end()){ throw IniParseException("Section is missing", index); } std::pair<KeyValueMapType::iterator, bool> ret; ret = found->second.insert(std::make_pair(key,value)); if ( ret.second == false ) throw IniParseException("Duplicate section", index); } }