`read csv` C++ Examples

12 C++ code examples are found related to "read csv". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: parser_test.cpp    From csv-parser with MIT License 6 votes vote down vote up
CSV read_all(CsvParser p) {
  CSV csv;
  for (auto& row : p) {
    std::vector<std::string> r;
    for (auto& field : row) {
      r.push_back(field);
    }
    csv.push_back(r);
  }
  return csv;
} 
Example 2
Source File: CsvOptionsReader.cpp    From acts with Mozilla Public License 2.0 5 votes vote down vote up
FW::CsvPlanarClusterReader::Config
FW::Options::readCsvPlanarClusterReaderConfig(const Variables& vm) {
  FW::CsvPlanarClusterReader::Config cfg;
  if (not vm["input-dir"].empty()) {
    cfg.inputDir = vm["input-dir"].as<std::string>();
  }
  return cfg;
} 
Example 3
Source File: CsvOptionsWriter.cpp    From acts with Mozilla Public License 2.0 5 votes vote down vote up
FW::CsvPlanarClusterWriter::Config
FW::Options::readCsvPlanarClusterWriterConfig(
    const FW::Options::Variables& vm) {
  FW::CsvPlanarClusterWriter::Config cfg;
  if (not vm["output-dir"].empty()) {
    cfg.outputDir = vm["output-dir"].as<std::string>();
  }
  cfg.outputPrecision = vm["csv-output-precision"].as<size_t>();
  return cfg;
} 
Example 4
Source File: CsvOptionsWriter.cpp    From acts with Mozilla Public License 2.0 5 votes vote down vote up
FW::CsvTrackingGeometryWriter::Config
FW::Options::readCsvTrackingGeometryWriterConfig(
    const FW::Options::Variables& vm) {
  FW::CsvTrackingGeometryWriter::Config cfg;
  if (not vm["output-dir"].empty()) {
    cfg.outputDir = vm["output-dir"].as<std::string>();
  }
  cfg.outputPrecision = vm["csv-output-precision"].as<size_t>();
  cfg.writePerEvent = vm.count("csv-tg-perevent");
  return cfg;
} 
Example 5
Source File: CsvOptionsWriter.cpp    From acts with Mozilla Public License 2.0 5 votes vote down vote up
FW::CsvParticleWriter::Config FW::Options::readCsvParticleWriterConfig(
    const FW::Options::Variables& vm) {
  FW::CsvParticleWriter::Config cfg;
  if (not vm["output-dir"].empty()) {
    cfg.outputDir = vm["output-dir"].as<std::string>();
  }
  cfg.outputPrecision = vm["csv-output-precision"].as<size_t>();
  return cfg;
} 
Example 6
Source File: CsvOptionsReader.cpp    From acts with Mozilla Public License 2.0 5 votes vote down vote up
FW::CsvParticleReader::Config FW::Options::readCsvParticleReaderConfig(
    const Variables& vm) {
  FW::CsvParticleReader::Config cfg;
  if (not vm["input-dir"].empty()) {
    cfg.inputDir = vm["input-dir"].as<std::string>();
  }
  return cfg;
} 
Example 7
Source File: features_cluster.cc    From nifi-minifi-cpp with Apache License 2.0 5 votes vote down vote up
static bool read_csv_file(const char *csv_file_path, vector<csv_entry_t *> &entries)
{
	ifstream csv(csv_file_path, ifstream::in);
	char header[256] = {0,};

	csv.getline(header, sizeof(header));

	string s(header);
	regex re("[\\s,]+");
	sregex_token_iterator it(s.begin(), s.end(), re, -1);
	sregex_token_iterator reg_end;

	for (; it != reg_end; it++) {
		csv_labels.push_back(it->str());
	}

	while (!csv.eof()) {
		char line[256] = {0,};
		csv.getline(line, sizeof(line));
		if (strlen(line) <= 1) {
			continue;
		}

		csv_entry_t *e = make_csv_entry(line);
		if (zero_count(e) == 0) {
			entries.push_back(e);
			number_of_entries++;
		}
		else {
			delete e;
		}
	} 
Example 8
Source File: full_example.cc    From jumanpp with Apache License 2.0 5 votes vote down vote up
Status FullExampleReader::readFullExampleDblCsv(FullyAnnotatedExample *result) {
  finished_ = !csv_.nextLine();
  if (finished_) {
    return Status::Ok();
  }

  auto numwords = csv_.numFields();
  result->data_.reserve(numwords * tio_->fields().size());
  result->lengths_.reserve(numwords);
  for (int i = 0; i < numwords; ++i) {
    auto content = csv_.field(i);

    if (content == "#") {
      for (int j = i + 1; j < numwords; ++j) {
        auto commentPart = csv_.field(j);
        result->comment_.append(commentPart.char_begin(),
                                commentPart.char_end());
        if (j != numwords - 1) {
          result->comment_.push_back(csv_.separator());
        }
      }
      break;
    }

    JPP_RETURN_IF_ERROR(csv2_.initFromMemory(content));
    if (!csv2_.nextLine()) {
      return JPPS_INVALID_PARAMETER << "failed to read word #" << i
                                    << " from the line #" << csv_.lineNumber();
    }
    JPP_RIE_MSG(readSingleExampleFragment(csv2_, result), "data=" << content);
  }

  return Status::Ok();
} 
Example 9
Source File: full_example.cc    From jumanpp with Apache License 2.0 5 votes vote down vote up
Status FullExampleReader::readFullExampleCsv(FullyAnnotatedExample *result) {
  while (csv_.nextLine()) {
    if (csv_.numFields() == 1 &&
        (csv_.field(0).empty() || csv_.field(0) == "EOS")) {
      return Status::Ok();
    }

    auto line = csv_.line();
    if (startsWith(line, "# ")) {
      line.slice(0, line.size() - 1).assignTo(result->comment_);
      continue;
    }

    JPP_RETURN_IF_ERROR(readSingleExampleFragment(csv_, result));
  }
  finished_ = true;
  return Status::Ok();
} 
Example 10
Source File: csvread.cpp    From grit-engine with MIT License 4 votes vote down vote up
void read_csv (std::istream &f, Csv &csv)
{
        bool in_section = false;
        std::string section = "nosection";
        {
                CsvSection &s = csv[section];
                s.section_name = section;
        }

        std::vector<std::string> strs;

        size_t orig_line_counter = 0;
        size_t section_line_counter = 0;

        for (std::string str_ ; std::getline(f,str_) ; ) {

                orig_line_counter++;

                std::string::size_type b, e;

                e = str_.find('\r');
                str_ = str_.substr(0,e);

                e = str_.find('\n');
                str_ = str_.substr(0,e);

                e = str_.find(';');
                str_ = str_.substr(0,e);

                e = str_.find('#');
                str_ = str_.substr(0,e);

                e = str_.find("//");
                str_ = str_.substr(0,e);

                if (str_[0] == '*') continue;

                b = str_.find_first_not_of("\t ");
                e = str_.find_last_not_of("\t ");
                if (b==str_.npos) continue;
                if (e==str_.npos) continue;
                str_ = str_.substr(b,e+1);

                std::string str;
                bool last_was_wspace = false;
                for (size_t i=0 ; i<str_.size() ; i++) {
                        bool wspace = str_[i]==' ' || str_[i]=='\t' || str_[i]==',';
                        if (!wspace) {
                                str += str_[i];
                        } else if (!last_was_wspace) {
                                str += ",";
                        }
                        last_was_wspace = wspace;
                }

                if (str.size()==0) continue;

                if (!in_section && str.find(",")==str.npos) {
                        section = str;
                        in_section = true;
                        section_line_counter = 0;
                        if (csv.find(section)!=csv.end()) {
                            GRIT_EXCEPT("Already seen section \""+section+"\"  in this file");
                        } else {
                                CsvSection &s = csv[section];
                                s.section_name = section;
                        }
                } 
Example 11
Source File: procobj.cpp    From grit-engine with MIT License 4 votes vote down vote up
void read_procobj (Csv &csv, ProcObjData &data)
{
        const CsvSection &s = csv["nosection"];
        for (unsigned i=0 ; i<s.size() ; ++i) {
                const CsvLine &line = s[i];
                APP_ASSERT(line.size()==14);

                ProcObj v;
                v.name = line[0];

                v.object_name = line[1];
                v.spacing = f(line[2]);
                v.mindist = f(line[3]);
                v.minrot = f(line[4]);
                v.maxrot = f(line[5]);
                v.minscl = f(line[6]);
                v.maxscl = f(line[7]);
                v.minsclz = f(line[8]);
                v.maxsclz = f(line[9]);
                v.zoffmin = f(line[10]);
                v.zoffmax = f(line[11]);
                v.align = b(line[12]);;
                v.use_grid = b(line[13]);;

                data.procobjs.push_back(v);
        }
        for (unsigned i=0 ; i<data.procobjs.size() ; ++i) {
                ProcObj &v = data.procobjs[i];
                data[v.name].push_back(&v);
        }
} 
Example 12
Source File: surfinfo.cpp    From grit-engine with MIT License 3 votes vote down vote up
void read_surfinfo (Csv &csv, SurfInfoData &data)
{
        const CsvSection &s = csv["nosection"];
        for (unsigned i=0 ; i<s.size() ; ++i) {
                const CsvLine &line = s[i];
                APP_ASSERT(line.size()>=36);

                SurfInfo v;
                v.name = line[0];

                v.adhesion_group = line[1];
                v.tyre_grip = f(line[2]);;
                v.wet_grip = f(line[3]);;
                v.skidmark = line[4];
                v.friction_effect = line[5];
                v.soft_landing = b(line[6]);
                v.see_through = b(line[7]);
                v.shoot_through = b(line[8]);
                v.sand = b(line[9]);
                v.water = b(line[10]);
                v.shallow_water = b(line[11]);
                v.beach = b(line[12]);
                v.steep_slope = b(line[13]);
                v.glass = b(line[14]);
                v.stairs = b(line[15]);
                v.skateable = b(line[16]);
                v.pavement = b(line[17]);
                v.roughness = dec(line[18]);
                v.flammability = dec(line[19]);
                v.sparks = b(line[20]);
                v.sprint = b(line[21]);
                v.footsteps = b(line[22]);
                v.footdust = b(line[23]);
                v.cardirt = b(line[24]);
                v.carclean = b(line[25]);
                v.w_grass = b(line[26]);
                v.w_gravel = b(line[27]);
                v.w_mud = b(line[28]);
                v.w_dust = b(line[29]);
                v.w_sand = b(line[30]);
                v.w_spray = b(line[31]);
                v.proc_plant = b(line[32]);
                v.proc_obj = b(line[33]);
                v.climbable = b(line[34]);
                v.bullet_fx = line[35];

                data.surfaces.push_back(v);
        }
        for (unsigned i=0 ; i<data.surfaces.size() ; ++i) {
                SurfInfo &v = data.surfaces[i];
                data[v.name] = &v;
        }
}