Beispiel #1
0
 inline
 std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, date& d)
 {
   std::istream_iterator<std::basic_string<charT>, charT> beg(is), eos;
   d = from_stream(beg, eos);
   return is;
 }
Beispiel #2
0
bool Buffer::_read(unsigned count) {
  // If we have enough characters in the queue; just return
  if (_queue.size() >= count) return true;

  std::istreambuf_iterator<char> end;
  unsigned needed = count - _queue.size();
  for (; needed > 0; --needed) {
    std::istreambuf_iterator<char> beg(*_stream);
    if (beg == end) {
      // Hit the end-of-file
      return false;
    }

    auto ch = utf8::next(beg, end);

    // Normalize line ending; only return 'Line Feed' to signal EOL
    if (ch == 0x0d) {  // Carriage Return
      ch = 0x0a;  // Interpret us as a Line Feed
      // Check if the next char is 'Carriage Return' and if so, drop it
      if (beg != end) {
        auto ch2 = utf8::next(beg, end);
        if (ch2 != 0x0a) {  // CR + LF or just CR
          _stream->seekg(-1, std::ios::cur);
        }
      }
    }

    _queue.push_back(ch);
  }

  return true;
}
Beispiel #3
0
void Dictionary::loadDicts(){

    // Создаём вектор файлов словарей для каждой буквы
    std::vector< std::string > files;
    char buf[3];

    for(int i = 1; i < 34; ++i){
        std::string str="dict//";
        itoa( i, buf, 10 );
        str.append( buf );
        files.push_back( str );
    }

    // Добавляем содержимое каждого из файлов в dictionary
    std::vector< std::string >::iterator fileNameIter = files.begin();
    for(; fileNameIter != files.end(); ++fileNameIter){

        //хранит список слов начинающихся на одну букву
        std::vector<std::string> singleDict;

        //читаем и копируем слова из файла
        std::ifstream file((*fileNameIter).c_str());
        std::istream_iterator<std::string> beg(file), end;
        std::copy(beg, end, std::back_inserter(singleDict));

        //Добавляем получившийся словарь на одну букву - в общий словарь
        std::vector<std::string>::iterator firstWord = singleDict.begin();
        char firstLetter = (*firstWord)[0];
        dictionary.insert (std::pair<char,std::vector<std::string> >(firstLetter,singleDict));
        singleDict.clear();
    }
}
void RockPaperScissors::setPosition(int lineNumber, const string& line, int playerNumber, Status& currentStatus) {
	Piece p;
	//split string by white spaces
	istringstream buf(line);
	istream_iterator<string> beg(buf), end;
	vector<string> tokens(beg, end);

	if (isPositionFormatCorrect(tokens)) {
		p = getPieceFromVector(tokens);
	}
	//illegal line
	else {
		cout << "Player " << playerNumber << " has a faulty format in line " << lineNumber + 1 << " : " << endl \
			<< line << endl \
			<< "Correct format is:" << endl \
			<< "<PIECE_CHAR> <X> <Y> or J <X> <Y> <PIECE_CHAR>" << endl;
		currentStatus.setStatus(playerNumber, PossibleStatus::input_File_Error, lineNumber + 1, line);
		return;
	}

	int row = stoi(tokens[1]) - 1;
	int column = stoi(tokens[2]) - 1;

	if (!placePiece(playerNumber, p, row, column, 0, 0, lineNumber, line, currentStatus))
		return;
}
Beispiel #5
0
 std::vector<std::string> extensions() const
 {
   std::string ext = info(CL_PLATFORM_EXTENSIONS);
   std::istringstream buf(ext);
   std::istream_iterator<std::string> beg(buf), end;
   return std::vector<std::string>(beg, end);
 }
