本文整理汇总了C++中House::getErr方法的典型用法代码示例。如果您正苦于以下问题:C++ House::getErr方法的具体用法?C++ House::getErr怎么用?C++ House::getErr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类House
的用法示例。
在下文中一共展示了House::getErr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fin
void importFiles::importHouses::insertHousesFromFile(vector<string> dirVec) {
string name;
string s_maxSteps, s_rows, s_cols; //value in string
string err, line;
int rows, cols; //values in numbers
char** matrix;
size_t errcnt = 0;
for (vector<string>::const_iterator itr = dirVec.begin(); itr != dirVec.end(); ++itr) { //for each .house file:
ifstream fin((*itr).c_str()); //open file
if (!fin.good()) { // check open() success
err = string("cannot open file");
errcnt++;
houses.insert(std::make_pair(new House(NULL, 0, 0, (*itr).substr((*itr).find_last_of("/\\") + 1)), err));
continue;
}
getline(fin, name);
//fin.ignore(); //skip name line
name = (*itr).substr((*itr).find_last_of("/\\") + 1); //get file name from path
//get parameters from file and check them
getline(fin, s_maxSteps);
if (!is_number(s_maxSteps)) {
err = "line number 2 in house file shall be a positive number, found: " + s_maxSteps;
errcnt++;
houses.insert(std::make_pair(new House(NULL, 0, 0, (*itr).substr((*itr).find_last_of("/\\") + 1)), err));
continue;
}
//maxSteps = atoi(s_maxSteps.c_str()); for future extensions
getline(fin, s_rows);
if (!is_number(s_rows)) {
err = "line number 3 in house file shall be a positive number, found: " + s_rows;
errcnt++;
houses.insert(std::make_pair(new House(NULL, 0, 0, (*itr).substr((*itr).find_last_of("/\\") + 1)), err));
continue;
}
rows = atoi(s_rows.c_str());
getline(fin, s_cols);
if (!is_number(s_cols)) {
err = "line number 4 in house file shall be a positive number, found: " + s_cols;
errcnt++;
houses.insert(std::make_pair(new House(NULL, 0, 0, (*itr).substr((*itr).find_last_of("/\\") + 1)), err));
continue;
}
cols = atoi(s_cols.c_str());
//allocate memory for the house matrix
matrix = (char**) malloc(sizeof(char*) * rows);
for (int i = 0; i < rows; i++) {
matrix[i] = (char*) malloc(sizeof(char) * cols);
getline(fin, line);
int m = MIN((int )line.length(), cols);
line.copy(matrix[i], m, 0);
if (m < cols)
for (int k = m; k < cols; k++)
matrix[i][k] = SPACE;
}
//create the house object adn check validity
House* house = new House(matrix, cols, rows, (*itr).substr((*itr).find_last_of("/\\") + 1));
if (house->getErr() == 0) { //no docking stat
houses.insert(std::make_pair(house, "missing docking station (no D in house)"));
errcnt++;
}
if (house->getErr() > 1) { //too many docking stat
houses.insert(std::make_pair(house, "too many docking stations (more than one D in house)"));
errcnt++;
} else
//1 docking
houses.insert(std::make_pair(house, ""));
}
//if all files are bad
if (errcnt == houses.size()) {
parent.setErr(true);
cout << "All house files in target folder " << parent.getHousePath() << " cannot be opened or are invalid:" << endl;
for (map<House*, string>::const_iterator itr = houses.begin(); itr != houses.end(); ++itr) {
cout << (*itr).first->getName() << ": " << (*itr).second << endl;
}
}
}