本文整理汇总了C++中value::get_int方法的典型用法代码示例。如果您正苦于以下问题:C++ value::get_int方法的具体用法?C++ value::get_int怎么用?C++ value::get_int使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类value
的用法示例。
在下文中一共展示了value::get_int方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: property_resolve
bool named_node_map::property_resolve(value const &id, unsigned /*flags*/) {
if (!id.is_int())
return false;
int uid = id.get_int();
if (uid < 0)
return false;
if (size_t(uid) >= impl_.getLength())
return false;
define_property(id, item(uid), permanent_shared_property);
return true;
}
示例2: property_resolve
bool binary::property_resolve(value const &id, unsigned /*flags*/) {
if (!id.is_int())
return false;
int uid = id.get_int();
if (uid < 0)
return false;
if (size_t(uid) >= v_data.size())
return false;
value v = element(v_data[uid]);
define_property(id.to_string(), v, permanent_shared_property);
return true;
}
示例3: get_byte
static int get_byte(value byte_) {
int byte;
if (byte_.is_int()) {
byte = byte_.get_int();
if (byte < 0 || byte > 255)
throw exception("Byte is outside the valid range for bytes");
return byte;
}
object byte_o = byte_.to_object();
if (byte_o.is_null())
throw exception("Not a valid byte");
binary &byte_bin = flusspferd::get_native<binary>(byte_o);
if (byte_bin.get_length() != 1)
throw exception("Byte must not be a non single-element Binary");
byte = byte_bin.get_const_data()[0];
return byte;
}
示例4: property_op
void named_node_map::property_op(property_mode mode, value const &id, value &x) {
int index;
if (id.is_int()) {
index = id.get_int();
} else {
this->native_object_base::property_op(mode, id, x);
return;
}
if (index < 0 || std::size_t(index) >= impl_.getLength())
throw exception("Out of bounds on NamedNodeMap", "RangeError");
switch (mode) {
case property_get:
x = item(index);
default: break;
};
}
示例5: property_op
void binary::property_op(property_mode mode, value const &id, value &x) {
int index;
if (id.is_int()) {
index = id.get_int();
} else {
this->native_object_base::property_op(mode, id, x);
return;
}
if (index < 0 || std::size_t(index) >= v_data.size())
throw exception("Out of bounds of binary");//TODO
switch (mode) {
case property_get:
x = element(v_data[index]);
break;
case property_set:
v_data[index] = get_byte(x);
break;
default: break;
};
}
示例6: split
array binary::split(value delim, object options) {
local_root_scope scope;
std::vector<binary*> delims;
// Parse the delimiter into the vector of delims.
if (delim.is_int()) { // single Number
if (delim.get_int() < 0 || delim.get_int() > 255)
throw exception("Outside byte range", "RangeError");
element_type e = delim.get_int();
delims.push_back(&create(&e, 1));
} else if (delim.is_object()) {
object obj = delim.get_object();
if (obj.is_array()) { // Array
array arr(obj);
std::size_t n = arr.length();
for (std::size_t i = 0; i < n; ++i) {
binary &new_delim =
flusspferd::create<byte_string>(
fusion::vector2<element_type*, std::size_t>(0, 0));
arguments arg;
arg.push_back(arr.get_element(i));
new_delim.do_append(arg);
if (new_delim.get_length() > 0)
delims.push_back(&new_delim);
}
} else { // Binary
binary &b = flusspferd::get_native<binary>(obj);
if (b.get_length() > 0)
delims.push_back(&b);
}
}
if (delims.empty())
throw exception("Need at least one valid delimiter");
// Options
std::size_t count = std::numeric_limits<std::size_t>::max();
bool include_delimiter = false;
// (only search options if the options object is not null)
if (!options.is_null()) {
// "count" option
value count_ = options.get_property("count");
if (!count_.is_undefined_or_null())
count = count_.to_number();
// "includeDelimiter" option
value include_delimiter_ = options.get_property("includeDelimiter");
if (!include_delimiter_.is_undefined_or_null())
include_delimiter = include_delimiter_.to_boolean();
}
// Main loop
typedef vector_type::iterator iterator;
iterator pos = v_data.begin();
array results = flusspferd::create<array>();
// Loop only through the first count-1 elements
for (std::size_t n = 1; n < count; ++n) {
// Search for the first occurring delimiter
std::size_t delim_id = delims.size();
iterator first_found = v_data.end();
for (std::size_t i = 0; i < delims.size(); ++i) {
binary &delim = *delims[i];
iterator found = std::search(
pos, v_data.end(),
delim.get_data().begin(), delim.get_data().end());
if (found < first_found) {
first_found = found;
delim_id = i;
}
}
// No delimiter found
if (delim_id == delims.size())
break;
binary &elem = create_range(pos, first_found);
// Add element
results.push(elem);
// Possible add delimiter
if (include_delimiter)
results.push(*delims[delim_id]);
// Advance position _after_ the delimiter.
pos = first_found + delims[delim_id]->get_length();
}
// Add last element, possibly containing delimiters
results.push(create_range(pos, v_data.end()));
return results;
}