本文整理汇总了C++中slice函数的典型用法代码示例。如果您正苦于以下问题:C++ slice函数的具体用法?C++ slice怎么用?C++ slice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了slice函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: version
Foam::masterCollatingOFstream::~masterCollatingOFstream()
{
autoPtr<OSstream> osPtr;
if (UPstream::master())
{
// Note: always write binary. These are strings so readable
// anyway. They have already be tokenised on the sending side.
osPtr.reset
(
new OFstream
(
pathName_,
IOstream::BINARY,
version(),
IOstream::UNCOMPRESSED //compression_
)
);
//writeHeader(osPtr());
// We don't have IOobject so cannot use writeHeader
OSstream& os = osPtr();
IOobject::writeBanner(os)
<< "FoamFile\n{\n"
<< " version " << version() << ";\n"
<< " format " << os.format() << ";\n"
<< " class " << decomposedBlockData::typeName << ";\n"
<< " location " << pathName_ << ";\n"
<< " object " << pathName_.name() << ";\n"
<< "}" << nl;
IOobject::writeDivider(os) << nl;
}
string s(str());
UList<char> slice(const_cast<char*>(s.data()), label(s.size()));
List<std::streamoff> start;
decomposedBlockData::writeBlocks(osPtr, start, slice, commsType_);
if (osPtr.valid() && !osPtr().good())
{
FatalIOErrorInFunction(osPtr())
<< "Failed writing to " << pathName_ << exit(FatalIOError);
}
}
开发者ID:mattijsjanssens,项目名称:mattijs-extensions,代码行数:44,代码来源:masterCollatingOFstream.C
示例2: slice
// extracts rules of the form Target <= {(Src_1,Dt_1),..,(Src_n,Dt_n)}
// for deltaTimes Dt_1 < .. < Dt_n
void Correlator::extract_rules(JacobianRules& rules, uint64_t episode_size)
{
uint64_t num_calls = episode_size - SLICE_SIZE;
rules.reserve(num_calls);
JacobianSlice slice(SLICE_SIZE, LSTMState(32));
for (int64_t t = num_calls - 1; t >= 0; --t) {
// perform sensitivity analysis
corcor.getJacobian(t, t + SLICE_SIZE, slice);
// the last one is the target
JacobianRule rule;
rule.target = findBestMatch(slice.back().begin(), rule.confidence);
if (rule.confidence < OBJECT_THR) {
continue;
}
// the later objects occurred closer to the target, so iterate in reverse
JacobianSlice::reverse_iterator it = ++slice.rbegin();
JacobianSlice::reverse_iterator end = slice.rend();
for (uint16_t deltaTime = 1; it != end; ++it, ++deltaTime) {
double match;
r_code::Code* source = findBestMatch(it->begin(), match);
// no confidence, no correlation
if (match >= OBJECT_THR) {
Source src;
src.source = source;
src.deltaTime = deltaTime;
rule.sources.push_back(src);
rule.confidence += match;
}
}
if (!rule.sources.empty()) {
rule.confidence /= rule.sources.size() + 1;
if (rule.confidence >= RULE_THR) {
rules.push_back(rule);
}
}
}
}
开发者ID:sandsmark,项目名称:replicode,代码行数:46,代码来源:correlator.cpp
示例3: log_error
int SSDBImpl::getset(const Bytes &key, std::string *val, const Bytes &newval, char log_type){
if(key.empty()){
log_error("empty key!");
//return -1;
return 0;
}
Transaction trans(binlogs);
int found = this->get(key, val);
std::string buf = encode_kv_key(key);
binlogs->Put(buf, slice(newval));
binlogs->add_log(log_type, BinlogCommand::KSET, buf);
leveldb::Status s = binlogs->commit();
if(!s.ok()){
log_error("set error: %s", s.ToString().c_str());
return -1;
}
return found;
}
开发者ID:cuixin,项目名称:ssdb,代码行数:19,代码来源:t_kv.cpp
示例4: slice
vector<gpu::GpuMat> SimilarityAssessment::splitDatasetGPU(Handle3DDataset <imgT>dataset)
{
DATAINFO imgInfo = dataset.getDatasetInfo(0);
vector<gpu::GpuMat> datasetSlicesGPU;
for( int i = 0; i < imgInfo.resDepth; i++ )
{
unsigned short** d = dataset.getDataset(0);
Mat slice(imgInfo.resHeight,imgInfo.resWidth,CV_16UC1,d[i]);
Mat plane;
gpu::GpuMat planeGPU;
slice.convertTo(plane,CV_8UC3);
planeGPU.upload(plane);
datasetSlicesGPU.push_back(planeGPU);
}
return datasetSlicesGPU;
}
开发者ID:jggrandi,项目名称:2D_image_matching,代码行数:19,代码来源:similarityassessment.cpp
示例5: fix_types
bool scratch_programt::check_sat() {
fix_types();
add_instruction(END_FUNCTION);
#ifdef DEBUG
cout << "Checking following program for satness:" << endl;
output(ns, "scratch", cout);
#endif
symex.constant_propagation = constant_propagation;
goto_symex_statet::propagationt::valuest constants;
symex(symex_state, functions, *this);
slice(equation);
equation.convert(checker);
return (checker.dec_solve() == decision_proceduret::D_SATISFIABLE);
}
开发者ID:smaorus,项目名称:rvt,代码行数:19,代码来源:scratch_program.cpp
示例6: it
big_number leveldb_chain_keeper::end_slice_difficulty(size_t slice_begin_index)
{
big_number total_work = 0;
leveldb_iterator it(db_.block->NewIterator(leveldb::ReadOptions()));
data_chunk raw_height = uncast_type(slice_begin_index);
for (it->Seek(slice(raw_height)); it->Valid(); it->Next())
{
constexpr size_t bits_field_offset = 4 + 2 * hash_digest_size + 4;
BITCOIN_ASSERT(it->value().size() >= 84);
// Deserialize only the bits field of block header.
const char* bits_field_begin = it->value().data() + bits_field_offset;
std::string raw_bits(bits_field_begin, 4);
auto deserial = make_deserializer(raw_bits.begin(), raw_bits.end());
uint32_t bits = deserial.read_4_bytes();
// Accumulate the total work.
total_work += block_work(bits);
}
return total_work;
}
开发者ID:RagnarDanneskjold,项目名称:libbitcoin,代码行数:19,代码来源:leveldb_chain_keeper.cpp
示例7: switch
inline beziersurface<point_t>
beziervolume<point_t>::slice( boundary_t b ) const
{
switch ( b )
{
case umin : return slice ( point_type::u, 0);
case umax : return slice ( point_type::u, _points.width() - 1);
case vmin : return slice ( point_type::v, 0);
case vmax : return slice ( point_type::v, _points.height() - 1);
case wmin : return slice ( point_type::w, 0);
case wmax : return slice ( point_type::w, _points.depth() - 1);
default : throw std::runtime_error("invalid boundary type");
}
}
开发者ID:scholli,项目名称:gpucast,代码行数:14,代码来源:beziervolume_impl.hpp
示例8: old
// if sizes==0, then keep current shape
int Data::realloc(Data::Type t, const int * sizes, int n){
Data old(*this); // REV0
if(sizes){ // new shape requested
clear();
shape(sizes, n);
}
else{ // just changing type, leave shape unchanged
// Data old(*this); // REV0
clear();
shape(old.mSizes, old.maxDim());
}
if(size()){
mType = t;
mStride= 1;
switch(type()){
case Data::BOOL: mData = pointer(new bool[size()]); break;
case Data::INT: mData = pointer(new int[size()]); break;
case Data::FLOAT: mData = pointer(new float[size()]); break;
case Data::DOUBLE: mData = pointer(new double[size()]); break;
case Data::STRING: mData = pointer(new std::string[size()]); break;
default: goto end;
}
acquire(mData);
offset(0);
// if(hasData() && isNumerical()) assignAll(0); // REV0
if(hasData() && isNumerical()){
if(old.hasData()){
assign(old); // copy over as many old elements as possible
if(size() > old.size()) slice(old.size()).assignAll(0);
}
else{
assignAll(0);
}
}
}
end:
return sizeBytes() - old.sizeBytes();
}
开发者ID:eranws,项目名称:GLV,代码行数:43,代码来源:glv_model.cpp
示例9: assert
StringData* StringData::shrinkImpl(size_t len) {
assert(!isImmutable() && !hasMultipleRefs());
assert(isFlat());
assert(len <= m_len);
assert(len <= capacity());
auto const sd = Make(len);
auto const src = slice();
auto const dst = sd->mutableData();
assert(len <= src.len);
sd->setSize(len);
auto const mcret = memcpy(dst, src.ptr, len);
auto const ret = static_cast<StringData*>(mcret) - 1;
// Recalculating ret from mcret avoids a spill.
assert(ret == sd);
assert(ret->checkSane());
return ret;
}
开发者ID:Dream-Seeker,项目名称:hhvm,代码行数:20,代码来源:string-data.cpp
示例10: slice
DataType StringData::isNumericWithVal(int64_t &lval, double &dval,
int allow_errors, int* overflow) const {
if (m_hash < 0) return KindOfNull;
DataType ret = KindOfNull;
auto s = slice();
if (s.size()) {
ret = is_numeric_string(
s.data(),
s.size(),
&lval,
&dval,
allow_errors,
overflow
);
if (ret == KindOfNull && !isProxy() && allow_errors) {
m_hash |= STRHASH_MSB;
}
}
return ret;
}
开发者ID:AeroEng43,项目名称:hhvm,代码行数:20,代码来源:string-data.cpp
示例11: it
bool leveldb_chain_keeper::end_slice(size_t slice_begin_index,
block_detail_list& sliced_blocks)
{
leveldb::WriteBatch blk_batch, blk_hash_batch;
leveldb_transaction_batch tx_batch;
leveldb_iterator it(db_blocks_->NewIterator(leveldb::ReadOptions()));
data_chunk raw_depth = uncast_type(slice_begin_index);
for (it->Seek(slice(raw_depth)); it->Valid(); it->Next())
{
std::stringstream ss;
ss.str(it->value().ToString());
protobuf::Block proto_block;
proto_block.ParseFromIstream(&ss);
// Convert protobuf block header into actual block
block_type sliced_block;
if (!reconstruct_block(common_, proto_block, sliced_block))
return false;
// Add to list of sliced blocks
block_detail_ptr sliced_detail =
std::make_shared<block_detail>(sliced_block);
sliced_blocks.push_back(sliced_detail);
// Make sure to delete hash secondary index too.
hash_digest block_hash = hash_block_header(sliced_block);
// Delete block header...
blk_batch.Delete(it->key());
// And it's secondary index.
blk_hash_batch.Delete(slice_block_hash(block_hash));
// Remove txs + spends + addresses too
for (const transaction_type& block_tx: sliced_block.transactions)
if (!clear_transaction_data(tx_batch, block_tx))
return false;
}
leveldb::WriteOptions options;
// Execute batches.
db_blocks_->Write(options, &blk_batch);
db_blocks_hash_->Write(options, &blk_hash_batch);
db_txs_->Write(options, &tx_batch.tx_batch);
db_spends_->Write(options, &tx_batch.spends_batch);
db_address_->Write(options, &tx_batch.address_batch);
return true;
}
开发者ID:hellais,项目名称:libbitcoin,代码行数:41,代码来源:leveldb_chain_keeper.cpp
示例12: fix_types
bool scratch_programt::check_sat(bool do_slice)
{
fix_types();
add_instruction(END_FUNCTION);
remove_skip(*this);
update();
#ifdef DEBUG
std::cout << "Checking following program for satness:\n";
output(ns, "scratch", std::cout);
#endif
symex.constant_propagation=constant_propagation;
goto_symex_statet::propagationt::valuest constants;
symex(symex_state, functions, *this);
if(do_slice)
{
slice(equation);
}
if(equation.count_assertions()==0)
{
// Symex sliced away all our assertions.
#ifdef DEBUG
std::cout << "Trivially unsat\n";
#endif
return false;
}
equation.convert(*checker);
#ifdef DEBUG
std::cout << "Finished symex, invoking decision procedure.\n";
#endif
return (checker->dec_solve()==decision_proceduret::D_SATISFIABLE);
}
开发者ID:dcattaruzza,项目名称:cbmc,代码行数:41,代码来源:scratch_program.cpp
示例13: toString
static std::string toString(const Matrix& matrix, size_t limit)
{
if(matrix.empty())
{
return "[]";
}
if(matrix.size().size() <= 2)
{
return toString2D(matrix, limit);
}
size_t lastDimension = matrix.size().back();
std::stringstream stream;
stream << "[\n";
for(size_t i = 0; i < lastDimension; ++i)
{
auto base = matrix.size();
auto start = zeros(base);
auto end = base;
start.back() = i;
end.back() = i + 1;
auto newSize = base;
newSize.pop_back();
stream << toString(reshape(slice(matrix, start, end), newSize), limit);
stream << ",\n";
}
stream << "]";
return stream.str();
}
开发者ID:DLlearn,项目名称:persistent-rnn,代码行数:41,代码来源:matrix.cpp
示例14: create_spent_key
bool leveldb_common::fetch_spend(const output_point& spent_output,
input_point& input_spend)
{
data_chunk spent_key = create_spent_key(spent_output);
std::string raw_spend;
leveldb::Status status = db_.spend->Get(
leveldb::ReadOptions(), slice(spent_key), &raw_spend);
if (status.IsNotFound())
return false;
else if (!status.ok())
{
log_fatal(LOG_BLOCKCHAIN) << "fetch_spend: " << status.ToString();
return false;
}
const data_chunk raw_spend_data(raw_spend.begin(), raw_spend.end());
auto deserial = make_deserializer(
raw_spend_data.begin(), raw_spend_data.end());
input_spend.hash = deserial.read_hash();
input_spend.index = deserial.read_4_bytes();
return true;
}
开发者ID:kaostao,项目名称:libbitcoin,代码行数:21,代码来源:leveldb_common.cpp
示例15: main
int main(int argc, char **argv)
{
int parts = atoi(argv[3]);
const char *srcPath = argv[1];
const char *destPath = argv[2];
slice(srcPath, destPath, parts);
char **partsArr = calloc(parts, sizeof(char *));
if (!partsArr)
{
printf("No memory to allocate");
return 1;
}
int i;
for (i = 0; i < parts; i++)
{
size_t destLen = strlen(destPath);
partsArr[i] = calloc(11 + destLen, sizeof(char));
if (!partsArr[i])
{
printf("No memory to allocate");
return 1;
}
sprintf(partsArr[i], "%sPart-%d.jpg", destPath, i);
}
assemble(partsArr, destPath);
for (i = 0; i < parts; i++)
{
free(partsArr[i]);
}
free(partsArr);
return 0;
}
开发者ID:bsdemon,项目名称:C,代码行数:40,代码来源:05-SlicingFile.c
示例16: slice
void StringData::dump() const {
StringSlice s = slice();
printf("StringData(%d) (%s%s%s%d): [", _count,
isLiteral() ? "literal " : "",
isShared() ? "shared " : "",
isStatic() ? "static " : "",
s.len);
for (uint32_t i = 0; i < s.len; i++) {
char ch = s.ptr[i];
if (isprint(ch)) {
std::cout << ch;
} else {
printf("\\x%02x", ch);
}
}
#ifdef TAINTED
printf("\n");
this->getTaintDataRefConst().dump();
#endif
printf("]\n");
}
开发者ID:RepmujNetsik,项目名称:hiphop-php,代码行数:22,代码来源:string_data.cpp
示例17: size
message message::extract_impl(size_t start, message_handler handler) const {
auto s = size();
for (size_t i = start; i < s; ++i) {
for (size_t n = (s - i) ; n > 0; --n) {
auto next_slice = slice(i, n);
auto res = handler(next_slice);
if (res) {
std::vector<size_t> mapping(s);
std::iota(mapping.begin(), mapping.end(), size_t{0});
auto first = mapping.begin() + static_cast<ptrdiff_t>(i);
auto last = first + static_cast<ptrdiff_t>(n);
mapping.erase(first, last);
if (mapping.empty()) {
return message{};
}
message next{detail::decorated_tuple::make(vals_, std::move(mapping))};
return next.extract_impl(i, handler);
}
}
}
return *this;
}
开发者ID:guigra,项目名称:actor-framework,代码行数:22,代码来源:message.cpp
示例18: slice
bool leveldb_common::get_transaction(leveldb_tx_info& tx_info,
const hash_digest& tx_hash, bool read_parent, bool read_tx)
{
// First we try to read the bytes from the database.
std::string value;
leveldb::Status status = db_.tx->Get(
leveldb::ReadOptions(), slice(tx_hash), &value);
if (status.IsNotFound())
return false;
else if (!status.ok())
{
log_fatal(LOG_BLOCKCHAIN) << "get_transaction("
<< tx_hash << "): " << status.ToString();
return false;
}
// Read the parent block height and our index in that block (if neccessary).
BITCOIN_ASSERT(value.size() > 8);
if (read_parent)
{
auto deserial = make_deserializer(value.begin(), value.begin() + 8);
tx_info.height = deserial.read_4_bytes();
tx_info.index = deserial.read_4_bytes();
}
if (!read_tx)
return true;
// Read the actual transaction (if neccessary).
try
{
BITCOIN_ASSERT(value.size() > 8);
satoshi_load(value.begin() + 8, value.end(), tx_info.tx);
}
catch (end_of_stream)
{
return false;
}
BITCOIN_ASSERT(satoshi_raw_size(tx_info.tx) + 8 == value.size());
BITCOIN_ASSERT(hash_transaction(tx_info.tx) == tx_hash);
return true;
}
开发者ID:kaostao,项目名称:libbitcoin,代码行数:39,代码来源:leveldb_common.cpp
示例19: split_line
// Split a line at suitable positions to make it shorter than
// maxWidth. The line should not contain embedded line breaks.
static void split_line(const TextInfo& info,
const utf8_string& string,
coord maxWidth, text_lines_t& result)
{
size_t wordStart = 0;
size_t wordEnd = 0;
utf8_string line;
do {
wordEnd = string.find(chars::space, wordStart);
if (wordEnd == std::string::npos){
wordEnd = string.size();
}
utf8_string word = slice(string, wordStart, wordEnd);
const coord width = info.GetWidth(line + chars::space + word);
if (!line.empty() && width > maxWidth){
result.push_back(TextLine::SoftBreak(width, line + chars::space));
line.clear();
}
if (info.GetWidth(word) > maxWidth){
word = split_word(info, word, result);
}
if (!line.empty()){
line += chars::space;
}
line += word;
wordStart = wordEnd + 1;
} while (wordEnd != string.size());
if (line.size() > 1){
const utf8_string last(line + chars::space);
const coord width = info.GetWidth(last);
result.push_back(TextLine::SoftBreak(width, last));
}
}
开发者ID:lukas-ke,项目名称:faint-graphics-editor,代码行数:40,代码来源:split-string.cpp
示例20: slice
/* virtual */
void idx_rbtree::select(const type_slice where[], const_dataset::index::iterator& func) const {
type_slice key;
/*if (row.metadata() != &(table_->metadata())) {
MLOG_WARN << this << "->idx_rbtree::select use row meta data[" << row.metadata()
<< "] do not match index meta data:" << table_->metadata() << endl;
return;
}*/
if (size_ > 1) key.type = buffer_metadata::STR;
else // do not check again!!!
key.type = table_->metadata().get_cfg_entry(*idx_keys_)->type();
// key.data = processing_utils::encoding(idx_keys_, size_, ':', row);
slice keys_slice[size_];
int len = processing_utils::encoding2slice(where, size_, 1, keys_slice);
if (len < 1) return; // empty string is not as a index value! add by [email protected]
char* key_buff = new char[len];
processing_utils::encoding(keys_slice, size_, key_buff, len, ':');
key.data = slice(key_buff, len);
// cout << "idx_rbtree::select args:" << key << endl;
pair<slice_map_t::const_iterator, slice_map_t::const_iterator> ret = map_.equal_range(key);
// MLOG_DEBUG << this << "->idx_rbtree::select key=" << key
// << (ret.first == ret.second ? " not " : " ") << "found!" << endl;
delete[] key.data.data();
const_dataset::table::rows_t::size_type rownum = 0;
for (slice_map_t::const_iterator itr = ret.first; itr != ret.second; ++itr, ++rownum) {
// MLOG_DEBUG << rownum << '>' << *(table_->get(itr->second)) << endl;
if (!func(*(table_->get(itr->second)), rownum)) // table cant contains null
break;
}
#if MLOG_LEVEL < 20 && 0 // debug
cout << this << "->idx_rbtree::select index show all:" << endl;
slice_map_t::const_iterator itr = map_.begin(), end = map_.end();
for (; itr != end; ++itr) {
cout << itr->first << '=' << itr->second << endl;
}
#endif
}
开发者ID:wugang33,项目名称:cepframe,代码行数:39,代码来源:idx_rbtree.cpp
注:本文中的slice函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论