Example #1
3
//unserialize l'objet
CHeroSyncEvent::CHeroSyncEvent(std::istringstream& data) 
: CEvent(EVENT_HEROSYNC), COORD_ERROR_MARGIN(50)
{
	data.read((char*)&m_dir,sizeof(UInt8));
	data.read((char*)&m_coord.x,sizeof(float));
	data.read((char*)&m_coord.y,sizeof(float));
}
Example #2
3
/// directly sends the quoted text to oss
/// and returns if a quote was found
/// empties the given buffer in to oss if one is given
/// works only if a quote char is found where the iss cursor is.
bool JLDIO::skipOverQuotes(std::ostringstream& oss, std::istringstream& iss, std::list<char> *bufferToEmpty)
{
    char charBuffer = iss.peek();
    if(charBuffer == '\'' || charBuffer == '\"')
    {
        if(bufferToEmpty && !bufferToEmpty->empty())
        {
            oss << listToString(*bufferToEmpty);
            bufferToEmpty->clear();
        }
        // std::cout<<"Skipping: ";
        char matchedChar = charBuffer;
        iss.get(charBuffer);
        assert(matchedChar == charBuffer);
        do
        {
            oss << charBuffer;
            // std::cout<<charBuffer;
        } while(iss.get(charBuffer) && charBuffer != matchedChar);
        if(iss.good())
            oss << charBuffer;
        // std::cout<<charBuffer<<"\n";
        return true;
    }
    return false;
}
Example #3
2
void factor( std::istringstream &ss, char &lookahead ) {
    if ( isDigit {}( lookahead ) ){
        int value = 0;
        do {
            value = value * 10 + ToDigit {}( lookahead );
            lookahead = ss.get();
        } while ( !ss.eof() && isDigit {} ( lookahead ) );
        print ( value );
    } else if ( lookahead == '(' ) {
        match ( ss, lookahead, '(' );
        expr( ss, lookahead );
        if( lookahead != ')' ){
            throw fail { "Expected a closing parenthesis before end of line." };
        }
        match ( ss, lookahead, ')' );
    } else if ( isWhiteSpace {} ( lookahead ) ) {
        for (;; lookahead = ss.get() ){
            if( isWhiteSpace {}( lookahead ) ) continue;
            else break;
        }
    } else {
        std::cerr << "Syntax Error: expecting a digit, got '" << lookahead << "' instead." << std::endl;
        abort();
    }
}
 // This resets the flags of streamToReset and sets its string to be
 // newString.
 inline void
 ParsingUtilities::ResetStringstream( std::istringstream& streamToReset,
                                      std::string const& newString )
 {
   streamToReset.clear();
   streamToReset.str( newString );
 }
Example #5
1
bool ossimWkt::parseObject( std::istringstream& is,
                            const std::string& prefix,
                            const std::string& object,
                            ossimKeywordlist& kwl )
{
    bool result = false;

    result = parseName( is, prefix, object, kwl );

    if ( result && is.good() )
    {
        char c;
        ossim_uint32 myObjectIndex = 0;
        ossim_uint32 paramIndex = 0;
        while ( is.good() )
        {
            is.get(c);
            if ( is.good() )
            {
                if ( c == ',' )
                {
                    parseParam( is, prefix, object, myObjectIndex, paramIndex, kwl );
                }
                else if ( (c == ']') || (c == ')') )
                {
                    break; // End of object.
                }
            }
        }

    }

    return result;
}
Example #6
0
static bool extractEnd(std::istringstream &strm, std::string &end)
{
	std::stringbuf temp;
	strm.get(temp);
	end = temp.str();
	return !strm.fail();
}
Example #7
0
int			PacketHelper::getUnreadSize(std::istringstream& st)
{
	std::streampos pos = st.tellg();
	st.seekg(0, st.end);
	int length = (int)(st.tellg() - pos);
	st.seekg(pos, st.beg);
	return length;
}
Example #8
0
/**
 * Read from input title and insert spaces into the title vector
 * @param iss       input stream
 * @param word      space word to insert
 * @param title     vector where to store the words
 */
void insert_spaces( std::istringstream& iss, std::string& word, std::vector<std::string>& title ){
  while( iss.peek() == ' ' ){
    iss.get();
    word += ' ';
  }
  if ( !word.empty() )
    title.push_back( std::move(word) );
}
 void convert( unsigned int count, std::istringstream& inputStream, T * value )
 {
   DP_ASSERT( count );
   for ( unsigned int i=0 ; i<count ; i++ )
   {
     DP_ASSERT( !inputStream.eof() && !inputStream.bad() );
     value[i] = convert<T>( inputStream );
   }
 }