Beispiel #6
0
void InstructionStack::splitWhitespace(std::vector<std::string> & tokens, std::string const & line)
{
	std::istringstream buf(line);
	std::istream_iterator<std::string> beg(buf);
	std::istream_iterator<std::string> end;
	tokens.assign(beg, end);
}
void cBaseUDP_Server::Run(){

	I_ReceiveData();
#ifdef TESTNETWORK
	static unsigned int lastsendtime = 0;
	static int d = 0;
	if(d==0){// calculate a new ping wait period
		d = rand()%PINGRANGE;// get random number [0,PINGRANGE]
		d -=PINGRANGE/2;// bring the delta into [-PINGRANGE/2, PINGRANGE/2] range
		d = (TARGETPING*2)+d;// combine the base ping and the delta ping

	}

	if(Network::GetTime() - lastsendtime < d) return; // if enough time has not passed, then skip this run
	lastsendtime = Network::GetTime();
	d=0;// calculate a new ping wait interval
#endif
	Threading::Parallel_For(0, MaxNumOfPeers, 48, [this] (unsigned int beg, unsigned int end) { UDP_Engine::Run(beg, end); });

	static unsigned int LastAutenticationCheck =Network::GetTime();

	if(Network::GetTime() - LastAutenticationCheck > AUTHENTICATIONCHECK){// do not check the un authenticated users repeatedly each loop, just check in every so often
		unsigned int time = LastAutenticationCheck= Network::GetTime();
		std::set<cPeer*>::iterator beg(I_UnAuthenticatedPeers_.begin());
		while(beg!= I_UnAuthenticatedPeers_.end()){
			if( time - (*beg)->ConnectTime > AUTHENTICATIONCHECKTIMEOUT){// disconnect the user, he has not authenticated himself. I dont want people hanging around using up resources
				cPeer* p = *beg;// need a copy
				beg = I_UnAuthenticatedPeers_.erase(beg);// this will move us to the next peer
				DisconnectPeerNow(p);// the peer has not authenticated himself, disconnect. A copy of the pointer, instead of *beg was passed because the disconnectpeernow calls the virtual disconnect(cPeer* peer) function so it would screw up my loop by removing the user in it			
			} else ++beg;
		}
	}
}
Beispiel #8
0
 string loadFile2Str(const char * const filepath)
 {
     ifstream in(filepath);
     istreambuf_iterator<char> beg(in), end;
     string str(beg, end);
     in.close();
     return str;
 }
Beispiel #9
0
 void updateTimeLimits(const CommonTime& bb, const CommonTime& ee)
 {
    CommonTime beg(bb), end(ee);
    beg.setTimeSystem(timeSystem);
    end.setTimeSystem(timeSystem);
    if(beg < initialTime) initialTime = beg;
    if(end > finalTime) finalTime = end;
 }
Beispiel #10
0
void SplitTest2()
{
	std::string s = "Hello my baby!";
	std::istringstream iss(s);
	std::istream_iterator<std::string> beg(iss), end;
	std::vector<std::string> words(beg, end);
	for(auto & w : words)
		std::cout << w << std::endl;
}
Beispiel #11
0
 inline 
 std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, date& d)
 {
   std::istream_iterator<std::basic_string<charT>, charT> beg(is), eos;
   
   typedef boost::date_time::all_date_names_put<greg_facet_config, charT> facet_def;
   d = from_stream(beg, eos);
   return is;
 }
