コード例 #1
0
ファイル: nodeFactory.cpp プロジェクト: prisme60/mastermind
    bool NodeFactory::readCombinaison(stringstream &sPath, U32 maxPosition, U32 &position, U8* &pCombinaisons) noexcept{
        bool bResult = true;
        if (position == 0)//if there was no previous search
            position = sPath.str().find_first_of('[');
        else
            position = sPath.str().find_first_of('[', position + 1);
        if (static_cast<size_t> (position) != string::npos) {
            char separator = '[';
            cerr << "fillNodeInit: found [" << endl;
            sPath.seekg(static_cast<size_t> (position + 1), ios::beg);
            for (U32 combiItem = 0; combiItem < maxPosition; combiItem++) {
                if (sPath.good()) {
                    if (separator != ']') {//retrieve another item of the combinaison
                        U32 temp;
                        sPath >> temp;
                        *pCombinaisons = static_cast<U8> (temp);
                        pCombinaisons++;

                        cerr << "position:" << position << endl;
                        cerr << "[" << temp << "]";
                        cerr << "�" << combiItem << "," << maxPosition << "�" << endl;
                    }
                    else //separator == ']'
                    {//combinaison completed too soon, all items of the combinaison are not retrieved
                        bResult = false;
                        break;
                    }
                } else {//incomplete combinaison
コード例 #2
0
ファイル: coldriver.cpp プロジェクト: LraCrisis/andes
/************************************************************************
 * solveTheProblem							*
 *	Assumes the equations and variables have already been entered	*
 *	solves the problem, writing the solution in TEMP_FILE, 		*
 *	including the tags and problem statements if the problem was	*
 *	not completely solved.						*
 *   Then it opens the file for reading, and returns the first line	*
 *	[does not close file]						*
 ************************************************************************/
const char* solveTheProblem() {
  int k;

  if (isFirst) throw string("solveTheProblem called before initialization");
  try {
    // reset the buffer to be empty
    resultBuffer.str(string());
    if(resultBuffer.good()) {
      numsols->assign(canonvars->size(),HUGE_VAL);
      if (solveeqs(resultBuffer)) {
	// should we do checking of solution here?
	bool discrep = false;
	for (k = 0; k < canoneqf->size(); k++) {
	  if (checksol((*canoneqf)[k],numsols,RELERR) > 1) {
	    if (!discrep) {
	      resultBuffer << "<DISCREPANCIES>" << endl;
	      discrep = true;
	    }
	    resultBuffer << (*canoneqf)[k]->getInfix() << endl;
	  }
	} // loop over equations to check
	dimchkeqf(resultBuffer);
	// end of "should we do checking of solution here?"
      }
    } 
    else throw string("unable to create solution buffer");
  } 
  catch (string message) { throw message; } 
  catch (...) { throw string("solveTheProblem went boom!!"); }

  // this would be a good place to insert checksol ? or after returning
  // solution, in solveMoreOfTheProblem ?
  try {
    resultBuffer.clear();
    resultBuffer.seekg(0);
    int tk;
    try { tk = resultBuffer.eof(); } 
    catch (...) { throw string("eof?!?"); }
    if (! tk) {
      string t;
      try { t = getaline(resultBuffer); }
      catch (...) { throw string("getaline fails???"); }
      try { sprintf(lzbfr, "%s", t.c_str()); } 
      catch(...) { throw string("copy is wrong??"); }
      return lzbfr;
    } 
    else return error[4];
  } 
  catch (string message) { throw message; } 
  catch (...) { throw string("Read went bad!!"); }
  return error[3];
}
コード例 #3
0
        uint32_t QueryableNetstringsDeserializerABCF::fillBuffer(istream& in, stringstream& buffer) {
            char _c = 0;
            uint32_t bytesRead = 0;

            // Peek Container's header: 2 bytes (0xABCF) followed by maximum 8 bytes (uint64_t) length of payload information.
            uint32_t bytesToRead = sizeof(uint16_t) + sizeof(uint64_t);

            // Read Container header + size of payload.
            while (in.good() && (bytesToRead > 0)) {
                // Read next byte.
                in.read(&_c, sizeof(char));
                bytesToRead--; bytesRead++;

                // Add new byte at the end of the buffer.
                buffer.write(&_c, sizeof(char));
            }

            // Decode Container's magic number.
            uint16_t magicNumber = 0;
            buffer.read(reinterpret_cast<char*>(&magicNumber), sizeof(uint16_t));
            magicNumber = ntohs(magicNumber);

            if (magicNumber == 0xABCF) {
                // Decode size of payload (encoded as varint).
                uint64_t value = 0;
                uint8_t size = 0;
                {
                    while (buffer.good()) {
                        char c = 0;
                        buffer.read(&c, sizeof(char));
                        value |= static_cast<unsigned int>( (c & 0x7f) << (0x7 * size++) );
                        if ( !(c & 0x80) ) break;
                    }
                    // Decode as little endian like in Protobuf's case.
                    value = le64toh(value);
                }

                bytesToRead = (value // This is the length of the payload.
                               - (sizeof(uint64_t) // We have already read this amount of bytes while peeking the header.
                                  - size) // This amount of bytes was consumed to encode the length of the payload in the varint field.
                                 )
                               + 1; // And we need to consume the final ','.

                // Add the data at the end of the buffer.
                buffer.seekg(0, ios_base::end);

                // Read remainder of the container.
                while (in.good() && (bytesToRead > 0)) {
                    // Read next byte.
                    in.read(&_c, sizeof(char));
                    bytesToRead--; bytesRead++;

                    // Add new byte at the end of the buffer.
                    buffer.write(&_c, sizeof(char));
                }

                // Move read pointer to the beginning to read container.
                buffer.seekg(0, ios_base::beg);
            }

            return bytesRead;
        }
コード例 #4
0
//Ask user what string they would like to find.
void userFind(stringstream& ss) {

	extern char** environ;
	char* choice = new char [WORD_SIZE];
	char* word   = new char [WORD_SIZE];
	char* environment = new char [WORD_SIZE];
	char temp;
	int numLine = 0;
	int count = 0;
	int lines = 0;
	streampos gpos, ppos;

	ss.str(ss.str());
	ss.seekp(0, ss.beg);
	ss.seekg(0, ss.beg);
	ss.clear();

	//Ask user what string they would like to search for.
	cout << "Please enter a string to search or \"END\" to quit. \n";
	cin >> choice;
	transform(choice, (choice + strlen(choice)), choice, ::toupper);

	while(strcmp(choice, "END") != 0) {
		//Search the stringstream for each occurance of the string.
		while(ss.getline(word, WORD_SIZE, ' ')) {
			transform(word, (word + strlen(word)), word, ::toupper);

			if(strcmp(word, choice) == 0) {
				//cout << "Word found!" << endl;
				count++;
			
				while(environ[lines]) {
					transform(environ[lines], (environ[lines] + strlen(environ[lines])), environment, ::toupper);
					if(strstr(environment, word)) cout << environ[lines] << endl;
					lines++;
				}

				//Incrememnt numLine for each newline character we find.

				//And print out the corresponding line.

			}



		}
	 
	 	//Then print out how many times the string appeared.
		cout << "Found " << count << " results!\n";
		cout << endl;
		cout << "Please enter a string to search or \"END\" to quit. \n";
		cin >> choice;
		transform(choice, (choice + strlen(choice)), choice, ::toupper);

		ss.str(ss.str());
		ss.seekp(0, ss.beg);
		ss.seekg(0, ss.beg);
		ss.clear();

		count = 0;

	}

	//delete environment;
	delete choice;
	delete word;

	return;
}