コード例 #1
0
ファイル: Facile.cpp プロジェクト: nchen2211/DataStructure
void parseProgram(istream &inf, vector<Statement *> & program)
{
	program.push_back(NULL);

	string line;
	while( ! inf.eof() )
	{
		getline(inf, line);
		program.push_back( parseLine( line ) );

	}
}
コード例 #2
0
ファイル: LanguageParsers.cpp プロジェクト: wllxyz/xyz
//加载输入流
bool LanguageParsers::LoadInput(istream& ins)
{
	if(ins.fail())
	{
		return false;
	}

	this->input_symbols.clear();

	char c=ins.get();
	if(!ins.eof())
	{
		do
		{
			this->input_symbols.push_back(Symbols(c));
			c=ins.get();
		}while(!ins.eof());
	}

	return true;
}
コード例 #3
0
ファイル: SimpleJSON.cpp プロジェクト: liyulun/mantid
// Consume whitespace characters from stream.  Leaves the stream
// pointing at the next non-whitespace char (or possibly eof());
void skipWhiteSpace(istream &istr) {

  char next;
  istr >> next; // take advantage of the fact that >> uses whitespace as a field
                // separator
  if (!istr.eof()) {
    // If eof() is set, it means we didn't find any tokens after the whitespace.
    // In this case
    // there's nother to put back, and doing so would unset the eof bit.
    istr.putback(next);
  }
}
コード例 #4
0
ファイル: Util.cpp プロジェクト: hussam-a/circ-min
void readExpression(istream& is, bitset* minterms, bitset* donotcare, uint8_t* varsCount) {
    char temp = '0';
    long long number;
    bitset* currentSet = minterms;
    is >> number;
    *varsCount = number;
    cout << *varsCount << endl;
    if (is.fail() || int(*varsCount) > int(16))
        throw logic_error("Variables count could not be read or invalid");
    is >> temp;
    if (is.fail() || is.eof() || temp != ';')
        throw logic_error("Syntax error: expected ';'");
    _t_minterm maxValue = (pow(2, *varsCount) - 1);
    minterms->resize(maxValue + 1);
    donotcare->resize(maxValue + 1);
    is >> number;
    if (!is.eof()) {
        while (true) {
            if (is.fail())
                throw logic_error("Syntax error");
            if (number > maxValue)
                throw out_of_range("Invalid min-term value: given value is greater than maximum");
            currentSet->set(number);
            temp = '0';
            is >> temp;
            if (is.fail() || is.eof() || (temp != ';' && temp != ','))
                throw logic_error("Syntax error: expected ';'");
            if (temp == ',') {
                is >> number;
            } else if (temp == ';') {
                if (currentSet == donotcare)
                    break;
                else {
                    currentSet = donotcare;
                    is >> number;
                    if (is.eof())
                        break;
                }
            } else {
                throw logic_error("Unhandled weird exception");
コード例 #5
0
ファイル: HumdrumFileBasic.cpp プロジェクト: mdsmus/humdrum
void HumdrumFileBasic::read(istream& inStream) {
   char* templine;
   templine = new char[4096];
   int linecount = 0;
   while (!inStream.eof()) {
      inStream.getline(templine, 4096);
#ifdef USING_URI
      if ((linecount++ == 0) && (strstr(templine, "://") != NULL)) {
         if (strncmp(templine, "http://", strlen("http://")) == 0) {
            readFromHttpURI(templine);
            delete [] templine;
            return;
         }
         if (strncmp(templine, "humdrum://", strlen("humdrum://")) == 0) {
            readFromHumdrumURI(templine);
            delete [] templine;
            return;
         } 
         if (strncmp(templine, "hum://", strlen("hum://")) == 0) {
            readFromHumdrumURI(templine);
            delete [] templine;
            return;
         } 
         if (strncmp(templine, "h://", strlen("h://")) == 0) {
            readFromHumdrumURI(templine);
            delete [] templine;
            return;
         } 
      }
#endif
      if (inStream.eof() && (strcmp(templine, "") == 0)) {
         break;
      } else {
         appendLine(templine);
      }
   }
   analyzeSpines();
   analyzeDots();
   delete [] templine;
}
コード例 #6
0
	vector<string> splitString(char* rawSplit, istream& source, char delimiter, unsigned int estimatedSplitCount)
	{
		vector<string> splits;
		splits.reserve(estimatedSplitCount);

		while (!source.eof())
		{
			source.getline(rawSplit, MAX_SPLIT_LENGTH, delimiter);
			splits.push_back(rawSplit);
		}

		return splits;
	}
コード例 #7
0
ファイル: Input2.cpp プロジェクト: DaisukeYamato/book
bool SkipOnError(istream& istr){
  if (istr.fail()){
    if (istr.eof()){
      exit(EXIT_FAILURE);
    }

    // skip one character
    char ch;
    istr.clear();
    istr >> ch;
    return true;
  } else {
    return false;
コード例 #8
0
ファイル: main.cpp プロジェクト: QiaoYangHan/ProcessScheduler
void createProcesses(istream& ifs, vector<Process*>& processes)
{	
	while(!ifs.eof())
	{
		unsigned id;
		unsigned arrivalTime;
		unsigned totalCPU;
		unsigned averageBurst;
		ifs >> id >> arrivalTime >> totalCPU >> averageBurst;
		Process* p = new Process(id, arrivalTime, totalCPU, averageBurst);
		processes.push_back(p);
	}
}
コード例 #9
0
bool getLine( istream &fileP, vector< string > &item )
{
  if (fileP.eof())
    return false;

  string line;
  if (!getline(fileP, line))
    return false;

  item = splitLine(line.c_str());

  return true;
}
コード例 #10
0
ファイル: cmdCharDef.cpp プロジェクト: ATeamMember/dsnp_hw3_2
// DO NOT CHANGE THIS PART...
// DO NOT CHANGE THIS PART...
//
// This part will be used by TA to test your program.
//
// TA will use "make -DTA_KB_SETTING" to test your program
//
ParseChar
CmdParser::getChar(istream& istr) const
{
   char ch = mygetc(istr);

   if (istr.eof())
      return returnCh(INPUT_END_KEY);
   switch (ch) {
      // Simple keys: one code for one key press
      // -- The following should be platform-independent
      case LINE_BEGIN_KEY:  // Ctrl-a
      case LINE_END_KEY:    // Ctrl-e
      case INPUT_END_KEY:   // Ctrl-d
      case TAB_KEY:         // tab('\t') or Ctrl-i
      case NEWLINE_KEY:     // enter('\n') or ctrl-m
         return returnCh(ch);

      // -- The following simple/combo keys are platform-dependent
      //    You should test to check the returned codes of these key presses
      // -- You should either modify the "enum ParseChar" definitions in
      //    "charDef.h", or revise the control flow of the "case ESC" below
      case BACK_SPACE_KEY:
         return returnCh(ch);

      // Combo keys: multiple codes for one key press
      // -- Usually starts with ESC key, so we check the "case ESC"
      case ESC_KEY: {
         char combo = mygetc(istr);
         // Note: ARROW_KEY_INT == MOD_KEY_INT, so we only check MOD_KEY_INT
         if (combo == char(MOD_KEY_INT)) {
            char key = mygetc(istr);
            if ((key >= char(MOD_KEY_BEGIN)) && (key <= char(MOD_KEY_END))) {
               if (mygetc(istr) == MOD_KEY_DUMMY)
                  return returnCh(int(key) + MOD_KEY_FLAG);
               else return returnCh(UNDEFINED_KEY);
            }
            else if ((key >= char(ARROW_KEY_BEGIN)) &&
                     (key <= char(ARROW_KEY_END)))
               return returnCh(int(key) + ARROW_KEY_FLAG);
            else return returnCh(UNDEFINED_KEY);
         }
         else { mybeep(); return getChar(istr); }
      }
      // For the remaining printable and undefined keys
      default:
         if (isprint(ch)) return returnCh(ch);
         else return returnCh(UNDEFINED_KEY);
   }

   return returnCh(UNDEFINED_KEY);
}
コード例 #11
0
void ScorePageBase::readPmx(istream& infile, int verboseQ) {
   clear();

   ScoreItem* sip = NULL;
   while (!infile.eof()) {
      sip = readPmxScoreLine(infile, verboseQ);
      if (sip != NULL) {
         // setPageOwner will store the pointer for the ScoreItem
         // on the given page.  The page will delete it when it
         // is deconstructed.
         sip->setPageOwner(this);
      }
   }
}
コード例 #12
0
ファイル: 10_6_2.cpp プロジェクト: k-mi/Stroustrup_PPP
// EOFまたは終了インジゲータが検出されるまでistからvに整数を読み取る
void fill_vector(istream& ist, vector<int>& v, char terminator){
	int i = 0;
	while(ist >> i) v.push_back(i);
	if(ist.eof()) return;		// OK: EOFが検出された

	if(ist.fail()){				// できるだけ後始末をし、問題を報告する
		ist.clear();			// ストリームの状態をクリアし、終了インジゲータを調査できるようにする
		char c;
		ist >> c;				// 文字を読み取る(終了インジゲータでありますように)
		if(c != terminator){	// 予想外の文字
			ist.unget();
			ist.clear(ios_base::failbit);	// 状態をfailに設定する
		}
	}
コード例 #13
0
string Utils::readStreamAsString(istream &inStream) {
	ostringstream result;

	while (true) {
		char got = static_cast<char>(inStream.get());
		if (!inStream.eof()) {
			result << got;
		} else {
			break;
		}
	}

	return result.str();
}
コード例 #14
0
obj ReplacementSelection<obj>::fill(istream& infile){
	obj newelement;
	int i;
	int newIndex;
	infile>>newelement; 
	for(i=0; i<size && !infile.eof(); i++){
		heap[i]=newelement;
		leftEnd=i;
		heapify(true);
		infile>>newelement;

	}
	return newelement;
}
コード例 #15
0
void createPrimary(istream& read, ostream& primary){
    int number,byte = 0;
    map<int,int> mymap;
    PrimaryIndex p;
    ClientData client;
    read.clear();
    read.seekg(0);
    primary.seekp(0);
    if(read.eof())return;
    read >> client;
    while(!read.eof()){
        if(number = client.getAccountNumber()){
            mymap[number] = byte;
            byte = read.tellg();
        }
        read >> client;
    }
    for(map<int,int>::iterator it = mymap.begin(); it != mymap.end(); it++){
        p.AccountNumber = it->first;
        p.Byte = it->second;
        primary.write(reinterpret_cast<char*>(&p), sizeof(PrimaryIndex));
    }
}
コード例 #16
0
void RecordProcess::AnalyseRecordStream(istream &RecordStream)
{
	while(!RecordStream.eof())
	{
		AnalyseARecord(RecordStream);

	}


    

	

}
コード例 #17
0
string GroceryItem::readName(istream &in)
{
    long int eoln;
	char inval[255];
	char *ptr;
	do
	{
		in.getline(inval,255);
		ptr = strchr(inval,'\0');
		eoln = ptr -inval;
	} while (!eoln && !in.eof());
	return string(inval);

}
コード例 #18
0
ファイル: egs_rndm.cpp プロジェクト: tener32/EGSnrc
bool EGS_RandomGenerator::setState(istream &data) {
    if( !egsGetI64(data,count) ) return false;
    int np1;
    data >> np1 >> ip;
    if( !data.good() || data.fail() || data.eof() ) return false;
    if( np1 < 1 ) return false;
    if( np1 != np && np > 0 ) {
        delete [] rarray; rarray = new EGS_Float [np1];
    }
    np = np1;
    for(int j=0; j<np; j++) data >> rarray[j];
    if( !data.good() ) return false;
    return setPrivateState(data);
}
コード例 #19
0
ファイル: convert.cpp プロジェクト: DavePearce/TuttePoly
string read_line(istream &in) {
  char c;
  string str;

  in.get(c); 
  while(!in.eof() && c != '\n') {
    if(c != '\r') {
      str = str + c;
    }
    in.get(c);  
  }

  return str;
}
コード例 #20
0
ファイル: convertBow06to05.cpp プロジェクト: Geekking/lima
// read documents in a file, using the document buffer given as argument
// (can be BoWDocument* or BoWDocumentST*)
void readDocuments(istream& fileIn, ostream& out)
{
  while (! fileIn.eof())
  {
    // enum type with small number of values coded on one byte;
    BoWBlocType blocType;
    fileIn >> blocType;
    if (blocType==DOCUMENT_PROPERTIES_BLOC)
    {
      Lima::Common::Misc::DocumentProperties props;
      props.read(fileIn);
      props.write(out);
      fileIn >> blocType;
    }
    BoWText text;
    while (blocType==BOW_TEXT_BLOC)
    {
      text.read(fileIn);
      if (fileIn.eof()) break;
      fileIn >> blocType;
    }
    text.write(out);
  }
コード例 #21
0
ファイル: LgShell.cpp プロジェクト: whoopdedo/lgscript
const char* LgScriptReader::read(State&, size_t *sz)
{
	if (extraline)
	{
		extraline = false;
		*sz = 1;
		return "\n";
	}
	if (infile->eof())
		return NULL;
	infile->read(buff, sizeof(buff));
	*sz = infile->gcount();
	return buff;
}
コード例 #22
0
ファイル: rumlagenhet00.cpp プロジェクト: tnordenmark/UU
bool Lagenhet::laes( istream &is )
{
  // För varje lägenhet finns 
  // följande information i filen: 
  // koeksyta badrumsyta antalrum yta 
  // för varje rum.
  //  Exempel: 
  // 20 12 3 20 10 10
  // 12 12 2 15 10

  // Rum har ingen egen inläsningsmetod.
  // Använd temporär variabel vid
  // inläsning. Om det gick bra:
  // använd konstruktor i Rum-klassen.

  int temp;      // temporär variabel

  is >> temp;
  if ( is.eof() ) return false;
  koek = Rum(temp);

  is >> temp;
  if ( is.eof() ) return false;
  badrum = Rum(temp);

  is >> temp;
  if ( is.eof() ) return false;
  antalrum = temp;

  for ( int i = 0; i < antalrum; i++ )
   {
     is >> temp;
     if ( is.eof() ) return false;
     rum[i] = Rum(temp);     
   }
  return true;
}
コード例 #23
0
ファイル: SimpleJSON.cpp プロジェクト: liyulun/mantid
// Initialize a JSON array from a stream
// This is similar to initFromStream() above and may also be called
// recursively by way of initValueFromStream()
// The expectation is that the first character will be a '[' and it
// will run until if finds a matching ']' char.  Along the way it
// may create nested objects and/or arrays.
// Note: It will consume the closing bracket from the stream
void initArrayFromStream(JSONArray &arr, istream &istr) {
  char nextChar;
  istr >> nextChar;
  checkChar(nextChar, '['); // sanity check
  skipWhiteSpace(istr);

  // Check for empty array (and make sure we consume the ])
  nextChar = static_cast<char>(istr.peek());
  if (nextChar == ']') {
    istr.ignore();
  }

  while (nextChar != ']') // process the stream
  {
    // Quick sanity check
    if (istr.eof()) {
      throw JSONParseException("Unexpected end of data stream");
    }

    // We expect to start the loop with the stream pointing to the
    // first character of the value
    // Add the value to our array
    arr.push_back(initValueFromStream(istr));

    istr >> nextChar;
    // nextChar is guaranteed to be either a comma, close brace or close
    // bracket.
    //(If it was anything else, initValueFromStream() would have thrown an
    // exception.)
    // A brace is an error, a bracket means the array is done (and will be
    // checked at
    // the start of the while loop) and a comma needs to be thrown out (along
    // with any
    // following whitespace) to position us for the next value
    if (nextChar == '}')
      throw JSONParseException(
          "Invalid closing brace while initializing array");
    else if (nextChar == ',') {
      skipWhiteSpace(istr);
      // Check to see if another key/value pair really follows the comma
      // (because if one doesn't, the parser will get screwed up and may not
      // actually detect the problem).
      if (istr.peek() == ']') {
        throw JSONParseException(
            "Invalid comma (array ended with no further values)");
      }
    }
  }
}
コード例 #24
0
int getFunctionInput(istream &fin, FunctionFormat &function)
{
	function.prepUp();
	fin.ignore(numeric_limits<streamsize>::max(), ':');
	if(fin.eof())
		return 1; //Could not find a function
	fin>>function.newname;
	if(!fin)
		return 1; //There was nothing after colon
	while(fin)
	{
		int temp;
		fin>>temp;
		if(fin)
			function.addReturn(temp);
	}
	fin.clear();
	while(fin.peek()!=':' && !fin.eof())
	{
		char temp_string[1000];
		fin.getline(temp_string, 1000);
		stringstream case_string_stream(temp_string);
		Case temp_case;
		case_string_stream>>temp_case.oldname;
		while(case_string_stream)
		{		
			int temp_int;
			case_string_stream>>temp_int;
			if(case_string_stream)
				temp_case.addArg(temp_int);
		}
		
		function.addCase(temp_case);
	}
	return 0;
}
コード例 #25
0
ファイル: GenBank.cpp プロジェクト: pjotrp/biopp
void GenBank::appendFromStream(istream & input, VectorSequenceContainer & vsc) const throw (Exception)
{
    if (!input) {
        throw IOException ("GenBank::read: fail to open file");
    }

    string temp, name, sequence = "";  // Initialization

    // Main loop : for all file lines
    while (!input.eof())
    {
        getline(input, temp, '\n');  // Copy current line in temporary string

        if(temp.size() >= 9 && temp.substr(0,9) == "ACCESSION")
        {
            name = TextTools::removeSurroundingWhiteSpaces(temp.substr(10));
            StringTokenizer st(name, " ");
            name = st.nextToken();
            //cout << name << endl;
        }
        if(temp.size() >=6 && temp.substr(0,6) == "ORIGIN")
        {
            sequence = "";
            getline(input, temp, '\n');  // Copy current line in temporary string
            while(!input.eof() && temp.size() > 2 && temp.substr(0,2) != "//")
            {
                sequence += TextTools::removeWhiteSpaces(temp.substr(10));
                getline(input, temp, '\n');  // Copy current line in temporary string
            }
            if(name == "") throw Exception("GenBank::read(). Sequence with no ACCESSION number!");
            Sequence * seq = new Sequence(name, sequence, vsc.getAlphabet());
            vsc.addSequence(* seq);
            name = "";
        }
    }
}
コード例 #26
0
void ConfigFile::read(istream& in)
{
    _map.clear();
    int lineNumber = 0;
    while (! in.eof())
    {
        string line;
        getline(in, line);
        trim(line);
        ++lineNumber;
        if (line == "" || line[0] == '#')
            continue;
        handleLine(line, lineNumber);        
    }
}
コード例 #27
0
ファイル: canberra_cnf.cpp プロジェクト: ayuzer/qpx-gamma
bool CanberraCnfDataSet::check(istream &f, string*)
{
    int acq_offset = 0;
    f.ignore(112);
    int pos = 112;
    char buf[48];
    while (!f.eof()) {
        f.read(buf, 48);
        if (f.gcount() != 48)
            return false;
        if ((buf[1] != 0x20 || buf[2] != 0x01) && buf[1] != 0 && buf[2] != 0)
            return false;
        pos += 48;
        if (buf[0] == 0) {
            acq_offset = from_le<uint32_t>(buf+10);
            break;
        }
    }
    if (acq_offset <= pos)
        return false;
    f.ignore(acq_offset - pos);
    f.read(buf, 48);
    return (!f.eof() && f.gcount() == 48 && buf[0] == 0 && buf[1] == 0x20);
}
コード例 #28
0
//------------------------------------------------------------------------------------------------------------------------------------------
///
bool SyncRecordManager::istreamMatrix( istream &is, const char *header, double m[16], const bool verbose )
{
	if( !istreamSkipPastEOL( is, 1 ) ){
		cerr << "SyncRecordManager::istreamMatrix(): cannot skip header line '" << header << "'" << endl; return false;
	}
	// later we can scan in the header and actually verify it
	int err = 0;
	for( int i = 0 ; i < 4 ; ++i ) for( int j = 0 ; j < 4 ; ++j ) if( !is.eof() && is.good() ) err += !( is >> m[4*i+j] );
	if( err ){     cerr << "SyncRecordManager::istreamMatrix(): could not read " << header << " matrix" << endl; return false; }
	if( verbose ){ cout <<       "SyncRecordManager::istreamMatrix(): read following matrix:" << endl; ostreamMatrix( cout, header, m ); }
	if( !istreamSkipPastEOL( is, 1 ) ){
		cerr            << "SyncRecordManager::istreamMatrix(): cannot skip to end of matrix" << endl; return false;
	}
	return true;
}
コード例 #29
0
ファイル: piglatin.cpp プロジェクト: gimki/C-Assignment
void translateStream(istream& in, ostream& out){


  char s[60];
  char t[60];
  in>>s;
  if(!in.eof()){
    translateWord(s,t);
    out<<t<<" ";
    out<<"00000";
    translateStream(in,out);
  }

  return;
}
コード例 #30
0
void printStreamState(const istream& istr)
{
	if (istr.good()) {
		cout << "stream state is good" << endl;
	}
	if (istr.bad()) {
		cout << "stream state is bad" << endl;
	}
	if (istr.fail()) {
		cout << "stream state is fail" << endl;
	}
	if (istr.eof()) {
		cout << "stream state is eof" << endl;
	}
}