CubeWorldMods/LocalizationMod/CCSVParse.h

75 lines
2.0 KiB
C
Raw Normal View History

2019-10-18 22:48:55 +08:00
//
// CCSVParse.hpp
// CPPAlgorithm
//
// Created by xujw on 16/2/26.
// Copyright © 2016年 xujw. All rights reserved.
//
#ifndef CCSVParse_h
#define CCSVParse_h
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#include <iostream>
#include <sstream>
/*
*
* toInt
* toFloat
* toDouble
*/
int conToInt(std::string &source);
float conToFloat(std::string &source);
double conToDouble(std::string &source);
//转成std::string
std::string conToString(int s);
std::string conToString(float s);
std::string conToString(double s);
class CCSVParse
{
public:
CCSVParse();
~CCSVParse();
/*
* map形式id名,id不可重复)
* 使id获取一行数据map形式key获取数据
*
* id name age
* 1 20
* 2 19
* 3 18
*/
std::map<std::string, std::map<std::string, std::string> > parseCsvFileToMap(const std::string &fileName,const std::string &separator = ",");
//解析出行列数据 separtor只能是一个字符(比如 , # 等)
std::vector< std::vector<std::string> > parseCsvFile(const std::string &fileName,const std::string &separator = ",");
//打印出解析的数据 测试用
void printParseData() const;
inline size_t getRowNum() const {return _gridData.size();};
inline void useSimpleModel(bool flag){_useSimpleModel = flag;};
/*
str:/
seperator:
*/
std::vector<std::string> splitString(const std::string &str,const std::string &sparator);
std::string loadCsvFile(const std::string &fileName);
private:
//原始数据
std::vector< std::vector<std::string> > _gridData;
bool _useSimpleModel; //是否使用简单模式
};
#endif /* CCSVParse_h */