예제 #1
0
static uint32_t parse_color(std::ifstream &f,
                            std::string *lookahead,
                            uint32_t *color)
{
  uint32_t i;

  *color = UINT_MAX;

  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  f >> *lookahead;




  eat_blankspace(f);
  if (f.peek() != '\n') {
    return 1;
  }

  f >> *lookahead;

  return 0;
}
예제 #2
0
static uint32_t parse_monster_color(std::ifstream &f,
                                    std::string *lookahead,
                                    std::vector<uint32_t> *color)
{
  uint32_t i;
  uint32_t c;

  c = UINT_MAX;

  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  do {
    f >> *lookahead;

    color->push_back(0);

    eat_blankspace(f);
  } while (f.peek() != '\n');

  f >> *lookahead;

  return 0;
}
	void ResourceManager::getI2NBlock(std::ifstream &file, 
										 Resource::Mapping &mapping, 
										 bool files, 
										 const std::string &dir, 
										 const std::string &ext)
	{
		uint id;
		const int bufferSize = 80;
		char buffer[bufferSize];
		while (!file.eof() && file.peek() != '#')
		{
			file >> id;
			if (!(file.peek() == '.'))
				return;
			
			file.ignore(2, ' ');
			
			file.getline(buffer, bufferSize);
			fixLineEnd(buffer);
			
			if (files)
			{
				std::string path = dir + '/' + std::string(buffer) + ext;
				Normalize(path);
				mapping[id] = path;
			}
			else
			{
				mapping[id] = std::string(buffer);
			}
		}
	}
예제 #4
0
void PpmConsumeWhitespaceAndComments(std::ifstream& bFile)
{
    // TODO: Make a little more general / more efficient
    while( bFile.peek() == ' ' )  bFile.get();
    while( bFile.peek() == '\n' ) bFile.get();
    while( bFile.peek() == '#' )  bFile.ignore(4096, '\n');
}
예제 #5
0
	// Skipping lines that start with # (together with empty lines)
	void SkipComments(std::ifstream& stream)
	{
		while (stream.peek() == '#' || stream.peek() == '\n' || stream.peek() == ' ' || stream.peek() == '\r')
		{
			std::string skipped;
			std::getline(stream, skipped);
		}
	}
예제 #6
0
    void read_poly () {
        int number;
        is >> number;

        // poly number is terminated by colon
        is >> std::ws;
        int colon;
        if ((colon = is.get ()) != ':')
            format_error ("PolyFileReader::read_poly: expected colon, got %c", colon);

        // first two vertices
        int initial_vertex;
        is >> initial_vertex;
        // translate POLY vertices into Boundary vertices
        initial_vertex = lookup_vertex (initial_vertex);
        int prev_vertex;
        is >> prev_vertex >> std::ws;
        prev_vertex = lookup_vertex (prev_vertex);

        int initial_edge = b->insert_edge (Boundary::INVALID_EDGE,
                                    initial_vertex, prev_vertex,
                                    Boundary::INVALID_EDGE);

        int prev_edge = initial_edge;
        while (is_digit (is.peek ())) {
            int vertex;
            is >> vertex >> std::ws;
            // translate POLY vertices into Boundary vertices
            vertex = lookup_vertex (vertex);

            int edge = b->insert_edge (prev_edge, prev_vertex,
                                       vertex, Boundary::INVALID_EDGE);
            prev_vertex = vertex;
            prev_edge = edge;
        }

        is >> std::ws;
        int closed_indic = is.peek ();
        if (closed_indic == '<') {
            // extract '<' character
            is.get ();
            // close contour
            b->insert_edge (prev_edge, prev_vertex, initial_vertex, initial_edge);
        } else {
            std::cerr << "WARNING: non-closed contour " << number << ". this is probably not what you want.\n";
        }

        ignore_rest_of_line ();
    }