Example #10
0
 bool seek(size_t v, int origin)
 {
     if (origin == SEEK_CUR)
         stream.seekg(v, std::ios_base::cur);
     else if (origin == SEEK_END)
         stream.seekg(v, std::ios_base::end);
     else
         stream.seekg(v, std::ios_base::beg);
     return !stream.fail();
 }
Example #11
0
/// moves the iss's cursor to the next non-WS char
bool JLDIO::ignoreWhiteSpace(std::istringstream& iss)
{
    char charBuffer = iss.peek();
    bool output = false;
    while(std::isspace(charBuffer))
    {
        iss.get(charBuffer);
        charBuffer = iss.peek();
        output = true;
    }
    return output;
}
Example #12
0
void match ( std::istringstream &ss, char &lookahead, const char &currToken ) noexcept
{
    if ( lookahead == currToken ){
        lookahead = ss.get();
        if( isWhiteSpace {}( lookahead ) ){
            for(;; lookahead = ss.get() ){
                if(isWhiteSpace {}( lookahead ) ) continue;
                else break;
            }
        }
    }
    //otherwise we have an epsilon production
}
 inline bool
 AsciiXmlParser::loadString( std::string const stringToParse )
 /* this loads stringToParse into the internal stringstream for parsing. if
   * there was a problem loading the file, false is returned. if there was a
   * file open, it is now closed.
   */
 {
   resetContent();
   stringParsingStream.clear();
   stringParsingStream.str( stringToParse );
   textStream = &stringParsingStream;
   return stringParsingStream.good();
 }
