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


C++ value::is_string方法代码示例

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


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

示例1: search_namespace_by_prefix

object node::search_namespace_by_prefix(value const &prefix_) {
  local_root_scope scope;
  xmlChar const *prefix = 0; 
  if (!prefix_.is_string() && !prefix_.is_undefined() && !prefix_.is_null())
    throw exception("Could not search for non-string namespace prefix");
  if (prefix_.is_string())
    prefix = (xmlChar const *) prefix_.get_string().c_str();
  xmlNsPtr ns = xmlSearchNs(ptr->doc, ptr, prefix);
  return namespace_::create(ns);
}
开发者ID:the-kenny,项目名称:flusspferd,代码行数:10,代码来源:node.cpp

示例2: write

void stream::write(value const &data) {
  if (data.is_string()) {
    string text = data.get_string();
    char const *str = text.c_str();
    streambuf_->sputn(text.c_str(), std::strlen(str));
  } else if (data.is_object()) {
    binary &b = flusspferd::get_native<binary>(data.get_object());
    streambuf_->sputn((char const*) &b.get_data()[0], b.get_length());
  } else {
    throw exception("Cannot write non-object non-string value to Stream");
  }
  //TODO slow?
  if (get_property("autoFlush").to_boolean())
    flush();
}
开发者ID:the-kenny,项目名称:flusspferd,代码行数:15,代码来源:stream.cpp

示例3: open

void file::open(char const *name, value options) {
  security &sec = security::get();

  if (boost::filesystem::is_directory(std::string(name))) {
    throw exception(
      std::string("Could not open file: it is a directory (")+ name + ")"
    );
  }

  std::ios::openmode open_mode = std::ios::openmode();

  bool exclusive = false, create = false;

  if (options.is_string()) {
    // String modes always set create

    std::string mode = options.to_std_string();
    if (mode == "r")
      open_mode = std::ios::in;
    else if (mode == "r+")
      open_mode = std::ios::in | std::ios::out;
    else if (mode == "r+x") {
      open_mode = std::ios::in | std::ios::out;
      exclusive = create = true;
    }
    else if (mode == "w") {
      open_mode = std::ios::out;
      create = true;
    }
    else if (mode == "wx") {
      open_mode = std::ios::out;
      exclusive = create = true;
    }
    else if (mode == "w+x") {
      open_mode = std::ios::out | std::ios::in | std::ios::trunc;
      exclusive = create = true;
    }
    else {
      throw exception(format("File.open: mode '%s' not supported (yet?)") % mode);
    }
  }else if (options.is_object()) {
    object obj = options.get_object();

    create = obj.get_property("create").to_boolean();

    if (obj.get_property("read").to_boolean())
      open_mode |= std::ios::in;
    if (obj.get_property("write").to_boolean())
      open_mode |= std::ios::out;
    if (obj.get_property("truncate").to_boolean())
      open_mode |= std::ios::trunc;
    if (obj.get_property("append").to_boolean()) {
      if (!(open_mode & std::ios::out)) {
        throw exception("File.open: append mode can only be used with write");
      }
      open_mode |= std::ios::app | std::ios::out;
    }
    if (obj.get_property("exclusive").to_boolean()) {
      if (!create)
        throw exception("File.open: exclusive mode can only be used with create");
      exclusive = create = true;
    }

  }else if (options.is_undefined_or_null()) {
    open_mode = std::ios::in;
  }else {
    throw exception("File.open: Invalid options argument", "TypeError");
  }

  unsigned sec_mode = 0;

  if (open_mode & std::ios::in)  sec_mode |= security::READ;
  if (open_mode & std::ios::out) sec_mode |= security::WRITE;
  if (create)                    sec_mode |= security::CREATE;

  if (!sec.check_path(name, sec_mode)) {
    throw exception(
      format("File.open: could not open file: 'denied by security' (%s)") % name
    );
  }

  if (create) {
    // C++ streams don't support O_EXCL|O_CREAT modes. Fall back to open
    unsigned o_mode = exclusive
                    ? O_CREAT|O_EXCL
                    : O_CREAT;
    int fd = ::open(name, o_mode, 0666);
    if (fd == -1)
      throw exception(compose_error_message("File.open: couldn't create file", name));

    // Done  - got the file (exclusively) created.
    ::close(fd);
  }

  p->stream.open(name, open_mode);

  if (!p->stream)
    throw exception(compose_error_message("Could not open file", name));

  define_property("fileName", string(name),
//.........这里部分代码省略.........
开发者ID:Flusspferd,项目名称:flusspferd,代码行数:101,代码来源:file.cpp


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