当前位置: 首页>>代码示例>>C++>>正文


C++ JsonWriter::write方法代码示例

本文整理汇总了C++中JsonWriter::write方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonWriter::write方法的具体用法?C++ JsonWriter::write怎么用?C++ JsonWriter::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonWriter的用法示例。


在下文中一共展示了JsonWriter::write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: saveUserConfig

bool NodeConfigManager::saveUserConfig(UserId userId)
{
   // FIXME: do we need locking for load/save/get/remove?
   bool rval;
   string path;
   rval = getUserConfigPath(this, userId, path);
   if(rval)
   {
      MO_CAT_DEBUG(BM_NODE_CAT,
         "NodeConfigManager: save user config: id=%" PRIu64 ", path=%s",
         userId, path.c_str());
      // FIXME: how to check if config is "empty" of useful data?
      Config c = getUserConfig(userId, true);
      File file(path.c_str());
      rval = file->mkdirs();
      if(rval)
      {
         FileOutputStream fos(file);
         JsonWriter writer;
         writer.setCompact(false);
         rval = writer.write(c, &fos);
         fos.close();
      }
   }
   return true;
}
开发者ID:digitalbazaar,项目名称:bitmunk,代码行数:26,代码来源:NodeConfigManager.cpp

示例2: mos

bool Id3v2TagFrameIO::getContractData(
   ByteBuffer* b, uint32_t* uncompressed, uint32_t* compressed)
{
   bool rval;

   // create output stream
   OutputStream* os = (b == NULL) ?
      static_cast<OutputStream*>(new NullOutputStream()) :
      static_cast<OutputStream*>(new ByteArrayOutputStream(b, false));

   // zlib-compress data
   Deflater def;
   def.startDeflating(-1, false);
   MutatorOutputStream mos(os, true, &def, false);

   // produce JSON-formatted contract data
   JsonWriter writer;
   writer.setCompact(true);
   rval = writer.write(mContract, &mos);
   mos.close();

   // store uncompressed bytes
   if(uncompressed != NULL)
   {
      *uncompressed = def.getTotalInputBytes();
   }

   // store compressed bytes
   if(compressed != NULL)
   {
      *compressed = def.getTotalOutputBytes();
   }

   return rval;
}
开发者ID:digitalbazaar,项目名称:bitmunk,代码行数:35,代码来源:Id3v2TagFrameIO.cpp

示例3: main

