bool FlickrPhotoFrameSource::serializeToPb(PbPhotoFrameSource * pbSource)
{
	assert(pbSource);

	// serialize the core photoframe source properties
	if (!PhotoFrameSource::serializeToPb(pbSource))
		return false;
	
	// write the group id, tag id, user id
	pbSource->SetExtension(PbFlickrPhotoFrameSource::group_id, stdString(_groupId));
	pbSource->SetExtension(PbFlickrPhotoFrameSource::tag_id, stdString(_tag));
	pbSource->SetExtension(PbFlickrPhotoFrameSource::user_id, stdString(_userId));

	return pbSource->IsInitialized();
}
示例#2
0
stdString BenchTimer::toString()
{
    double t = runtime();
    char buf[100];

    if (t < 1.0)
        sprintf(buf, "%.3f ms", t*1000.0);
    else if (t < 60.0)
        sprintf(buf, "%.3f s", t);
    else if (t < 60.0*60.0)
    {
        int m = (int)(t/60.0);
        t -= m*60.0;
        sprintf(buf, "%d min, %.3f s", m, t);
    }
    else
    {
        int h = (int)(t/(60.0*60.0));
        t -= h*60.0*60.0;
        int m = (int)(t/60.0);
        t -= m*60.0;
        sprintf(buf, "%02d:%02d:%02.3f", h, m, t);
    }
    return stdString(buf);
}
示例#3
0
TEST_CASE test_list()
{
    printf("------------------------------------------\n");
    printf("List Test\n");
    printf("------------------------------------------\n");

    stdList<stdString> list;
    
    list.push_back(stdString("A"));
    list.push_back(stdString("B"));
    list.push_back(stdString("C"));

    printf("Dump\n");
    TEST(list.size() == 3);
    stdList<stdString>::iterator i;
    for (i = list.begin(); i!=list.end(); ++i)
    {
        printf("        %s\n", i->c_str());
    }
    
    printf("Append while traversing\n");
    i = list.begin();
    printf("        %s\n", i->c_str());
    ++i;
    list.push_back(stdString("D added while traversing"));
    for (/**/; i!=list.end(); ++i)
    {
        printf("        %s\n", i->c_str());
    }

#if 0
    printf("Delete 'A' while traversing\n");
    i = list.begin();
    // This results in crash, since we remove an element
    list.pop_front();
    // ... and then try to access the deleted element:
    printf("        %s\n", i->c_str());
    ++i;
    for (/**/; i!=list.end(); ++i)
    {
        printf("        %s\n", i->c_str());
    }
#endif

    TEST_OK;
}
示例#4
0
bool PhotoFrameSource::serializeToPb(PbPhotoFrameSource * pbSource)
{
	assert(pbSource);

	// write the current resource id
	if (_current.isValid())
		pbSource->set_current_resource_id(stdString(_current.getResourceId()));
	return pbSource->IsInitialized();
}
示例#5
0
void CString::ReleaseBuffer( int nNewLength)
{
	if (bufferTemp)
	{
        QString str = QString::fromWCharArray(bufferTemp);
        *this = stdString(bufferTemp, nNewLength == -1  ? str.length() : nNewLength).c_str();
		m_bufferTempSize = 0;
		delete [] bufferTemp;
		bufferTemp = 0;
	}
}
示例#6
0
bool LocalPhotoFrameSource::serializeToPb(PbPhotoFrameSource * pbSource)
{
	assert(pbSource);

	// serialize the core photoframe source properties
	if (!PhotoFrameSource::serializeToPb(pbSource))
		return false;
	
	// write the local file path
	pbSource->SetExtension(PbLocalPhotoFrameSource::file_path, stdString(native(_localPath)));

	return pbSource->IsInitialized();
}
示例#7
0
文件: Utils.cpp 项目: AlanCal/rstudio
// note that this function disposes the underlying CXString so it
// shouldn't be used after this call
std::string toStdString(CXString cxStr)
{
   const char* str = clang().getCString(cxStr);
   if (str != NULL)
   {
      std::string stdString(str);
      clang().disposeString(cxStr);
      return stdString;
   }
   else
   {
      return std::string();
   }
}
示例#8
0
bool PbPersistenceManager::saveScene(const QString& filePath)
{
	PbBumpTop bumptop;

	// save the header
	if (bumptop.mutable_header())
	{
		PbHeader * header = bumptop.mutable_header();

		QString buildStr;
		QTextStream stream(&buildStr);
		stream << "BumpTop,";
		stream << winOS->BumpTopEditionName(winOS->GetBumpTopEdition()) << ",";
		stream << ((GLOBAL(settings).freeOrProLevel == AL_PRO) ? "Pro," : "Free,");	
		stream << winOS->GetBuildNumber() << ",";
		stream << winOS->GetLocaleLanguage() << ",";
		stream << "win32";

		header->set_build(stdString(buildStr));
		header->set_version(atoi(SVN_VERSION_NUMBER));
	}

	// save the scene data
	if (!scnManager->serializeToPb(bumptop.mutable_scene()))
	{
		assert(false);
		return false;
	}

	// write the bumptop root to disk
	std::ofstream fileOut(filePath.utf16(), ios::trunc | ios::binary);
	if (!bumptop.SerializeToOstream(&fileOut))
	{
		fileOut.close();
		return false;
	}
	fileOut.close();
	
	bool ret = bumptop.IsInitialized();
	if (ret)
		LOG("PbPersistenceManager::saveScene successful");
	return ret;
}
示例#9
0
// very_complex_array = archiver.values(key, names[], start, end, ...)
xmlrpc_value *get_values(xmlrpc_env *env, xmlrpc_value *args, void *user)
{
#ifdef LOGFILE
    LOG_MSG("archiver.get_values\n");
#endif
    xmlrpc_value *names;
    xmlrpc_int32 key, start_sec, start_nano, end_sec, end_nano, count, how;
    xmlrpc_int32 actual_count;
    // Extract arguments
    xmlrpc_parse_value(env, args, "(iAiiiiii)",
                       &key, &names,
                       &start_sec, &start_nano, &end_sec, &end_nano,
                       &count, &how);    
    if (env->fault_occurred)
        return 0;
#ifdef LOGFILE
    LOG_MSG("how=%d, count=%d\n", (int) how, (int) count);
#endif
    if (count <= 1)
        count = 1;
    actual_count = count;
    if (count > 10000) // Upper limit to avoid outrageous requests.
        actual_count = 10000;
    // Build start/end
    epicsTime start, end;
    pieces2epicsTime(start_sec, start_nano, start);
    pieces2epicsTime(end_sec, end_nano, end);    
    // Pull names into vector for SpreadsheetReader and just because.
    xmlrpc_value *name_val;
    char *name;
    int i;
    xmlrpc_int32 name_count = xmlrpc_array_size(env, names);
    stdVector<stdString> name_vector;
    name_vector.reserve(name_count);
    for (i=0; i<name_count; ++i)
    {   // no new ref!
        name_val = xmlrpc_array_get_item(env, names, i);
        if (env->fault_occurred)
            return 0;
        xmlrpc_parse_value(env, name_val, "s", &name);
        if (env->fault_occurred)
            return 0;
        name_vector.push_back(stdString(name));
    }
    // Build results
    switch (how)
    {
        case HOW_RAW:
            return get_channel_data(env, key, name_vector, start, end,
                                    actual_count, ReaderFactory::Raw, 0.0);
        case HOW_SHEET:
            return get_sheet_data(env, key, name_vector, start, end,
                                  actual_count, ReaderFactory::Raw, 0.0);
        case HOW_AVERAGE:
            return get_sheet_data(env, key, name_vector, start, end,
                                  actual_count,
                                  ReaderFactory::Average, (end-start)/count);
        case HOW_PLOTBIN:
            // 'count' = # of bins, resulting in up to 4*count samples
            return get_channel_data(env, key, name_vector, start, end,
                                    actual_count*4,
                                    ReaderFactory::Plotbin, (end-start)/count);
        case HOW_LINEAR:
            return get_sheet_data(env, key, name_vector, start, end,
                                  actual_count,
                                  ReaderFactory::Linear, (end-start)/count);
    }
    xmlrpc_env_set_fault_formatted(env, ARCH_DAT_ARG_ERROR,
                                   "Invalid how=%d", how);
    return 0;
}
bool ArchiveDataClient::getInfo(int &version,
                                stdString &description,
                                stdVector<stdString> &how_strings,
                                stdVector<stdString> &stat_strings,
                                stdVector<SeverityInfo> &sevr_infos)
{
    xmlrpc_value *result, *hows, *stats, *sevrs, *element;
    xmlrpc_int32 num;
    xmlrpc_bool has_value, txt_stat;
    const char   *str;
    size_t       count, len, i;
    result = xmlrpc_client_call(&env, (char *)URL, "archiver.info", "()");
    if (log_fault())
        return false;
    xmlrpc_parse_value(&env, result, "{s:i,s:s#,s:A,s:A,s:A,*}",
                       "ver",  &num,
                       "desc", &str, &len,
                       "how",  &hows,
                       "stat", &stats,
                       "sevr", &sevrs);
    if (log_fault())
        return false;
    version = num;
    description.assign(str, len);
    // 'how' array
    count = xmlrpc_array_size(&env, hows);
    how_strings.reserve(count);
    for (i=0; i<count; ++i)
    {
        element = xmlrpc_array_get_item(&env, hows, i);
        if (log_fault())
            return false;
        xmlrpc_parse_value(&env, element, "s", &str);
        if (log_fault())
            return false;
        how_strings.push_back(stdString(str));
    }
    // 'stat' array
    count = xmlrpc_array_size(&env, stats);
    stat_strings.reserve(count);
    for (i=0; i<count; ++i)
    {
        element = xmlrpc_array_get_item(&env, stats, i);
        if (log_fault())
            return false;
        xmlrpc_parse_value(&env, element, "s", &str);
        if (log_fault())
            return false;
        stat_strings.push_back(stdString(str));
    }
    // 'sevr' array
    count = xmlrpc_array_size(&env, sevrs);
    stat_strings.reserve(count);
    SeverityInfo info;
    for (i=0; i<count; ++i)
    {
        element = xmlrpc_array_get_item(&env, sevrs, i);
        if (log_fault())
            return false;
        xmlrpc_parse_value(&env, element, "{s:i,s:s#,s:b,s:b,*}",
                           "num",  &num,
                           "sevr", &str, &len,
                           "has_value",  &has_value,
                           "txt_stat", &txt_stat);
        if (log_fault())
            return false;
        info.num = num;
        info.text.assign(str, len);
        info.has_value = has_value;
        info.txt_stat = txt_stat;
        sevr_infos.push_back(info);
    }
    xmlrpc_DECREF(result);
    return true;
}
示例#11
0
bool FileSystemActor::serializeToPb(PbBumpObject * pbObject)
{
	assert(pbObject);

	// NOTE: if this actor is pileized, then sync the position of this actor to the pile
	if (isPileized())
	{
		BumpObject * lastPileItem = pileizedPile->getLastItem();
		assert(lastPileItem);
		if (lastPileItem)
		{
			Vec3 pos = lastPileItem->getGlobalPosition();
			pos.y = getGlobalPosition().z;
			setGlobalPosition(pos);
		}
	}

	// serialize the core actor properties
	if (!Actor::serializeToPb(pbObject))
		return false;

	// write the full path
	pbObject->SetExtension(PbFileSystemActor::full_path, stdString(getFullPath()));
	
	// write the launch override path
	pbObject->SetExtension(PbFileSystemActor::launch_override_path, stdString(getLaunchOverride()));

	// write the texture override path
	QString overrideTexturePath;
	getTextureOverride(overrideTexturePath);
	pbObject->SetExtension(PbFileSystemActor::texture_override_path, stdString(overrideTexturePath));

	// write the pilelized state
	bool pileized = (pileizedPile != NULL);
	pbObject->SetExtension(PbFileSystemActor::pileized, pileized);

	// write the thumbnail state
	pbObject->SetExtension(PbFileSystemActor::thumbnailized, useThumbnail);

	// write the launch count
	pbObject->SetExtension(PbFileSystemActor::launch_count, useThumbnail);

	// NOTE: if the actor was pileized, then push it back underground
	if (isPileized())
		PushBelowGround(this);

	// write all the cached previous children sizes if this filesystem actor was pileized
	if (isFileSystemType(Folder))
	{
		QHashIterator<QString, Vec3> iter(_prevPileizedActorDims);
		while (iter.hasNext()) 
		{
			iter.next();
			PbFileSystemActor_PbCachedFilePathDims * dims = pbObject->AddExtension(PbFileSystemActor::prev_pileized_children_dims);
			dims->set_file_path(stdString(iter.key()));
			toPbVec3(iter.value(), dims->mutable_dims());
		}
	}

	return pbObject->IsInitialized();
}