shared_ptr<LobKo::TaskHolder> LobKo::TaskHolderBuilder::build(ifstream& file_in) {
    shared_ptr<TaskHolder> spBuildThis(new TaskHolder);

    std::string str;

    file_in.clear();
    bool flag = true;
    do {
        std::getline(file_in, str);
        if ( file_in.bad() || file_in.fail() ) {
            break;
        } else if ( file_in.eof() ) {
            flag = false;
        }
        std::istringstream istream(str);

        string res;
        string filepath;

        istream >> res >> filepath;
        if ( res.size() && res[0] != '#' ) {
            if ( filepath.size() ) {
                spBuildThis->addTask(Task(res, filepath));
            }
        }
    } while (flag);


    return spBuildThis;
}
//-----------------------------------------------------------------------------
// initMovies(ifstream& infile) const
// Initialize movie list
//-----------------------------------------------------------------------------
void MovieStore::initMovies(ifstream& infile)
{
    while (true)
    {
        if (infile.eof() || infile.bad())
        {
            break;
        }

        m_movieManager.add(infile);
    }
}
Example #3
0
int HTTPRequest::copyFromFile(ifstream& ifs, size_t contentLength)
{
	char* fileBuf = new char[contentLength];
	memset(fileBuf, '\0', contentLength);

	if (ifs.good())
	{
		ifs.read(fileBuf, contentLength);
	}
	m_requestBody.append(fileBuf, contentLength);

	if (ifs.bad())
		return -1;

	return 0;
}
//-----------------------------------------------------------------------------
// initAccounts(ifstream& infile) const
// Initialize customer list
//-----------------------------------------------------------------------------
void MovieStore::initAccounts(ifstream& infile)
{
    while (true)
    {
        Customer* pCust = new Customer();

        if (infile.eof() || infile.bad() || !pCust->setData(infile))
        {
            delete pCust;
            break;
        }

        m_customers.insert(pCust);
        m_customersHash.insert(pCust);
    }
}
Example #5
0
uint Genome::OpenStream(string name, ifstream & stream)
{
    stream.open((P->genomeDir+ "/" +name).c_str(), ios::binary); 
    if (!stream.good()) {
        ostringstream errOut;
        errOut << "EXITING because of FATAL ERROR: could not open genome file "<< P->genomeDir << "/" << name <<"\n" << endl;
        errOut << "SOLUTION: check that the path to genome files, specified in --genomeDir is correct and the files are present, and have user read permsissions\n" <<flush;     
        exitWithError(errOut.str(),std::cerr, P->inOut->logMain, EXIT_CODE_GENOME_FILES, *P);
    };

    uint size = 0;

    P->inOut->logMain << "checking " << name << " size";
    stream.seekg (0, ios::end);
    size=(uint) stream.tellg();
    stream.clear();        
    stream.seekg (0, ios::beg);
    P->inOut->logMain << "file size: "<< size <<" bytes; state: good=" <<stream.good()\
            <<" eof="<<stream.eof()<<" fail="<<stream.fail()<<" bad="<<stream.bad()<<"\n"<<flush;

    return size;
}
Example #6
0
int GetInputInt(ifstream& file)
{
	string temp = "";
	int number = 0;
	//get the line from the text file. (Just like with cin)
	getline(file, temp);

	//test if the file is at the end
	if (file.eof())
	{
		throw IOException(ERROR_EOF, DEFAULT);
	}
	//test if input is bad, or failed
	else if (file.bad() || file.fail())
	{
		throw IOException(ERROR_FILE_FAIL, DEFAULT);
	}
	//convert the validated temp string to integer
	//store as int
	number = ValidateInt(temp);
	return number;
} // End GetValidInputInt()
Example #7
0
double GetInputDouble(ifstream& file)
{
	string temp = "";
	double number = 0;
	//get the line from the text file. (Just like with cin)
	getline(file, temp);

	//test if the file is at the end
	if (file.eof())
	{
		throw IOException(ERROR_EOF, DEFAULT);
		return 0.0;
	}
	//test if input is bad, or failed
	else if (file.bad() || file.fail())
	{
		throw IOException(ERROR_FILE_FAIL, DEFAULT);
	}

	number = ValidateDouble(temp);
	return number;
} // End GetValidInputDouble()
Example #8
0
bool fill_bucket(vector<pair<int, string>> &myVec, int &num_lines, ifstream &myfile) {
	int i = myVec.size();
	int counter = 0;
	// seek to num_lines read
	goto_line(myfile, num_lines + 1);
	string str;
	while (getline(myfile, str)) {
		myVec.push_back(split_str(str));
		counter++;
		num_lines++;
		if (counter == i) {
			break;
		}
	}
	getline(myfile, str);
	// already at the end of file
	if (myfile.bad() && counter == 0)
		return false;
	else
		return true;
	myfile.close();
}
Example #9
0
int StreamToValidInt(ifstream& file)
{
	string temp = "";
	int number = 0;
	//get the line from the text file. (Just like with cin)
	getline(file, temp);

	//test if the file is at the end
	if (file.eof())
	{
		string error = EOF_MSG;
		throw FileException(error, 0);
	}
	//test if input is bad, or failed
	else if (file.bad() || file.fail())
	{
		string error = FILE_FAIL_MSG;
		throw FileException(error, 0);
	}
	//convert the validated temp string to integer
	//store as int
	number = StringToValidInt(temp);
	return number;
} // End StreamToValidInt()
Example #10
0
double StreamToValidDouble(ifstream& file)
{
	string temp = "";
	double number = 0;
	//get the line from the text file. (Just like with cin)
	getline(file, temp);

	//test if the file is at the end
	if (file.eof())
	{
		string error = EOF_MSG;
		throw FileException(error, 0);
		return 0.0;
	}
	//test if input is bad, or failed
	else if (file.bad() || file.fail())
	{
		string error = FILE_FAIL_MSG;
		throw FileException(error, 0);
	}

	number = StringToValidDouble(temp);
	return number;
} // End StreamToValidDouble()
Example #11
0
void Shader::ShaderCode::load(ifstream &ShaderStream)
{
	string Line = "";
	if (ShaderStream.is_open())
	{
		while (getline(ShaderStream, Line))
		{
			if (ShaderStream.eof() || ShaderStream.bad())
				break;
			_code += Line + "\n";
		}
	}
	else
	{
		LOG << string(_path) + " wasn't open :/\n";
		return;
	}

	//Analyze Code
	try {
		//get Structures
		smatch _structs, _vars;

		regex structRegex = regex("struct .*?\\n?\\{\\n(.*?;\\n)*\\};");
		auto StructBegin = std::sregex_iterator(_code.begin(), _code.end(), structRegex);

		unsigned int _counter(0);
		for (auto i = StructBegin; i != std::sregex_iterator(); i++) {
			std::string temp = (*i).str();
			vector<string> structVar = vector<string>();
			regex_search(temp, _vars, regex("struct .*?\\n\\{\\n"));
			temp = _vars[0].str();
			structVar.push_back(temp.substr(7, temp.size() - 10));//adds name
			temp = (*i).str();

			regex structVarRegex = regex("\\t.*? .*?;\\n");
			auto StructVarBegin = std::sregex_iterator(temp.begin(), temp.end(), structVarRegex);

			for (std::sregex_iterator i = StructVarBegin; i != std::sregex_iterator(); ++i) {
				std::string match_str = (*i).str();
				structVar.push_back(match_str.substr(1, match_str.size() - 3)); //write the variables
			}
			structVariables.push_back(structVar);
			_counter++;
		}
		LOG << string(_path) + " contains " + to_string(_counter) + " Structures\n";

		//read uniforms
		_counter = 0;
		regex structVarRegex = regex("uniform .*? .*?;\\n");
		auto UniformsBegin = std::sregex_iterator(_code.begin(), _code.end(), structVarRegex);
		for (auto i = UniformsBegin; i != std::sregex_iterator(); i++) {
			std::string match_str = (*i).str();
			addUniform(match_str.substr(match_str.find_first_of(' ') + 1, match_str.size() - 3 - match_str.find_first_of(' ')));
			_counter++;
		}
		LOG << string(_path) + " contains " + to_string(_counter) + " Uniforms\n";
	}
	catch (regex_error &e)
	{
		LOG << string(e.what()) + "\n";
		LOG << "Could not Resolve Uniforms in Shader \n";
	}

}
Example #12
0
int getBlockAE(ifstream & inpF, ofstream & outRp, double G, double C,
		double fSize, UINT & totRpNum) {
	if (inpF.bad())
		return -1;

	vector<dataVect_T> X;
	UINT maxF = 0;
	int lineNum = 0;
	double memUsed = 0;
	while (1) {
		string line;
		if (getline(inpF, line)) {
			char * lineC = new char[line.length() + 1];
			strcpy(lineC, line.c_str());
			char * labelC = strtok(lineC, " \t\n");
			if (labelC == NULL) {
				cout << "Error in input file read\n";
				return -1;
			}
			char *endPtr, *idx, *val;
			char label = (char) strtol(labelC, &endPtr, 10);
			queue<feat_T> tempQ;
			UINT numFeats = 0, fNum = 0;
			double fVal = 0;
			if (endPtr == labelC || *endPtr != '\0') {
				cout << "Error in input file read\n";
				return -1;
			}

			while (1) {
				idx = strtok(NULL, ":");
				val = strtok(NULL, " \t");

				if (val == NULL)
					break;

				fNum = (UINT) strtoll(idx, &endPtr, 10);
				if (endPtr == idx || *endPtr != '\0') {
					cout << "Error in input file read\n";
					return -1;
				}

				fVal = strtod(val, &endPtr);
				if (endPtr == val || (*endPtr != '\0' && !isspace(*endPtr))) {
					cout << "Error in input file read\n";
					return -1;
				}
				feat_T tempF;
				tempF.fNum = fNum;
				tempF.fVal = fVal;
				tempQ.push(tempF);
				numFeats++;
				maxF = max(maxF, fNum);
			}
			delete[] lineC;

			double memReq = (double) sizeof(dataVect_T) + sizeof(feat_T) * numFeats;
			if (memUsed + memReq >= G) {
				if (numFeats > 0) {
					for (UINT ind = 0; ind < numFeats; ind++)
						tempQ.pop();
					queue<feat_T> empty;
					swap(tempQ, empty);
				}
				break;
			}
			dataVect_T Xtemp;
			Xtemp.numFeats = numFeats;
			Xtemp.label = label;
			if (numFeats > 0) {
				Xtemp.F = new feat_T[numFeats];
				for (UINT ind = 0; ind < numFeats; ind++) {
					Xtemp.F[ind] = tempQ.front();
					tempQ.pop();
				}
				queue<feat_T> empty;
				swap(tempQ, empty);
			} else
				Xtemp.F = NULL;

			X.push_back(Xtemp);
			memUsed += memReq;
		} else {
			break;
		}
		lineNum++;
	}
	maxF++;
	double *w = new double[maxF];
	// solve SVM for selected vectors
	svmSolver(X, w, C, maxF);

	// calc number of rp vects.
	double numRp = G / ((double) sizeof(feat_T) * maxF);
	numRp = numRp * G / fSize;
	if (numRp < 1) {
		cerr << "Not enough memory to store representative set.\n";
		exit(1);
	}
	// comp AE vects
	onePassDRS(X, w, 1, numRp, outRp, totRpNum);

	for (UINT ind = 0; ind < X.size(); ind++) {
		if (X[ind].F != NULL)
			delete[] X[ind].F;
	}
	vector<dataVect_T>().swap(X);
	delete[] w;
	if (inpF.eof())
		return -1;

	return 0;
}
Example #13
0
void read_ini_file(ifstream &argfile)
try
{
	string section;
	do
	{
		argfile>>section;
	}
	while(section!="[bmp2c]" && !argfile.eof());
	if(argfile.eof())
	{
		stringstream msg;
		msg<<"ini file:failed to find the [bmp2c] section"<<endl;
		throw  error_msg(msg.str());
	}
	
	argfile.ignore(numeric_limits<streamsize>::max(),'=');
	argfile>>min_version;
	if(argfile.bad()||argfile.fail())
	{
		stringstream msg;
		msg<<"ini file:failed to read version info."<<endl;
		throw  error_msg(msg.str());
	}
   if(min_version>BMP2C_VERSION)
	{
	   stringstream msg;
	   msg<<"executable version too old:"<<endl;
	   msg<<"The version of this executable is: v";
	   msg<<BMP2C_VERSION<<endl;
	   msg<<"The specified ini files requires at least v";
	   msg<<min_version<<endl;
	   msg<<"Please download a compatible executable or adapt your ini file";
	   throw error_msg(msg.str());
	}
	if(min_version<BMP2C_MIN_INI_VERSION)
	{
	   stringstream msg;
	   msg<<"ini file version too old:"<<endl;
	   msg<<"This executable is backward compatible with ini files version from v";
	   msg<<BMP2C_MIN_INI_VERSION<<endl;
	   msg<<"Please download a compatible executable or adapt your ini file";
	   throw error_msg(msg.str());
	}
	
	argfile.ignore(numeric_limits<streamsize>::max(),'=');
	getline( argfile, x_decl );
	argfile.ignore(numeric_limits<streamsize>::max(),'=');
	getline( argfile, x_decl_postfix );
	argfile.ignore(numeric_limits<streamsize>::max(),'=');
	getline( argfile, y_decl );
	argfile.ignore(numeric_limits<streamsize>::max(),'=');
	getline( argfile, y_decl_postfix );
	argfile.ignore(numeric_limits<streamsize>::max(),'=');
	getline( argfile, array_decl );
	argfile.ignore(numeric_limits<streamsize>::max(),'=');
	argfile>>data_size;	
	argfile.ignore(numeric_limits<streamsize>::max(),'=');
	getline( argfile, data_map );
	argfile.ignore(numeric_limits<streamsize>::max(),'=');
	getline( argfile, preview_map );
	argfile.ignore(numeric_limits<streamsize>::max(),'=');
	argfile>>generate_preview_bmp;
	argfile.ignore(numeric_limits<streamsize>::max(),'=');
	argfile>>pause;
	if(min_version>0)
	{
	   argfile.ignore(numeric_limits<streamsize>::max(),'=');
	   argfile>>src_endl_param;
	}
	if(argfile.bad()||argfile.fail())