void save(Archive & ar, 
          const posix_time::time_period& tp, 
          unsigned int /*version*/)
{
  posix_time::ptime beg(tp.begin().date(), tp.begin().time_of_day());
  posix_time::ptime end(tp.end().date(), tp.end().time_of_day());
  ar & make_nvp("time_period_begin", beg);
  ar & make_nvp("time_period_end", end);
}
Beispiel #13
0
//Iterates through the whole program looking for variable declarations
//Supports ONLY int and double declarations
//NOTE: This DELETES all declarations (converts the line to ""), since they are added in appropriate locations later
void processVariables()
{
	const std::string intStr = "int";
	const std::string doubleStr = "double";

	for (int i = 0; i < input.size(); i++)
	{
		std::string curStr = input.at(i);
		std::string typeStr;
		int offset;

		//determine what is being declared
		if (curStr.substr(0, 3).compare("int") == 0) //integer declaration
		{
			if (curStr.substr(0, 8).compare("int main") == 0) //special case for this int!
			{
				continue;
			}
			typeStr = intStr;
			offset = 4;
		}
		else if (curStr.substr(0, 6).compare("double") == 0) //double declaration
		{
			typeStr = doubleStr;
			offset = 7;
		}
		else //TODO could include more primitives here
		{
			continue; //not a var declaration
		}

		//everything below here applies only to var declarations, since we continued above
		if (curStr.find(",") == std::string::npos) //if no commas
		{
			std::string varName = curStr.substr(offset, (curStr.length() - offset - 1)); //-1 to leave semicolon off
			varsAndTypes[varName] = typeStr;
			varsAndLines[varName] = i;
		}
		else //multiple vars/line
		{
			std::istringstream buf(curStr);
			std::istream_iterator<std::string> beg(buf), end;
			std::vector<std::string> tokens(beg, end);

			for (int j = 1; j < tokens.size(); j++)
			{
				std::string varName = tokens.at(j).substr(0, tokens.at(j).length() - 1); //leave off the comma or semicolon
				varsAndTypes[varName] = typeStr;
				varsAndLines[varName] = i;
			}
		}

		//now that the value is preserved in the hashmap, remove the declaration
		input.at(i) = "";
	}
}
Beispiel #14
0
glm::vec4 splitVec4(std::string toSplit){
	glm::vec4 out;
	std::istringstream buf(toSplit);
	std::istream_iterator<std::string> beg(buf), end;
	int i = 0;
	for (; beg != end; beg++){
		out[i++] = (float)std::stoi(*beg);
	}
	return out;
}
Beispiel #15
0
const std::string AngleRange::toCSV() const {

    std::ostringstream os;

    os << std::setprecision(1) << std::fixed;

    os << beg() << ";" << end() << ";" << min() << ";" << max();

    return os.str();
}
inline void load_construct_data(Archive & ar, 
                                boost::posix_time::time_period* tp, 
                                const unsigned int /*file_version*/)
{
  posix_time::time_duration td(1,0,0);
  gregorian::date d(gregorian::not_a_date_time);
  posix_time::ptime beg(d,td);
  posix_time::ptime end(d,td);
  new(tp) boost::posix_time::time_period(beg,end);
}
int main()
{
    std::string s = "Hello,How,Are,You,Today";
    std::istringstream buf(s);
    buf.imbue(std::locale(buf.getloc(), new comma_ws));
    std::istream_iterator<std::string> beg(buf), end;
    std::vector<std::string> v(beg, end);
    copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."));
    std::cout << '\n';
}
Beispiel #18
0
const std::string AngleRange::str(const char* name) const {

    std::ostringstream os;

    os << std::setprecision(1) << std::fixed;

    os << name << " " << beg() << " / " << end() << " / ";

    os << min() << " / " << max() << " / " << range();

    return os.str();
}
void load(Archive & ar, 
          boost::posix_time::time_period & tp, 
          unsigned int /*version*/)
{
  posix_time::time_duration td(1,0,0);
  gregorian::date d(gregorian::not_a_date_time);
  posix_time::ptime beg(d,td);
  posix_time::ptime end(d,td);
  ar & make_nvp("time_period_begin", beg);
  ar & make_nvp("time_period_end", end);
  tp = boost::posix_time::time_period(beg, end);
}
Beispiel #20
0
SeqOfScalar EquelleRuntimeCPU::inputSequenceOfScalar(const String& name)
{
    const String filename = param_.get<String>(name + "_filename");
    std::ifstream is(filename.c_str());
    if (!is) {
        OPM_THROW(std::runtime_error, "Could not find file " << filename);
    }
    std::istream_iterator<Scalar> beg(is);
    std::istream_iterator<Scalar> end;
    SeqOfScalar data(beg, end);
    return data;
}
Beispiel #21
0
std::string RecipeManager::ReadRecipe(const std::string& recipe_name)
{
	std::ifstream ifs(recipe_fullname(recipe_name));
	if(!ifs.is_open())
		return "";

	std::istreambuf_iterator<char> beg(ifs), end;
	std::string strdata(beg, end);
	ifs.close();

	return strdata;
}
Beispiel #22
0
//Returns the size of the tree
std::size_t parse_tree::size(void)
{
	tree_iterator beg(begin());
	tree_iterator finish(end());
	std::size_t count = 1;
	while(beg != finish)
	{
		++count;
		++beg;
	}
	return count;
}
Beispiel #23
0
void CMTimeMachine::add_cycle_at(unsigned short n,const CMTime& b,const CMTime& e,const CMTime& s,CMTIMEUNIT si)
{
	CMTime beg(b),end(e),start(s);
   long diff = CMTime::Diff(end,beg,incunits,inclength);
	end = beg.Plus(diff*inclength,incunits);
	if (n==0)
	   now = beg;
   else {
		diff = CMTime::Diff(start,beg,incunits,inclength);
		start = beg.Plus(diff*inclength,incunits);
   }
	cycles.AddAt(n,CMTimeCycle(beg,end,start,si));
}
Beispiel #24
0
void CMTimeMachine::AddCycle(const wchar_t* b, const wchar_t* e, const wchar_t* s, int lastmonth, CMTIMEUNIT si)
{
	CMTime beg(b),end(e),start(s);
   int begweek = beg.WeekDay();

	if (CMTime::GetResolution(e)==CM_YEAR) {
		end = CMTime(end.Year(),lastmonth);
		end = end.AtEnd(CM_MONTH);
   	if (incunits==CM_YEAR)
      	end = end.AtBeginning(CM_MONTH);
      else
	      end = end.AtBeginning(incunits,begweek);
   }
	else {
		end = end.AtEnd(CMTime::GetResolution(e));
	   end = end.AtBeginning(incunits,begweek);
   }

	if (CMTime::GetResolution(b)==CM_YEAR) {
   	if (incunits==CM_YEAR)
      	beg = CMTime(beg.Year(),lastmonth).AtBeginning(CM_MONTH);
      else {
			beg = CMTime(lastmonth<12 ? beg.Year()-1 : beg.Year(),lastmonth%12+1);
		   beg = beg.AtBeginning(incunits,begweek);
      }
   }
   else {
		beg = beg.AtBeginning(CMTime::GetResolution(b));
	   beg = beg.AtBeginning(incunits,begweek);
   }

	if (s!=0) {
		if (CMTime::GetResolution(s)==CM_YEAR) {
   		if (incunits==CM_YEAR)
      		start = CMTime(start.Year(),lastmonth).AtBeginning(CM_MONTH);
	      else {
				start = CMTime(lastmonth<12 ? start.Year()-1 : start.Year(),lastmonth%12+1);
			   start = start.AtBeginning(incunits,begweek);
	      }
   	}
	   else {
			start = start.AtBeginning(CMTime::GetResolution(s));
	   	start = start.AtBeginning(incunits,begweek);
	   }
   }
   else
   	start = beg;

   AddCycle(beg,end,start,si);
}
Beispiel #25
0
   void draw(drawer_type & drawer, contour_2f const & cnt, bool draw_vertices)
   {
      contour_circulator beg(cnt), it = beg;

      do
      {
         point_2f pt = *it;
         if (draw_vertices)
            drawer.draw_point(pt, 3);
         ++it;
         drawer.draw_line(segment_2f(pt, *it));
      }
      while (it != beg);
   }
