Beispiel #1
0
  Scheduler::Scheduler(size_t maxNrStudents, const string& filename):
      maxNrStudents_(maxNrStudents)
  {
    typedef boost::tokenizer<boost::escaped_list_separator<char> > Tokenizer;

    // open file
    ifstream is(filename.c_str());
    if (!is) {
      cerr << "Scheduler: could not open file " << filename << endl;
      throw runtime_error("Scheduler: could not open file " + filename);
    }

    string line; // buffer

    // process first line with faculty
    if (getline(is, line, '\r')) {
      Tokenizer tok(line);
      Tokenizer::iterator it = tok.begin();
      for (++it; it != tok.end(); ++it)
        addFaculty(*it);
    }

    // for all remaining lines
    size_t count = 0;
    while (getline(is, line, '\r')) {
      if (count++ > 100) throw runtime_error("reached 100 lines, exiting");
      Tokenizer tok(line);
      Tokenizer::iterator it = tok.begin();
      addSlot(*it++); // add slot
      // add availability
      for (; it != tok.end(); ++it)
        available_ += (it->empty()) ? "0 " : "1 ";
      available_ += '\n';
    }
  } // constructor
Beispiel #2
0
void Terminal::Parser::parseSetAttributes(const std::string& str)
{
	using Tokenizer = boost::tokenizer<boost::char_separator<char>>;

	boost::char_separator<char> sep(";");
	Tokenizer tok(str, sep);

	for(Tokenizer::iterator it = tok.begin(); it != tok.end(); ++it)
	{
		errno = 0;
		char* endptr = const_cast<char*>(it->c_str());
		int code = strtoul(it->c_str(), &endptr, 10);

		if(errno != 0 || *endptr != 0)
		{
			// Error in specification, break out of here
			m_fgColor = -1;
			m_bgColor = -1;
			return;
		}

		if(code == 0)
		{
			m_fgColor = -1;
			m_bgColor = -1;
		}
		else if(code >= 30 && code <= 37)
			m_fgColor = code - 30;
		else if(code >= 40 && code <= 47)
			m_bgColor = code - 40;
	}
}
Beispiel #3
0
void Stock::load_stock_csv(std::string filename) 
{
    std::vector< std::vector<double> > csv_values;
    fstream file(filename.c_str(), ios::in);

    // Load in values.
    if (file) {
        typedef boost::tokenizer< boost::char_separator<char> > Tokenizer;
        boost::char_separator<char> sep(",");
        std::string line;

        // Skip one line for header.
        getline(file, line);

        while (getline(file, line)) {
            Tokenizer info(line, sep);   // tokenize the line of data
            std::vector<double> values;

            for (Tokenizer::iterator it = info.begin(); it != info.end(); ++it){
                if (it == info.begin()) 
                    this->date.push_back(*it);
                else
                    values.push_back(strtod(it->c_str(), 0));
            }

            // store array of values
            csv_values.push_back(values);
        }
    }
    else {
        cerr << "Error: Unable to open file " << filename << endl;
    }

    // display results
    cout.precision(2);
    cout.setf(ios::fixed,ios::floatfield);

    // Load values into stock arrays. 
    for (size_t i = 0; i < csv_values.size(); i++) {
        this->open(i)   = csv_values[i][0];
        this->high(i)   = csv_values[i][1];
        this->low(i)    = csv_values[i][2];
        this->close(i)  = csv_values[i][3];
        this->volume(i) = csv_values[i][4];
    }
}
Beispiel #4
0
double readFirstDoubleFromIterator(tokenizer::iterator & it) {
    double d = atof(it->c_str());
    it++;
    return d;

}