Example #1
0
result_t ValueListDataField::writeSymbols(istringstream& input,
		const unsigned char offset,
		SymbolString& output, const bool isMaster, unsigned char* usedLength)
{
	NumberDataType* numType = (NumberDataType*)m_dataType;
	if (isIgnored())
		return numType->writeRawValue(numType->getReplacement(), offset, m_length, output, usedLength); // replacement value

	const char* str = input.str().c_str();

	for (map<unsigned int, string>::iterator it = m_values.begin(); it != m_values.end(); it++)
		if (it->second.compare(str) == 0)
			return numType->writeRawValue(it->first, offset, m_length, output, usedLength);

	if (strcasecmp(str, NULL_VALUE) == 0)
		return numType->writeRawValue(numType->getReplacement(), offset, m_length, output, usedLength); // replacement value

	char* strEnd = NULL; // fall back to raw value in input
	unsigned int value;
	value = (unsigned int)strtoul(str, &strEnd, 10);
	if (strEnd == NULL || strEnd == str || (*strEnd != 0 && *strEnd != '.'))
		return RESULT_ERR_INVALID_NUM; // invalid value
	if (m_values.find(value) != m_values.end())
		return numType->writeRawValue(value, offset, m_length, output, usedLength);

	return RESULT_ERR_NOTFOUND; // value assignment not found
}
Example #2
0
void Bank::createFromXml( istringstream& is, Program& program )
{
    Document doc;
    try
    {
	    doc.Parse( is.str(), true );
        Node* root = &doc;

        Node* programNode = doc.FirstChild( "Program", false );
        if( programNode != NULL ) {
            root = programNode;
        }

	    Iterator< Element > it( "Module" );
	    for( it = it.begin( root ); it != it.end(); it++ )
	    {
		    ModuleData* data = new ModuleData();
		    Element* moduleElement = it.Get();
		    readModule( moduleElement, data );

		    program.addModule( data );
	    }
    }
    catch( const exception& e ) {
        TRACE( e.what() );
    }
}
Example #3
0
void Bank::createFromXml( istringstream& is, ProgramList& list )
{
    Document doc;
    try
    {
	    doc.Parse( is.str(), true );

        Node* moduleNode = doc.FirstChild( "Module", false );
        if( moduleNode != NULL )
        {
            Program* program = new Program();
            createFromXml( is, *program );
            list.push_back( program );
        }
        else {

	        Iterator< Element > it( "Program" );
	        for( it = it.begin( &doc ); it != it.end(); it++ )
	        {
		        Program* program = new Program();
		        Element* programElement = it.Get();
		        readProgram( programElement, program );

		        list.push_back( program );
	        }
        }
    }
    catch( const exception& e ) {
        TRACE( e.what() );
    }
}
const float& CPUPercentage::get_percentage()
{
  m_stat_file.open("/proc/stat");
  getline(m_stat_file, m_stat_line);
  m_stat_file.close();

  // skip "cpu"
  m_line_start_pos = m_stat_line.find_first_not_of(" ", 3);
  m_line_end_pos = m_stat_line.find_first_of(' ', m_line_start_pos);
  m_line_end_pos = m_stat_line.find_first_of(' ', m_line_end_pos + 1);
  m_line_end_pos = m_stat_line.find_first_of(' ', m_line_end_pos + 1);
  m_line_end_pos = m_stat_line.find_first_of(' ', m_line_end_pos + 1);
  m_iss.str(m_stat_line.substr(m_line_start_pos, m_line_end_pos - m_line_start_pos));
  m_iss >> m_next_user >> m_next_nice >> m_next_system >> m_next_idle;
  m_iss.clear();

  m_diff_user   = m_next_user - m_current_user;
  m_diff_system = m_next_system - m_current_system;
  m_diff_nice   = m_next_nice - m_current_nice;
  m_diff_idle   = m_next_idle - m_current_idle;
  m_percentage = static_cast<float>(m_diff_user + m_diff_system + m_diff_nice)/static_cast<float>(m_diff_user + m_diff_system + m_diff_nice + m_diff_idle)*100.0;

  m_current_user = m_next_user;
  m_current_system = m_next_system;
  m_current_nice = m_next_nice;
  m_current_idle = m_next_idle;

  return m_percentage;
}
Example #5
0
void AgendaUI::createMeeting(void) {
    cout  << endl << "****************" << endl << "CreateMeeting"  << endl << "***************" << endl;
    os << "[create meeting] [title] [participator] [start time(yyyy-mm-dd/hh:mm)] [end time(yyy-mm-dd/hh:mm)]" << endl;
    os << "[create meeting] ";
    res = os.str();
    strcpy(buffer, res.c_str());
    os.str("");
    __send();
    __read();
    string title, participator, startDate, endDate;
    istringstream ss(is.str());
    ss >> title >> participator >> startDate >> endDate;

    cout << "!!!!!!!!" <<  title << participator << startDate << endDate << endl;
    if (agendaService_.createMeeting(userName_, title, participator, startDate, endDate)) {
        os << "[create meeting] succeed!" << endl;
        os << endl;
        os << "Agenda@" << userName_ << " : # ";
        res = os.str();
        strcpy(buffer, res.c_str());
        os.str("");
        __send();
        input();
    } else {
        os << "[error] create meeting fail!" << endl;
        os << endl;
        os << "Agenda@" << userName_ << " : # ";
        res = os.str();
        strcpy(buffer, res.c_str());
        os.str("");
        __send();
        input();
    }
}
Example #6
0
void __read() {
//    clntAddr.sin_family = AF_INET;
//    clntAddr.sin_port = htons(6666);
//    inet_pton(AF_INET, "20.1.0.60", &clntAddr.sin_addr);
    addrLen = sizeof(toAddr);
    clear_buffer();
    is.str("");
    cout << "__reading ...." << endl;
    if ((len = recvfrom(s, buffer, 2048, 0, (struct sockaddr*)&toAddr,&addrLen))<0) {
        cout << "shit" << endl;
    }
    printf("__read from  %s with the string:\n%s\n",inet_ntoa(toAddr.sin_addr), buffer);
    cout << "__read finished" << endl;
    cout << "the client enter : " << buffer << endl;
    string tem = buffer;
    cout << "the tem is " << tem << endl;
    is.str(tem);
}
Example #7
0
bool FirecrestInput::next_cluster( int *plane, int *ptile, int *px, int* py ) 
{
    string line ;
    if( !getline( intensities_, line ) ) return false ;
    cur_line_.str( line ) ;
    cur_line_.clear() ;
    cycle_ = 0 ;
    return cur_line_ >> *plane >> *ptile >> *px >> *py ; 
}
Example #8
0
void AgendaUI::userLogIn(void) {
    cout  << endl << "****************" << endl << "login"  << endl << "***************" << endl;
    list<User> l = agendaService_.listAllUsers();
    if (l.empty()) {
        os << "[error] No User" << endl;
        res = os.str();
        strcpy(buffer, res.c_str());
        os.str("");
        __send();
        start_input();
        return;
    }
    os << endl;
    os << "[log in] [user name] [password]" << endl;
    os << "[log in] ";
    res = os.str();
    strcpy(buffer, res.c_str());
    os.str("");
    __send();
    __read();
    istringstream ss(is.str());
    ss >> userName_ >> userPassword_;

    // is >> userName_ >> userPassword_;
    cout << is.str() << endl;
    cout << "!!!!!!!!!" << userName_ << "   " << userPassword_ << endl;
    if (agendaService_.userLogIn(userName_, userPassword_)) {
        os << "[log in] succeed!" << endl;
        os << endl;
        help();
    } else {
        os << "[error] log in fail!" << endl;
        res = os.str();
        strcpy(buffer, res.c_str());
        os.str("");
        userLogIn();
    }
}
Example #9
0
void AgendaUI::queryMeetingByTimeInterval(void) {
    cout  << endl << "****************" << endl << "queryMeetingByTimeInterval"  << endl << "***************" << endl;
    os << endl;
    os << "[query meetings] [start time(yyyy-mm-dd/hh:mm)] [end time(yyyy-mm-dd/hh:mm)]" << endl;
    os << "[query meeting] ";
    res = os.str();
    strcpy(buffer, res.c_str());
    os.str("");
    __send(),  __read();;
    std::string startDate, endDate;
    // is >> startDate >> endDate;
    istringstream ss(is.str());
    ss >> startDate >> endDate;
    cout << "!!!!!" << startDate << "   " << endDate << endl;
    os << endl;
    os << left << setw(17) << "title";
    os << left << setw(17) << "sponsor";
    os << left << setw(17) << "participator";
    os << left << setw(17) << "start time";
    os << left << setw(17) << "end time" << endl;
    list<Meeting> l = agendaService_.meetingQuery(userName_, startDate, endDate);
    for (list<Meeting>::iterator it = l.begin(); it != l.end(); it++) {
        os << left << setw(17) << it->getTitle();
        os << left << setw(17) << it->getSponsor();
        os << left << setw(17) << it->getParticipator();
        os << left << setw(17) << Date::dateToString(it->getStartDate());
        os << left << setw(17) << Date::dateToString(it->getEndDate()) << endl;
    }
    os << endl;
    os << endl;
    os << "Agenda@" << userName_ << " : # ";
    res = os.str();
    strcpy(buffer, res.c_str());
    os.str("");
    __send();
    input();
}
Example #10
0
void AgendaUI::queryMeetingByTitle(void) {
    cout  << endl << "****************" << endl << "queryMeetingByTitle"  << endl << "***************" << endl;
    os << endl;
    os << "[query meeting] [title]:" << endl;
    os << "[query meeting] ";
    res = os.str();
    strcpy(buffer, res.c_str());
    os.str("");
    __send();
    __read();
    string title;
    istringstream ss(is.str());
    // is >> title;
    ss >> title;
    cout << "!!!!!!!!" << title << endl;
    os << endl;
    os << left << setw(17) << "sponsor";
    os << left << setw(17) << "participator";
    os << left << setw(17) << "start time";
    os << left << setw(17) << "end time" << endl;
    list<Meeting> l = agendaService_.meetingQuery(userName_, title);
    for (list<Meeting>::iterator it = l.begin(); it != l.end(); it++) {
        os << left << setw(17) << it->getSponsor();
        os << left << setw(17) << it->getParticipator();
        os << left << setw(17) << Date::dateToString(it->getStartDate());
        os << left << setw(17) << Date::dateToString(it->getEndDate()) << endl;
    }
    os << endl;
    os << endl;
    os << "Agenda@" << userName_ << " : # ";
    res = os.str();
    strcpy(buffer, res.c_str());
    os.str("");
    __send();
    input();
}
Example #11
0
inline const ObjIO::e_FaceFormat ObjIO::parseFaceFormat(const istringstream & line)
{
    string s(line.str());
    trim(s);

    size_t l(s.find(" "));
    if(string::npos == l)
        l = s.length();

    const size_t f0(s.find("/", 0));

    if(string::npos == f0)
        return FF_V;

    const size_t f1(s.find("/", f0 + 1));

    if(string::npos == f1 || f1 > l)
        return FF_VT;

    if(string::npos == s.find("//", 0))
        return FF_VTN;
    else
        return FF_VN;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out","w",stdout);
#endif
scanf("%d\n",&cas);
tt=0;
while(cas--){
    printf("Case #%d: ",++tt);
    bases.clear();
    getline(cin,strtmp);
    inss.clear();
    inss.str(strtmp);
    while(inss>>a){
        bases.push_back(a);
    }
    j=2;
    while(!test(j)){
        j++;
    }
    printf("%d\n",j);
}
}
Example #13
0
void assign(istringstream &iss, const string &str) {
	iss.clear();
	iss.str(str);
}
		/// \brief TODOCUMENT
		void istreams_equal_test_suite_fixture::reset_stringstreams() {
			compare_ss.str        ( compare_str        );
			compare_ss_equal.str  ( compare_str_equal  );
			compare_ss_longer.str ( compare_str_longer );
			compare_ss_diff.str   ( compare_str_diff   );
		}
Example #15
0
string OBJLoader::readStr(istringstream &input) {
	return input.str().substr(1+input.tellg());
}