Beispiel #26
0
	__forceinline char * stack_allocator::allocate(int size_bytes){
			//round size_bytes up to multiple of 4
			if(size_bytes==0){
			    perror("Allocating 0 bytes?\n");fflush(stdout);
			    abort();
			};
			int size = (size_bytes+3)>>2;
			if(cap_free()<size+overhead){//check if it fits
				throw std::bad_alloc();
			};
			int * P = beg()-size;
			block_size(P) = size;
			mark_block_used(P);
			_beg = P-overhead;
			return (char*)P;
	};
Beispiel #27
0
int main(int argc, char const *argv[])
{
	StrVec svec1;
	std::ifstream ifs("in.txt");
	std::istream_iterator<std::string> beg(ifs), end;
	std::vector<std::string> src(beg, end);
	for (auto& s : src)
	{
		svec1.push_back(s);
	}
	svec1.resize(10, "illidan");
	StrVec svec = { "a", "b", "c", "d", "e" };
	display(svec);
	std::cout << svec.size() << std::endl;
	return 0;
}
Beispiel #28
0
void Compiler::analyze(string filename)
{
	strcpy(SourceFileName, filename.c_str());
	ifstream in(filename, ios::in);
	if (!in)
	{
		cout << "can't not opend " << filename << endl;
		exit(0);
	}
	istreambuf_iterator<char> beg(in), end;
	string input(beg, end);
	in.close();

	IR::analyze(input);
	//IR::printResult();
}
Beispiel #29
0
//does a depth first traversal and passes an inorder representation of the tree to os
std::ostream& operator<<(std::ostream & os, const parse_tree & ptree)
{
	tree_iterator beg(ptree.begin());
	tree_iterator finish(ptree.end());
	std::stringstream ss;
	while(beg != finish)
	{
		if(beg==finish)
			break;
		(*beg)->to_string(ss);
		os << ss.str();
		ss.str("");
		++beg;
	}
	return os;
}
Beispiel #30
0
Robot wbot::generateRobot(){
	Robot robot{};

	std::ifstream infile("wbotJoints.txt");
	std::string str;
	while (std::getline(infile, str)){

		std::istringstream buf(str);
		std::istream_iterator<std::string> beg(buf), end;

		std::vector<std::string> tokens(beg, end); // done!

		robot.addJoint(tokens[0], Joint(std::stoi(tokens[1]), 512, 100, 1024, 0));
	}

	return robot;
}