예제 #7
0
void getNextWord(std::ifstream& inFile, std::string& token, std::string tokenizer, int64_t endOffSet)
{
   token.clear();
   char byte[1];

  while(inFile.good())
  {
     if(inFile.tellg() >= endOffSet)
       return;

     byte[0] =inFile.peek();
     if(byte[0]=='\n' || byte[0] == tokenizer.c_str()[0]){
       inFile.get();
     }else{
       break;
     }
  }


  while(inFile.good()){
   byte[0] = inFile.get();   
   if(byte[0]=='\n' || byte[0] == tokenizer.c_str()[0]){
     return;
   }
    token.append(byte,1);
   }
}
예제 #8
0
Counter::Counter(std::ifstream &file)
{
	numWords = 0;
	numChars = 0;
	numLines = 0;
	numDigits = 0;
	numLower = 0;
	numUpper = 0;
	lineCond = 0;
	lineCond2 = 0;
	std::string word;
	std::string line;

	//Read by word
	while (file.peek() != EOF)
	{
		
		getline(file, line);
		numWords += wordInStr(line);
		numChars += line.length();
		numDigits += numInStr(line);
		numLower += lowerInStr(line);
		numUpper += upperInStr(line);
		if ((numInStr(line) >= 1) && (lowerInStr(line)>=1))
		{
			lineCond += 1;
			if ((numInStr(line) >= 2) && (lowerInStr(line) >= 3))
			{
				lineCond2 += 1;
			}
		}

	}
	file.close();
}
static uint32_t parse_dice(std::ifstream &f,
                           std::string *lookahead,
                           dice *d)
{
  int32_t base;
  uint32_t number, sides;

  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  f >> *lookahead;

  if (sscanf(lookahead->c_str(), "%d+%ud%u", &base, &number, &sides) != 3) {
    return 1;
  }

  d->set(base, number, sides);

  f >> *lookahead;

  return 0;
}
예제 #10
0
std::tuple<unsigned int, unsigned int, int> parse_ppm_header(std::ifstream &fs)
{
    // Check the PPM magic number is valid
    std::array<char, 2> magic_number{ { 0 } };
    fs >> magic_number[0] >> magic_number[1];
    ARM_COMPUTE_ERROR_ON_MSG(magic_number[0] != 'P' || magic_number[1] != '6', "Invalid file type");
    ARM_COMPUTE_UNUSED(magic_number);

    discard_comments_and_spaces(fs);

    unsigned int width = 0;
    fs >> width;

    discard_comments_and_spaces(fs);

    unsigned int height = 0;
    fs >> height;

    discard_comments_and_spaces(fs);

    int max_val = 0;
    fs >> max_val;

    discard_comments(fs);

    ARM_COMPUTE_ERROR_ON_MSG(isspace(fs.peek()) == 0, "Invalid PPM header");
    fs.ignore(1);

    return std::make_tuple(width, height, max_val);
}
예제 #11
0
/**\brief Used by testers.  
 *
 * Not operators because that would conflict
 * with the std:: operators for unsigned ints, alas.
 */