void skipCharacter(std::istringstream& is, char char_to_skip)
{
    for (;;) {
        int c = is.get();
        if ( !is.good() ) {
            break;
        } else {
            if (c != char_to_skip) {
                is.unget();
                break;
            }
        }
    }
}
Example #15
0
void TaskConti::
commandLine( const std::string& cmdLine
	     ,std::istringstream& cmdArgs
	     ,std::ostream& os )
{
  if( cmdLine=="help" )
    {
      os << "TaskConti: "<<endl
	 << "  - touch <sot.control>"<<endl
	 << "  - timeRef" << endl
	 << "  - mu [<val>]" << endl;

      Task::commandLine( cmdLine,cmdArgs,os );
    }
  else if( cmdLine=="touch" )
    {
      Signal<ml::Vector,int> & sig
	= dynamic_cast< Signal<ml::Vector,int>& >
	(dg::PoolStorage::getInstance()->getSignal(cmdArgs));
      timeRef = TIME_REF_TO_BE_SET; //sig.getTime();
      q0 = sig.accessCopy();
    }
  else if( cmdLine=="timeRef" )
    {
      os << "timeRef = ";
      if( timeRef == TIME_REF_TO_BE_SET ) os << "to be set.";
      else if( timeRef == TIME_REF_UNSIGNIFICANT ) os << "no signaificant";
      else os << timeRef;
      os << std::endl;
    }
  else if( cmdLine=="mu" )
    {
      cmdArgs >> std::ws; if(! cmdArgs.good() ) os << "mu = " << mu << std::endl;
      else { cmdArgs >> mu; }
    }
Example #16
0
// Parse input string stream. Read and convert a hexa-decimal number up 
// to a ``,'' or ``:'' or ``\0'' or end of stream.
uint_least32_t SidTuneTools::readHex( std::istringstream& hexin )
{
    uint_least32_t hexLong = 0;
    char c;
    do
    {
        hexin >> c;
        if ( !hexin )
            break;
        if (( c != ',') && ( c != ':' ) && ( c != 0 ))
        {
            // machine independed to_upper
            c &= 0xdf;
            ( c < 0x3a ) ? ( c &= 0x0f ) : ( c -= ( 0x41 - 0x0a ));
            hexLong <<= 4;
            hexLong |= (uint_least32_t)c;
        }
        else
        {
            if ( c == 0 )
                hexin.putback(c);
            break;
        }
    }  while ( hexin );
    return hexLong;
}
Example #17
0
void TimeStamp::
commandLine( const std::string& cmdLine,
	     std::istringstream& cmdArgs,
	     std::ostream& os )
{
  if( cmdLine=="help" )
    {
      os << "TimeStamp: "<<std::endl
	 << " - offset [{<value>|now}] : set/get the offset for double sig." << std::endl;      
      Entity::commandLine( cmdLine,cmdArgs,os );
    }
  else if( cmdLine=="offset" )
    {
      cmdArgs >> std::ws; 
      if( cmdArgs.good() )
	{ 
	  std::string offnow; 
	  cmdArgs >> offnow;  
	  if(offnow=="now") 
	    {
	      gettimeofday( &val,NULL );
	      offsetValue = val.tv_sec;
	    }
	  else { offsetValue = atoi(offnow.c_str()); }
	  offsetSet = ( offsetValue>0 );
	} else {
Example #18
0
bool JLDIO::moreItems(std::istringstream& iss, char delim)
{
    char charBuffer;
    ignoreWhiteSpace(iss);
    if(iss.peek() == ',')
    {
        iss.get(charBuffer);
        return true;
    }
    else if(iss.peek() != delim)
    {
        std::cout<<"Expected '"<<delim<<"' but found '"<<(char)iss.peek()<<"'\n";
        assert(0 && "Unexpected char");
    }
    return false;
}
Example #19
0
/**
 * @brief Recurse internal function to parse a Boolean formula from a line in the input file
 * @param is the input stream from which the tokens in the line are read
 * @param allowedTypes a list of allowed variable types - this allows to check that assumptions do not refer to 'next' output values.
 * @return a BF that represents the transition constraint read from the line
 */
BF GR1Context::parseBooleanFormulaRecurse(std::istringstream &is,std::set<VariableType> &allowedTypes, std::vector<BF> &memory) {
    std::string operation = "";
    is >> operation;
    if (operation=="") {
        SlugsException e(false);
        e << "Error reading line " << lineNumberCurrentlyRead << ". Premature end of line.";
        throw e;
    }
    if (operation=="|") return parseBooleanFormulaRecurse(is,allowedTypes,memory) | parseBooleanFormulaRecurse(is,allowedTypes,memory);
    if (operation=="^") return parseBooleanFormulaRecurse(is,allowedTypes,memory) ^ parseBooleanFormulaRecurse(is,allowedTypes,memory);
    if (operation=="&") return parseBooleanFormulaRecurse(is,allowedTypes,memory) & parseBooleanFormulaRecurse(is,allowedTypes,memory);
    if (operation=="!") return !parseBooleanFormulaRecurse(is,allowedTypes,memory);
    if (operation=="1") return mgr.constantTrue();
    if (operation=="0") return mgr.constantFalse();

    // Memory Functionality - Create Buffer
    if (operation=="$") {
        unsigned nofElements;
        is >> nofElements;
        if (is.fail()) {
            SlugsException e(false);
            e << "Error reading line " << lineNumberCurrentlyRead << ". Expected number of memory elements.";
            throw e;
        }
        std::vector<BF> memoryNew(nofElements);
        for (unsigned int i=0; i<nofElements; i++) {
            memoryNew[i] = parseBooleanFormulaRecurse(is,allowedTypes,memoryNew);
        }
        return memoryNew[nofElements-1];
    }
Example #20
0
void MotionPeriod::
commandLine( const std::string& cmdLine,
	     std::istringstream& cmdArgs,
	     std::ostream& os )
{
  if( cmdLine == "help" )
    {
      os << "MotionPeriod:"<<endl
	 <<"  - size  " <<endl
	 <<"  - period  <rank> [<value>]" <<endl
	 <<"  - amplitude  <rank> [<value>] " <<endl
	 <<"  - init  <rank> [<value>] " <<endl
	 <<"  - type  <rank> [const|sin|cos] " <<endl;
    }
//   else if( cmdLine == "period" )
//     {
//       unsigned int rank; unsigned int period; 
//       cmdArgs >> rank >>std::ws; 
//       if( rank>=this->size ) { os <<"!! Error size too large." << std::endl; }
//       if( cmdArgs.good() ) 
// 	{ cmdArgs>>period; motionParams[rank].period = period; }
//       else { os << "period[" << rank << "] = " <<  motionParams[rank].period << std::endl; }
//     }
  SOT_PARAMS_CONFIG(period,unsigned int)
    SOT_PARAMS_CONFIG(amplitude,double)
    SOT_PARAMS_CONFIG(initPeriod,unsigned int)
    SOT_PARAMS_CONFIG(initAmplitude,double)
    else if( cmdLine == "size" )
      {
	unsigned int rank(0); 
	cmdArgs >> std::ws; 
	if( cmdArgs.good() ) 
	  { cmdArgs>>rank; resize( rank ); }
Example #21
0
// format: [depth *] X [x Y]
// Depth, if omitted, defaults to zero.
// Y, if omitted, defaults to zero.
//
dxySize extractDxySize(std::istringstream &ss)
{
    char ch;
    dxySize size;
    size.depth = 1;  // Default is 1 unless otherwise specified

    ss >> size.x;   // This may actually be the depth, we'll see
    auto pos = ss.tellg();
    ss >> ch;       // Test the next non-space char
    if (ch == '*') {
        // Depth dimension
        size.depth = size.x; // That was the depth we read, not X
        size.x = 0;
        ss >> size.x;
        pos = ss.tellg();
        ss >> ch;       // Test the next non-space char
    }
Example #22
0
 SteamReadFile(const char * filename)
 {
     int32 size = SteamRemoteStorage()->GetFileSize(filename);
     std::string v;
     v.resize(size, 0);
     SteamRemoteStorage()->FileRead(filename, &v[0], size);
     stream.str(v);
 }
Example #23
0
std::string WordWrapper::readWord(std::istringstream &stream) {
  auto word = std::string{};

  // Gobble leading spaces
  while (stream.peek() == ' ' || stream.peek() == '\n') stream.ignore(1);

  while (true) {
    auto c = static_cast<char>(stream.peek());
    if (!stream) return word;
    if (c == -1) return word;

    if (c == ' ') {
      stream.ignore(1);
      return word;
    }

    if (c == '\n') {
      stream.ignore(1);
      return word + "\n";
    }

    word += c;
    stream.ignore(1);
  }
}
/*! \brief Overloading method of SimplePlugin */
void FilteringAnalyticalTrajectoryByPreviewControl::CallMethod(std::string &Method,
							       std::istringstream &strm)
{
    if (Method==":samplingperiod")
    {
      std::string aws;
      if (strm.good())
	{
	  strm >> m_SamplingPeriod;
	  Resize();
	}
void LoadArray(std::istringstream &buf, pnlVector<Type> &array, char delim = ' ')
{
    char ch;
    int ich;
    Type val;

    buf >> ch;
    ASSERT(ch == '[' || !buf.good());
    array.reserve(16);
    array.resize(0);
    for(;buf.good();)
    {
        do
        {
            ich = buf.peek();
            if(ich == ']')
            {
                buf >> ch;
                return;
            }
            else if(ich == delim || (delim == ' ' && isspace(ich)))
            {
                buf.get(ch);
            }
        } while(buf.good() && (ich == delim || (delim == ' ' && isspace(ich))));

	if(!buf.good())
	{
	    break;
	}

        buf >> val;
        array.push_back(val);
    }
Example #26
0
static void setupEnvVar(std::istringstream& iss, const char** var, const char* varname) {
  std::string line;
  std::string value;

  std::getline(iss, line);
  if (!iss.good() || line.find(varname) == std::string::npos) {
    INT_FATAL(astr("Parsing ", varname));
  }
  value = line.substr(line.find('=')+1, std::string::npos);

  *var = astr(value.c_str());  // astr call is to canonicalize
  parseCmdLineConfig(varname, astr("\"", *var, "\""));
}
Example #27
0
void rest_2( std::istringstream &ss, char &lookahead )
{
    while( !ss.eof() ){
        char tempToken = lookahead;
        if( lookahead == '*' ) {
            match( ss, lookahead, '*' );
            factor( ss, lookahead );
            print( tempToken );
        } else if ( lookahead == '/' ) {
            match ( ss, lookahead, '/' );
            factor( ss, lookahead );
            print( '/' );
        } else if ( isWhiteSpace {}( lookahead ) ) {
            for(;; lookahead = ss.get() ){
                if( isWhiteSpace {}( lookahead ) ) continue;
                else break;
            }
        } else {
            break;
        }
    }
}
Example #28
0
ErrorXmlParseFailed::ErrorXmlParseFailed(const ApiRequest& request, const std::istringstream& xmlContent)
  : ApiError() {
  status = FREDCPP_FAIL_PARSE;

  std::ostringstream buf;
  buf << "Bad Response."
      << " "
      << " XML response from API is invalid or has unexpected XML schema."
      << " request:" << request
      << " content-begin:{\n" << xmlContent.str() << "\n}:content-end"
      ;

  message = buf.str();
}
Example #29
0
Mesh_ptr GCObjLoader::meshProcess(std::istringstream &stream) {
	char buff[512];
	short len = 0;
	
	// header
	stream.read((char*)&len, sizeof(short));
	LOGI("len:%d", len);
	stream.read(buff, len);
	buff[len] = '\0';
	LOGI("str:%s", buff);
	bool usecolor = false;
	stream.read((char*)&usecolor, sizeof(bool));
	LOGI("usecolor:%d", usecolor);
	short uvnum = 0;
	stream.read((char*)&uvnum, sizeof(short));
	LOGI("uvnum:%d", uvnum);
	int vnum = 0;
	stream.read((char*)&vnum, sizeof(int));
	LOGI("vnum:%d", vnum);
	
	int size = vnum * (6 + (usecolor?3:0) + uvnum * 2) * sizeof(float);
	LOGI("size:%d", size);
	
	// data
	// TODO: バッファオーバー対策
	stream.read(buff, size);
	float *f_buf = (float*)buff;
	std::vector<float> interleaveArray(f_buf, f_buf+size);
	
	//3,3,3,2*n
	std::vector<AttribType> attribArray;
	attribArray.push_back(AttribTypeVertex);
	attribArray.push_back(AttribTypeNormal);
	if (usecolor) {
		attribArray.push_back(AttribTypeColor);
	}
	for (int i=0; i<uvnum; i++) {
		attribArray.push_back((AttribType)(AttribTypeUV0+i));
	}
	
	// index
	std::vector<short> indexArray;
	for (short i=0; i<vnum; i++) {
		indexArray.push_back(i);
	}
	
	// make
	MeshInterleaveData_ptr mdata(new MeshInterleaveData());
	mdata->data = interleaveArray;
	mdata->vertexIndexes = indexArray;
	mdata->attribs = attribArray;
	
	Mesh_ptr mesh(new Mesh());
	mesh->build(mdata);
	
	return mesh;
}
template<typename T> void me_traffic_generator::do_do_store(std::istringstream &iss) {
  tlm::tlm_generic_payload  *req_transaction_ptr = m_txn_pool.pop();

  sc_dt::uint64 addr;
  iss >> hex >> addr >> dec;

  T *buffer = (T *)m_buffer;
  int len;
  for(len=0; len < m_buffer_size; len++) {
    unsigned tmp;
    iss >> hex >> tmp >> dec;
    if(iss.fail()) break;
    *(buffer++) = T(tmp);
  }
  if(len == 0) return;

  req_transaction_ptr->set_command(tlm::TLM_WRITE_COMMAND);
  req_transaction_ptr->set_address(addr);
  req_transaction_ptr->set_data_ptr(m_buffer);
  req_transaction_ptr->set_data_length(len * sizeof(T));
  req_transaction_ptr->set_streaming_width(len * sizeof(T));
  req_transaction_ptr->set_byte_enable_ptr(0);
  req_transaction_ptr->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);

  if(m_endianness != m_host_endianness)
    tlm::tlm_to_hostendian_word<T>(req_transaction_ptr,4);

  request_out_port->write(req_transaction_ptr);
  tlm::tlm_generic_payload  *resp_transaction_ptr = response_in_port->read();

  if (resp_transaction_ptr != req_transaction_ptr) {
    std::ostringstream msg;
    msg << m_ID << "Response to wrong request";
    REPORT_FATAL(filename, __FUNCTION__, msg.str());
  }
  if (resp_transaction_ptr->get_response_status() != tlm::TLM_OK_RESPONSE) {
    std::ostringstream msg;
    msg << m_ID << "Transaction ERROR";
    REPORT_FATAL(filename, __FUNCTION__, msg.str());
  }

  if(m_endianness != m_host_endianness)
    tlm::tlm_from_hostendian_word<T>(req_transaction_ptr,4);

  std::cout << m_prompt << ":: " << "write transaction length " << len
            << " (10) x " << sizeof(T)*8 << "-bit completed" << std::endl;

  m_txn_pool.push(resp_transaction_ptr);
}