int main(int argc, char* argv[]) {
    System::init();
    
    /*
     * Byte buffer
     *
     */
    ByteBuffer buffer(5);
    char abc[4] = "abc";
    buffer.write(abc,3);
    buffer.reset();
    buffer.resize(3,true);
    printf("%c\n",buffer.readByte());
    printf("%c\n",buffer.readByte());
    printf("%c\n",buffer.readByte());
    buffer.reset();

    /*
     * Canvas
     */
    Canvas canvas(640,480);
    if (!canvas.getSurface()) {
        return -1;
    }

    Thread thread("test thread", &testFunc, (void*)NULL);

    /*
     * Json Reader.
     */
    JsonReader reader;
    reader.read("res/config.json");
    Json::Value value = reader.getRoot();
    std::cout << reader.getRoot().get("verson", "1.2") << std::endl;

    JsonWriter writer;
    writer.write("res/1.json", reader.getRoot(), true);
    writer.write("res/2.json", reader.getRoot(), false);

    Shader vertex("res/shaders/vertex.glsl",Shader::ShaderType::VERTEX_SHADER);
    Shader fragment("res/shaders/fragment.glsl",Shader::ShaderType::FRAGMENT_SHADER);
    ShaderProgram shaderProgram;
    shaderProgram.addShader(&vertex);
    shaderProgram.addShader(&fragment);
    shaderProgram.link();

    Shader vertexRadialBlur("res/shaders/radialblur_vertex.glsl",Shader::ShaderType::VERTEX_SHADER);
    Shader fragmentRadialBlur("res/shaders/radialblur_fragment.glsl",Shader::ShaderType::FRAGMENT_SHADER);
    ShaderProgram radialBlur;
    radialBlur.addShader(&vertexRadialBlur);
    radialBlur.addShader(&fragmentRadialBlur);
    radialBlur.link();

    ResourcesManager resourcesManager;
    resourcesManager.loadTexture("lama1","res/lama1.png");
    resourcesManager.loadTexture("spritesheet","res/ch.png");
    resourcesManager.loadTexture("courrier","res/courrier_0.png");
    
    Sprite sprite2(resourcesManager.getTexture("lama1"));

    Rect<float> texCoords[] = { Rect<float>(32,0,32,32), Rect<float>(0,0,32,32), Rect<float>(32,0,32,32), Rect<float>(64,0,32,32)};
    unsigned int durations[] = { 100, 100, 100, 100 };
    Sprite sprite(resourcesManager.getTexture("spritesheet"));
    sprite.addAnimation("down", 4, durations, texCoords);
    sprite.setSize(128,128);
    sprite.setAnimation("down");

    SimpleScene2D scene2D(640,480);

    shared_ptr<SceneNode> node = shared_ptr<SceneNode>(new SceneNode(&vertex,&fragment));
    scene2D.addNode(node);

    for (int i = 0; i < 1; i++)
    {
        shared_ptr<SpriteActor> s = shared_ptr<SpriteActor>(new SpriteActor(sprite2));
        if (s)
        {
            node->addActor(s);
        }
    }
    node->addActor(shared_ptr<SpriteActor>(new SpriteActor(sprite)));

    BMFontReader fontReader("res/courrier.fnt");
    FontActorCreator fontActorCreator(resourcesManager,fontReader.read());
    shared_ptr<FontActor> fontActor = fontActorCreator.createFontActor("courrier", "This IS A TEXT TEST ! Hehehe", 1, 2, 2.0f, Vector4d<float>(0.2f,0.5f,1.0f,0.2f));
    node->addActor(fontActor);

    /*
    for (int i = 0; i < 5000; i++)
    {
        shared_ptr<SpriteActor> s = shared_ptr<SpriteActor>(new SpriteActor(sprite));
        if (s)
        {
            node->addActor(s);
        }
    }
    */

    InputDevicesManager& idm = canvas.getInputDevicesManager();

//.........这里部分代码省略.........
开发者ID:remeh,项目名称:mehteor,代码行数:101,代码来源:main.cpp

示例4: saveSystemUserConfig

// FIXME: This code has an issue if the config file has a changed id or
// FIXME: changed contents since it was first loaded. Just assuming this code
// FIXME: is the only code that manages the file for now.
bool NodeConfigManager::saveSystemUserConfig()
{
   bool rval;
   Config cfg = getNodeConfig();
   const char* suPath;
   string path;

   rval = !cfg.isNull();

   if(rval)
   {
      // get system user config and expand any home path
      suPath = cfg["systemUserConfig"]->getString();
      rval = expandBitmunkHomePath(suPath, path);
   }

   if(rval)
   {
      // FIXME: do we need locking for load/save/get/remove?
      MO_CAT_DEBUG(BM_NODE_CAT,
         "NodeConfigManager: save system user config: path=%s",
         path.c_str());
      // read
      File file(path.c_str());
      // new config
      Config c;
      if(file->exists())
      {
         FileInputStream fis(file);
         JsonReader reader;
         reader.start(c);
         rval = reader.read(&fis) && reader.finish();
         fis.close();
      }
      else
      {
         c[ConfigManager::VERSION] = MO_DEFAULT_CONFIG_VERSION;
         c[ConfigManager::ID] = "custom system user";
         c[ConfigManager::GROUP] = "system user";
      }
      // update
      if(rval &&
         getConfigManager()->hasConfig(c[ConfigManager::ID]->getString()))
      {
         // get old raw config
         Config active = getConfigManager()->getConfig(
            c[ConfigManager::ID]->getString(), true);
         c.merge(active, false);
      }
      // backup old file
      if(rval && file->exists())
      {
         string backupPath = path + ".bak";
         File backupFile(backupPath.c_str());
         rval = file->rename(backupFile);
      }
      // make sure dirs exist
      rval = rval && file->mkdirs();
      // write
      if(rval)
      {
         FileOutputStream fos(file);
         JsonWriter writer;
         writer.setCompact(false);
         rval = writer.write(c, &fos);
         fos.close();
      }
   }

   if(!rval)
   {
      ExceptionRef e = new Exception(
         "Could not save system user config.",
         "bitmunk.node.NodeConfigManager.ConfigError");
      e->getDetails()["path"] = path.c_str();
      Exception::push(e);
   }

   return rval;
}
开发者ID:digitalbazaar,项目名称:bitmunk,代码行数:83,代码来源:NodeConfigManager.cpp


注:本文中的JsonWriter::write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。