コード例 #1
0
bool CNotificationHelper::HasNotifications(const std::string &DevIdx)
{
	std::stringstream s_str(DevIdx);
	unsigned long long idxll;
	s_str >> idxll;
	return HasNotifications(idxll);
}
コード例 #2
0
ファイル: Camera.cpp プロジェクト: htlinux/domoticza
void CCameraHandler::ReloadCameras()
{
	std::vector<std::string> _AddedCameras;
	boost::lock_guard<boost::mutex> l(m_mutex);
	m_cameradevices.clear();
	std::stringstream szQuery;
	std::vector<std::vector<std::string> > result;
	std::vector<std::vector<std::string> >::const_iterator itt;

	szQuery << "SELECT ID, Name, Address, Port, Username, Password, ImageURL FROM Cameras WHERE (Enabled == 1) ORDER BY ID";
	result=m_sql.query(szQuery.str());
	if (result.size()>0)
	{
		_log.Log(LOG_STATUS,"Camera: settings (re)loaded");
		for (itt=result.begin(); itt!=result.end(); ++itt)
		{
			std::vector<std::string> sd=*itt;

			cameraDevice citem;
			std::stringstream s_str( sd[0] );
			s_str >> citem.ID;
			citem.Name		= sd[1];
			citem.Address	= sd[2];
			citem.Port		= atoi(sd[3].c_str());
			citem.Username	= base64_decode(sd[4]);
			citem.Password	= base64_decode(sd[5]);
			citem.ImageURL	= sd[6];
			m_cameradevices.push_back(citem);
			_AddedCameras.push_back(sd[0]);
		}
	}
コード例 #3
0
ファイル: main.cpp プロジェクト: Pompeu/Competicoes
    int main()
    {
    std::string word;
    std::getline(std::cin,word);
    std::stringstream s_str(word);
    std::vector<std::string> words;

    std::string a1,b1,c1,d1;
        while (std::getline(s_str, word, ' ')){
            words.push_back(word);
           /* if(words.at(0))a1 = words.at(0);
            if(words.at(1))b1 = words.at(1);
            if(words.at(2))c1 = words.at(2);
            if(words.at(3))d1 = words.at(3);*/
        }

        /*if(word.at(0))a1 = words.at(0);
        else if(word.at(0) && word.at(1))b1 = words.at(1);
        else if(word.at(2))c1 = words.at(2);
        else if(word.at(3))d1 = words.at(3);
*/
    std::cout<<words.size();
           // std::cout<<a1<<b1<<c1<<d1;


    }
コード例 #4
0
std::vector<_tNotification> CNotificationHelper::GetNotifications(const std::string &DevIdx)
{
	std::stringstream s_str(DevIdx);
	unsigned long long idxll;
	s_str >> idxll;
	return GetNotifications(idxll);
}
コード例 #5
0
bool CNotificationHelper::HasNotifications(const std::string &DevIdx)
{
	std::stringstream s_str(DevIdx);
	uint64_t idxll;
	s_str >> idxll;
	return HasNotifications(idxll);
}
コード例 #6
0
ファイル: fio.cpp プロジェクト: barry-scott/BarrysEmacs
int EmacsFile::fio_get_line( unsigned char *buf, int len )
{
    fgets( s_str(buf), len, m_file );
    if( ferror( m_file ) )
        return -1;
    if( feof( m_file ) )
        return 0;

    return get_fixup_buffer( buf, strlen( (const char *)buf ) );
}
コード例 #7
0
ファイル: sentencepool.cpp プロジェクト: niklasfi/mu
void SentencePool::addSentence(target t, std::string s){

	std::string token;
	std::istringstream s_str(s);
	std::vector<uint>* vec_tmp = new std::vector<uint>();

	while(s_str >> token) {
		vec_tmp->push_back(elex.getWord_or_add(token));
	}

	if (t == ref)
		reference.push_back(vec_tmp);
	else
		guess.push_back(vec_tmp);
}
コード例 #8
0
ファイル: JSBuffer.cpp プロジェクト: pec1985/hyperloop
/**
 * putString
 */
JSValueRef putStringForJSBuffer (JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    BUFFER(buffer);
    ARGCOUNTMIN(1);
    auto string = HyperloopToString(ctx,arguments[0]);
    if (string!=nullptr)
    {
		std::wstring w_str(string->Begin());
		std::string s_str(w_str.begin(), w_str.end());
        const char *copy = s_str.c_str();
        size_t length = strlen(copy);
        CHECK_SIZE_AND_GROW(length,0);
        memcpy(buffer->buffer,copy,length);
    }
    return JSValueMakeUndefined(ctx);
}
コード例 #9
0
ファイル: SBFSpot.cpp プロジェクト: AbsolutK/domoticz
void CSBFSpot::ImportOldMonthData()
{
	_log.Log(LOG_STATUS, "SBFSpot Import Old Month Data: Start");
	//check if this device exists in the database, if not exit
	bool bDeviceExits = true;
	std::vector<std::vector<std::string> > result;
	result = m_sql.safe_query("SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Type==%d) AND (Subtype==%d)",
		m_HwdID, "00000001", int(pTypeGeneral), int(sTypeKwh));
	if (result.size() < 1)
	{
		//Lets create the sensor, and try again
		SendMeter(0, 1, 0, 0, "SolarMain");
		result = m_sql.safe_query("SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Type==%d) AND (Subtype==%d)",
			m_HwdID, "00000001", int(pTypeGeneral), int(sTypeKwh));
		if (result.size() < 1)
		{
			_log.Log(LOG_ERROR, "SBFSpot Import Old Month Data: FAILED - Cannot find sensor in database");
			return;
		}
	}
	unsigned long long ulID;
	std::stringstream s_str(result[0][0]);
	s_str >> ulID;

	//Try actual year, and previous year
	time_t atime = time(NULL);
	struct tm ltime;
	localtime_r(&atime, &ltime);

	int totyearsback = 2;

	int startYear = ltime.tm_year + 1900 - totyearsback;
	for (int iYear = startYear; iYear != startYear + 1 + totyearsback; iYear++)
	{
		for (int iMonth = 1; iMonth != 12+1; iMonth++)
		{
			ImportOldMonthData(ulID,iYear, iMonth);
		}
	}
	_log.Log(LOG_STATUS, "SBFSpot Import Old Month Data: Complete");
}
コード例 #10
0
void CScheduler::ReloadSchedules()
{
	boost::lock_guard<boost::mutex> l(m_mutex);
	m_scheduleitems.clear();

	std::stringstream szQuery;
	std::vector<std::vector<std::string> > result;

	//Add Device Timers
	szQuery << "SELECT T1.DeviceRowID, T1.Time, T1.Type, T1.Cmd, T1.Level, T1.Days, T2.Name, T2.Used, T1.UseRandomness, T1.Hue, T1.[Date] FROM Timers as T1, DeviceStatus as T2 WHERE ((T1.Active == 1) AND (T1.TimerPlan == " << m_sql.m_ActiveTimerPlan << ") AND (T2.ID == T1.DeviceRowID)) ORDER BY T1.ID";
	result = m_sql.query(szQuery.str());
	if (result.size() > 0)
	{
		std::vector<std::vector<std::string> >::const_iterator itt;
		for (itt = result.begin(); itt != result.end(); ++itt)
		{
			std::vector<std::string> sd = *itt;

			bool bDUsed = (atoi(sd[7].c_str()) != 0);

			if (bDUsed == true)
			{
				tScheduleItem titem;

				titem.bEnabled = true;
				titem.bIsScene = false;
				titem.bIsThermostat = false;

				_eTimerType timerType = (_eTimerType)atoi(sd[2].c_str());

				std::stringstream s_str(sd[0]);
				s_str >> titem.RowID;

				titem.startHour = (unsigned char)atoi(sd[1].substr(0, 2).c_str());
				titem.startMin = (unsigned char)atoi(sd[1].substr(3, 2).c_str());
				titem.startTime = 0;
				titem.timerType = timerType;
				titem.timerCmd = (_eTimerCommand)atoi(sd[3].c_str());
				titem.Level = (unsigned char)atoi(sd[4].c_str());
				titem.bUseRandmoness = (atoi(sd[8].c_str()) != 0);
				titem.Hue = atoi(sd[9].c_str());

				if (timerType == TTYPE_FIXEDDATETIME)
				{
					std::string sdate = sd[10];
					if (sdate.size() != 10)
						continue; //invalid
					titem.startYear = (unsigned short)atoi(sdate.substr(0, 4).c_str());
					titem.startMonth = (unsigned char)atoi(sdate.substr(5, 2).c_str());
					titem.startDay = (unsigned char)atoi(sdate.substr(8, 2).c_str());
				}

				if ((titem.timerCmd == TCMD_ON) && (titem.Level == 0))
				{
					titem.Level = 100;
				}
				titem.Days = atoi(sd[5].c_str());
				titem.DeviceName = sd[6];
				if (AdjustScheduleItem(&titem, false) == true)
					m_scheduleitems.push_back(titem);
			}
			else
			{
コード例 #11
0
ファイル: 21.string.op.plus.cpp プロジェクト: Quna/mspdev
void test_op_plus (charT, Traits*, Allocator*,
                   const StringFunc     &func,
                   const StringTestCase &tcase)
{
    typedef std::basic_string <charT, Traits, Allocator> String;
    typedef typename UserTraits<charT>::MemFun           UTMemFun;

    static const std::size_t BUFSIZE = 256;

    static charT wstr_buf [BUFSIZE];
    static charT warg_buf [BUFSIZE];

    std::size_t str_len = sizeof wstr_buf / sizeof *wstr_buf;
    std::size_t arg_len = sizeof warg_buf / sizeof *warg_buf;

    charT* wstr = rw_expand (wstr_buf, tcase.str, tcase.str_len, &str_len);
    charT* warg = rw_expand (warg_buf, tcase.arg, tcase.arg_len, &arg_len);

    static charT wres_buf [BUFSIZE];
    std::size_t res_len = sizeof wres_buf / sizeof *wres_buf;
    charT* wres = rw_expand (wres_buf, tcase.res, tcase.nres, &res_len);

    // construct the string object to be modified
    // and the (possibly unused) argument string
    /* const */ String  s_str (wstr, str_len);
    const       String  s_arg (warg, arg_len);

    if (wstr != wstr_buf)
        delete[] wstr;

    if (warg != warg_buf)
        delete[] warg;

    wstr = 0;
    warg = 0;

    String s_res;

    // save the state of the string object before the call
    // to detect wxception safety violations (changes to
    // the state of the object after an exception)
    const StringState str_state (rw_get_string_state (s_res));

    const charT* const arg1_ptr = tcase.str ? s_str.c_str () : s_arg.c_str ();
    const String&      arg1_str = tcase.str ? s_str : s_arg;
    const charT* const arg2_ptr = tcase.arg ? s_arg.c_str () : s_str.c_str ();
    const String&      arg2_str = tcase.arg ? s_arg : s_str;
    const charT        arg_val = make_char (char (tcase.val), (charT*)0);

    std::size_t total_length_calls = 0;
    std::size_t n_length_calls = 0;
    std::size_t* const rg_calls = rw_get_call_counters ((Traits*)0, (charT*)0);

    if (rg_calls)
        total_length_calls = rg_calls [UTMemFun::length];

    rwt_free_store* const pst = rwt_get_free_store (0);
    SharedAlloc*    const pal = SharedAlloc::instance ();

    // iterate for`throw_after' starting at the next call to operator new,
    // forcing each call to throw an exception, until the function finally
    // succeeds (i.e, no exception is thrown)
    std::size_t throw_count;
    for (throw_count = 0; ; ++throw_count) {

        // (name of) expected and caught exception
        const char* expected = 0;
        const char* caught   = 0;

#ifndef _RWSTD_NO_EXCEPTIONS

        if (0 == tcase.bthrow) {
            // by default excercise the exception safety of the function
            // by iteratively inducing an exception at each call to operator
            // new or Allocator::allocate() until the call succeeds
            expected = exceptions [3];      // bad_alloc
            *pst->throw_at_calls_ [0] = pst->new_calls_ [0] + throw_count + 1;
            pal->throw_at_calls_ [pal->m_allocate] =
                pal->throw_at_calls_ [pal->m_allocate] + throw_count + 1;
        }
        else {
            // exceptions disabled for this test case
        }

#else   // if defined (_RWSTD_NO_EXCEPTIONS)

    if (tcase.bthrow) {
        if (wres != wres_buf)
            delete[] wres;

        return;
    }

#endif   // _RWSTD_NO_EXCEPTIONS

        // start checking for memory leaks
        rw_check_leaks (s_res.get_allocator ());

        try {

            switch (func.which_) {
            case OpPlus (cptr_cstr): 
                s_res = arg1_ptr + arg2_str;
                if (rg_calls)
                    n_length_calls = rg_calls [UTMemFun::length];
                break;
            
            case OpPlus (cstr_cstr): 
                s_res = arg1_str + arg2_str;
                break;
            
            case OpPlus (cstr_cptr): 
                s_res = arg1_str + arg2_ptr;
                if (rg_calls)
                    n_length_calls = rg_calls [UTMemFun::length];
                break;
            
            case OpPlus (cstr_val): 
                s_res = arg1_str + arg_val;
                break;
            
            case OpPlus (val_cstr): 
                s_res = arg_val + arg2_str;
                break;

            default:
                RW_ASSERT ("test logic error: unknown operator+ overload");
                return;
            }

            // verfiy that strings length are equal
            rw_assert (res_len == s_res.size (), 0, tcase.line,
                       "line %d. %{$FUNCALL} expected %{#*s} "
                       "with length %zu, got %{/*.*Gs} with length %zu",
                       __LINE__, int (tcase.nres), tcase.res, res_len,
                       int (sizeof (charT)), int (s_res.size ()),
                       s_res.c_str (), s_res.size ());

            if (res_len == s_res.size ()) {
                // if the result length matches the expected length
                // (and only then), also verify that the modified
                // string matches the expected result
                const std::size_t match =
                    rw_match (tcase.res, s_res.c_str(), s_res.size ());

                rw_assert (match == res_len, 0, tcase.line,
                           "line %d. %{$FUNCALL} expected %{#*s}, "
                           "got %{/*.*Gs}, difference at offset %zu",
                           __LINE__, int (tcase.nres), tcase.res,
                           int (sizeof (charT)), int (s_res.size ()),
                           s_res.c_str (), match);
            }

            // verify that Traits::length was used
            if ((OpPlus (cptr_cstr) == func.which_ 
              || OpPlus (cstr_cptr) == func.which_) && rg_calls) {
                    rw_assert (n_length_calls - total_length_calls > 0, 
                               0, tcase.line, "line %d. %{$FUNCALL} doesn't "
                               "use traits::length()", __LINE__);
            }
        }

#ifndef _RWSTD_NO_EXCEPTIONS

        catch (const std::bad_alloc &ex) {
            caught = exceptions [3];
            rw_assert (0 == tcase.bthrow, 0, tcase.line,
                       "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
                       "unexpectedly%{;} caught std::%s(%#s)",
                       __LINE__, 0 != expected, expected, caught, ex.what ());
        }
        catch (const std::exception &ex) {
            caught = exceptions [4];
            rw_assert (0, 0, tcase.line,
                       "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
                       "unexpectedly%{;} caught std::%s(%#s)",
                       __LINE__, 0 != expected, expected, caught, ex.what ());
        }
        catch (...) {
            caught = exceptions [0];
            rw_assert (0, 0, tcase.line,
                       "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
                       "unexpectedly%{;} caught %s",
                       __LINE__, 0 != expected, expected, caught);
        }

#endif   // _RWSTD_NO_EXCEPTIONS

        // FIXME: verify the number of blocks the function call
        // is expected to allocate and detect any memory leaks
        rw_check_leaks (s_res.get_allocator (), tcase.line,
                        std::size_t (-1), std::size_t (-1));

        if (caught) {
            // verify that an exception thrown during allocation
            // didn't cause a change in the state of the object
            str_state.assert_equal (rw_get_string_state (s_res),
                                    __LINE__, tcase.line, caught);

            if (0 == tcase.bthrow) {
                // allow this call to operator new to succeed and try
                // to make the next one to fail during the next call
                // to the same function again
                continue;
            }
        }
        else if (0 < tcase.bthrow) {
            rw_assert (caught == expected, 0, tcase.line,
                       "line %d. %{$FUNCALL} %{?}expected %s, caught %s"
                       "%{:}unexpectedly caught %s%{;}",
                       __LINE__, 0 != expected, expected, caught, caught);
        }

        break;
    }

#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE

    // verify that if exceptions are enabled and when capacity changes
    // at least one exception is thrown
    const std::size_t expect_throws = str_state.capacity_ < s_res.capacity ();

#else   // if defined (_RWSTD_NO_REPLACEABLE_NEW_DELETE)

    const std::size_t expect_throws = 
        (StringIds::UserAlloc == func.alloc_id_) 
      ? str_state.capacity_ < s_res.capacity () : 0;

#endif   // _RWSTD_NO_REPLACEABLE_NEW_DELETE

    // we may got no more 2 bad_allocs
    rw_assert (expect_throws <= throw_count && throw_count <= 2, 0, tcase.line,
               "line %d: %{$FUNCALL}: expected at least 1 %s exception "
               "while changing capacity from %zu to %zu, got %zu",
               __LINE__, exceptions [3],
               str_state.capacity_, s_res.capacity (), throw_count);

    // disable bad_alloc exceptions
    *pst->throw_at_calls_ [0] = 0;
    pal->throw_at_calls_ [pal->m_allocate] = 0;

    if (wres != wres_buf)
        delete[] wres;
}