void in(std::ifstream& i, unsigned48_t& res)
{
    /*
     * print "0x........,0x........,0x........"
     */
    union {
       unsigned48_t   seed;
       unsigned short dummy[sizeof(unsigned48_t)/sizeof(unsigned short)];
    } PUN ;

    char             comma = ',';
    unsigned         j=0;

    while( (comma == ',') && 
        (j < sizeof(PUN.dummy)/sizeof(unsigned short)) &&
        (i >>  PUN.dummy[j])
        ) {

            if(i.peek() == ',') i >> comma;
            j++;
    }
    if(j < sizeof(PUN.dummy)/sizeof(unsigned short) ) {
        // This actually sets the badbit:
        i.clear(std::ios::badbit|i.rdstate());
    }
    res = PUN.seed;
}
예제 #12
0
static uint32_t parse_monster_description(std::ifstream &f,
                                          std::string *lookahead,
                                          std::vector<monster_description> *v)
{
  std::string s;
  bool read_name, read_symb, read_color, read_desc,
       read_speed, read_dam, read_hp, read_abil;
  std::string name, desc;
  char symb;
  uint32_t abil;
  std::vector<uint32_t> color;
  dice speed, dam, hp;
  monster_description m;
  int count;

  read_name = read_symb = read_color = read_desc =
              read_speed = read_dam = read_hp = read_abil = false;

  if (*lookahead != "BEGIN") {
    std::cerr << "Discovered at " << __FILE__ << ":" << __LINE__ << "\n"
              << "Parse error in monster description.\n"
              << "Discarding monster." << std::endl;
    do {
      f >> *lookahead;
    } while (*lookahead != "BEGIN" && f.peek() != EOF);
  }
static uint32_t parse_object_description(std::ifstream &f,
                                          std::string *lookahead,
                                          std::vector<object_description> *v)
{
  std::string s;
  bool read_name, read_color, read_desc,
       read_speed, read_dam, read_hp, read_attr,
       read_type, read_dodge, read_def, read_val,
       read_weight;
  std::string name, desc;
  uint32_t color, type;
  dice speed, dam, hp, dodge, def, val, weight, attr;
  object_description m;
  int count;

  read_name = read_color = read_desc =
              read_speed = read_dam = read_hp = read_attr = 
              read_type = read_dodge = read_def = read_val = 
              read_weight = false;

  if (*lookahead != "BEGIN") {
    std::cerr << "Discovered at " << __FILE__ << ":" << __LINE__ << "\n"
              << "Parse error in object description.\n"
              << "Discarding object." << std::endl;
    do {
      f >> *lookahead;
    } while (*lookahead != "BEGIN" && f.peek() != EOF);
  }
예제 #14
0
/**
 * Loads the header of a glove data file.
 * This is both for the samples and for the trained files.
 *
 * The header format is:
 *   -Comments -- # starting<br>
 *   - num gestures<br>
 *   -Gesture names<br>
 *   -Gesture samples<br>
 *
 * @param infile A file that is already open and ready for reading.
 *               After running, this routines will leave the file pointer
 *               immedately after the header.
 */
void GloveGesture::loadFileHeader(std::ifstream& infile)
{
    // skip comments
    while(infile.peek() == '#')
        infile.ignore(4096, '\n');    // Ignore the entire line.

    // Get num gestures
    int num_gestures;
    infile >> num_gestures;          // Get the number of gestures

    infile.ignore(4096, '\n');       // Ignore the rest of the line

    // Get gesture names
    int i;
    char gest_name[512];

    mGestureNames = std::vector<std::string>(num_gestures);
    for(i=0; i<num_gestures; i++)
    {
        infile.getline(gest_name,512);
        mGestureNames[i] = std::string(gest_name);
    }

    mGestureExamples = std::vector<GloveData>(num_gestures);

    // Get gesture data
    for(i=0; i<num_gestures; i++)
        mGestureExamples[i].inputAngles(infile);
}
예제 #15
0
	std::string readLine(std::ifstream &in_)
	{
		std::string result = "";
		while (in_.peek() != '\n' && in_.eof() == false)
		{
			result += in_.get();
		}
		in_.get();
		return result;
	}
예제 #16
0
int loadNextKeyFrame(int val){			//val = 2 : initial load (2 key frames) ; val = 1 subsequent loads

	for ( int i=0;i<34;i++){
		curr_angles[i] = next_angles[i];
	}
	curr_lid_angle = next_lid_angle;
	keyFileIn.peek();
	if (keyFileIn.good()){
		keyFileIn >> l1 >> l2 >> next_lid_angle;

		for ( int i=0;i<34;i++){
			keyFileIn >> next_angles[i] ;
		}

		while(keyFileIn.get() != '\n');
		keyFileIn.peek();
		if(val == 1)
			return 0;
	}	
예제 #17
0
Regions RegionFileLoader::ReadRegions(std::ifstream& f)
{
    Regions regions;
    std::vector<Double_t> vec;
    Char_t next_char;
    std::stringstream ss;
    Double_t sa;

    std::string aline;
    while (1)
    {
        f >> std::ws;
        next_char = f.peek();
        // check to see if the next is a number,
        // if so, this function is done break
        if ( ! IsNumber(next_char) )
        {
            break;
        }

        std::getline(f,aline);
        ss.clear(); ss.str("");
        vec.clear();

        ss << aline;
        ss >> sa;
        while(!ss.fail())
        {
            vec.push_back(sa);
            ss >> sa;
        }

//        std::cout << vec.size() << std::endl;
        if (vec.size() == 8)
        {
            Region region;
            region.grid_xlow = vec[0];
            region.cntr_xlow = vec[1];

            region.grid_xhigh = vec[2];
            region.cntr_xhigh = vec[3];

            region.grid_ylow = vec[4];
            region.cntr_ylow = vec[5];

            region.grid_yhigh = vec[6];
            region.cntr_yhigh = vec[7];

//            std::cout << "filling current region" << std::endl;
            regions.push_back(region);
        }
    }

    return regions;
}
예제 #18
0
///// overmap legacy deserialization, replaced with json serialization June 2015
// throws std::exception (most likely as JsonError)
void overmap::unserialize_legacy(std::ifstream & fin) {
    // DEBUG VARS
    int nummg = 0;
    char datatype;
    int cx, cy, cz, cs, cp, cd, cdying, horde, tx, ty, intr;
    std::string cstr;
    city tmp;
    std::list<item> npc_inventory;

    if ( fin.peek() == '#' ) {
        std::string vline;
        getline(fin, vline);
    }

    int z = 0; // assumption
    while (fin >> datatype) {
        if (datatype == 'L') { // Load layer data, and switch to layer
            fin >> z;

            std::string tmp_ter;
            oter_id tmp_otid(0);
            if (z >= 0 && z < OVERMAP_LAYERS) {
                int count = 0;
                std::unordered_map<tripoint, std::string> needs_conversion;
                for (int j = 0; j < OMAPY; j++) {
                    for (int i = 0; i < OMAPX; i++) {
                        if (count == 0) {
                            fin >> tmp_ter >> count;
                            if( obsolete_terrain( tmp_ter ) ) {
                                for( int p = i; p < i+count; p++ ) {
                                    needs_conversion.emplace( tripoint( p, j, z-OVERMAP_DEPTH ),
                                                              tmp_ter );
                                }
                                tmp_otid = 0;
                            } else if( otermap.count( tmp_ter ) > 0 ) {
                                tmp_otid = tmp_ter;
                            } else if( tmp_ter.compare( 0, 7, "mall_a_" ) == 0 &&
                                       otermap.count( tmp_ter + "_north" ) > 0 ) {
                                tmp_otid = tmp_ter + "_north";
                            } else if( tmp_ter.compare( 0, 13, "necropolis_a_" ) == 0 &&
                                       otermap.count( tmp_ter + "_north" ) > 0 ) {
                                tmp_otid = tmp_ter + "_north";
                            } else {
                                debugmsg("Loaded bad ter! ter %s", tmp_ter.c_str());
                                tmp_otid = 0;
                            }
                        }
                        count--;
                        layer[z].terrain[i][j] = tmp_otid; //otermap[tmp_ter].loadid;
                        layer[z].visible[i][j] = false;
                    }
                }
                convert_terrain( needs_conversion );
            } else {
예제 #19
0
/*  THIS FUNCTION FILLS A BUFFER FOR THE ACTUAL READS, REPRESENTED AS
 *  RECORDS IN A FASTQ FILE, INCLUDING THE QUALITY SCORES
 */
void 
fill_buffer(std::ifstream &in, const size_t buffer_start, 
	    vector<MappedRead> &buffer) {
  size_t i = buffer_start;
  for (; i != buffer.size() && !in.eof(); ++i) {
    in >> buffer[i];
    in.peek();
  }
  if (i < buffer.size())
    buffer.erase(buffer.begin() + i, buffer.end());
}
예제 #20
0
static uint32_t parse_monster_symb(std::ifstream &f,
                                   std::string *lookahead,
                                   char *symb)
{
  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  *symb = f.get();

  eat_blankspace(f);
  if (f.peek() != '\n') {
    return 1;
  }

  f >> *lookahead;

  return 0;
}
예제 #21
0
/*
 * Parse an open .sav file.
 */
void game::unserialize(std::ifstream & fin) {
   if ( fin.peek() == '#' ) {
       std::string vline;
       getline(fin, vline);
       std::string tmphash, tmpver;
       int savedver=-1;
       std::stringstream vliness(vline);
       vliness >> tmphash >> tmpver >> savedver;
       if ( tmpver == "version" && savedver != -1 ) {
           savegame_loading_version = savedver;
       }
   }
예제 #22
0
Message::Message(std::ifstream &in, char c) {
    if (!in.eof()) {
        getline(in, user, ' ');

        if (in.peek() == '@') {
            in.get();
            getline(in, reply, ' ');
        }

        getline(in, tweet, c);
    }
}
static uint32_t parse_object_desc(std::ifstream &f,
                                   std::string *lookahead,
                                   std::string *desc)
{
  /* DESC is special.  Data doesn't follow on the same line *
   * as the keyword, so we want to eat the newline, too.    */
  eat_blankspace(f);

  if (f.peek() != '\n') {
    return 1;
  }

  f.get();

  while (f.peek() != EOF) {
    getline(f, *lookahead);
    if (lookahead->length() > 77) {
      return 1;
    }

    lookahead->push_back('\n');

    if (*lookahead == ".\n") {
      break;
    }

    *desc += *lookahead;
  }

  /* Strip off the trailing newline */
  desc->erase(desc->length() - 1);

  if (*lookahead != ".\n") {
    return 1;
  }

  f >> *lookahead;

  return 0;
}
template <class T> void GetNextToken(std::ifstream& Config, T& Data)
{
    if (!Config)
        throw std::runtime_error("Config stream is not open !");

    std::string buffer;
    while (Config.peek() == '#')
    Config.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    
    std::getline(Config, buffer, ' ');
    std::cout << "[DEBUG] : " << buffer << std::endl;
    Data = ToType<T>(buffer);
}
     bool read(int gid) {
    	 //logstream(LOG_INFO) << "gid=" << gid << ", idx=" << idx << std::endl;
    	 if (gid > idx) {
    		 idx = gid;
    	 }

    	 int bid = getBlockId(idx);
    	 if (bid != block_id) {
    		 ASSERT_TRUE(closeEdgeFile(0));

    		 block_id = bid;
    		 ASSERT_TRUE(openEdgeFile(0));
    	 }

    	 int vid, len, eid;
    	 bool find = false;
    	 std::vector<int>().swap(edges);
    	 //logstream(LOG_INFO) << "num_of_edges = " << degree[idx] << ", total_ver_num=" << ver_num << std::endl;
    	 while (fin.peek()!=EOF) {
    		 //logstream(LOG_INFO) << "begin to read file..." << std::endl;
    		 fin.read((char*)(&vid), sizeof(vid));
    		 fin.read((char*)(&len), sizeof(len));
    		 //logstream(LOG_INFO) << "read vid=" << vid << ", current idx=" << idx <<std::endl;
    		 if (vid > idx) {
    			 //logstream(LOG_INFO) << "judge, read vid=" << vid << ", current idx=" << idx <<std::endl;
    			 break;
    		 } else if (vid < idx) {
    			 for (int i = 0; i < len; i++) {
    				 fin.read((char*)(&eid), sizeof(eid));
    				 //logstream(LOG_INFO) << "skip eid=" << eid << std::endl;
    			 } // skip no-used edges
    			 continue;
    		 } else {
    			 for (int i = 0; i < len; i++) {
    				 fin.read((char*)(&eid), sizeof(eid));
    				 edges.push_back(eid);
    				 //logstream(LOG_INFO) << "eid=" << eid << std::endl;
    			 }
    			 find = true;
    			 break;
    		 }
    	 }

    	 if (find) {
    		 //logstream(LOG_INFO) << "find" << std::endl;
    		 return true;
    	 } else {
    		 //logstream(LOG_INFO) << "not find" << std::endl;
    		 return false;
    	 }
     }
예제 #26
0
static uint32_t parse_monster_color(std::ifstream &f,
                                    std::string *lookahead,
                                    std::vector<uint32_t> *color)
{
  uint32_t i;
  uint32_t c;

  c = UINT_MAX;

  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  do {
    f >> *lookahead;

    for (i = 0; colors_lookup[i].name; i++) {
      if (*lookahead == colors_lookup[i].name) {
        c = colors_lookup[i].value;
        break;
      }
    }

    if (!colors_lookup[i].name) {
      return 1;
    }

    color->push_back(c);

    eat_blankspace(f);
  } while (f.peek() != '\n');

  f >> *lookahead;

  return 0;
}
예제 #27
0
/*  THIS FUNCTION FILLS A BUFFER FOR GenomicRegion OBJECTS
 */
void 
fill_buffer(std::ifstream &in, const size_t buffer_start, 
	    vector<GenomicRegion> &buffer) {
  GenomicRegion tmp;
  size_t i = buffer_start;
  assert(buffer_start <= buffer.size());
  for (; i != buffer.size() && !in.eof(); ++i) {
    in >> tmp;
    buffer[i].swap(tmp);
    in.peek();
  }
  if (i < buffer.size())
    buffer.erase(buffer.begin() + i, buffer.end());
}
예제 #28
0
static uint32_t parse_monster_abil(std::ifstream &f,
                                   std::string *lookahead,
                                   uint32_t *abil)
{
  uint32_t i;

  *abil = 0;

  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  /* Will not lead to error if an ability is listed multiple times. */
  while (f.peek() != '\n') {
    f >> *lookahead;

    for (i = 0; abilities_lookup[i].name; i++) {
      if (*lookahead == abilities_lookup[i].name) {
        *abil |= abilities_lookup[i].value;
        break;
      }
    }

    if (!abilities_lookup[i].name) {
      return 1;
    }

    eat_blankspace(f);
  }

  f >> *lookahead;

  return 0;
}
static uint32_t parse_object_color(std::ifstream &f,
                                    std::string *lookahead,
                                    uint32_t *color)
{
  uint32_t i;

  *color = UINT_MAX;

  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  f >> *lookahead;

  for (i = 0; colors_lookup[i].name; i++) {
    if (*lookahead == colors_lookup[i].name) {
      *color = colors_lookup[i].value;
      break;
    }
  }

  if (!colors_lookup[i].name) {
    return 1;
  }

  eat_blankspace(f);
  if (f.peek() != '\n') {
    return 1;
  }

  f >> *lookahead;

  return 0;
}
static uint32_t parse_object_type(std::ifstream &f,
                                   std::string *lookahead,
                                   uint32_t *type)
{
  uint32_t i;

  *type = 0;

  eat_blankspace(f);

  if (f.peek() == '\n') {
    return 1;
  }

  /* Will not lead to error if an ability is listed multiple times. */
  while (f.peek() != '\n') {
    f >> *lookahead;

    for (i = 0; type_lookup[i].name; i++) {
      if (*lookahead == type_lookup[i].name) {
        *type |= type_lookup[i].value;
        break;
      }
    }

    if (!type_lookup[i].name) {
      return 1;
    }

    eat_blankspace(f);
  }

  f >> *lookahead;

  return 0;
}