本文整理汇总了C++中StringData::slice方法的典型用法代码示例。如果您正苦于以下问题:C++ StringData::slice方法的具体用法?C++ StringData::slice怎么用?C++ StringData::slice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringData
的用法示例。
在下文中一共展示了StringData::slice方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Create
APCHandle::Pair APCHandle::Create(const Variant& source,
bool serialized,
APCHandleLevel level,
bool unserializeObj) {
auto type = source.getType(); // this gets rid of the ref, if it was one
switch (type) {
case KindOfUninit: {
auto value = APCTypedValue::tvUninit();
return {value->getHandle(), sizeof(APCTypedValue)};
}
case KindOfNull: {
auto value = APCTypedValue::tvNull();
return {value->getHandle(), sizeof(APCTypedValue)};
}
case KindOfBoolean: {
auto value = source.getBoolean() ? APCTypedValue::tvTrue()
: APCTypedValue::tvFalse();
return {value->getHandle(), sizeof(APCTypedValue)};
}
case KindOfInt64: {
auto value = new APCTypedValue(source.getInt64());
return {value->getHandle(), sizeof(APCTypedValue)};
}
case KindOfDouble: {
auto value = new APCTypedValue(source.getDouble());
return {value->getHandle(), sizeof(APCTypedValue)};
}
case KindOfPersistentString:
case KindOfString: {
StringData* s = source.getStringData();
if (serialized) {
// It is priming, and there might not be the right class definitions
// for unserialization.
return APCString::MakeSerializedObject(apc_reserialize(String{s}));
}
if (s->isStatic()) {
auto value = new APCTypedValue(APCTypedValue::StaticStr{}, s);
return APCHandle::Pair{value->getHandle(), sizeof(APCTypedValue)};
}
auto const st = lookupStaticString(s);
if (st) {
auto value = new APCTypedValue(APCTypedValue::StaticStr{}, st);
return {value->getHandle(), sizeof(APCTypedValue)};
}
if (apcExtension::UseUncounted) {
auto st = StringData::MakeUncounted(s->slice());
auto value = new APCTypedValue(APCTypedValue::UncountedStr{}, st);
return {value->getHandle(), st->size() + sizeof(APCTypedValue)};
}
return APCString::MakeSharedString(s);
}
case KindOfPersistentVec:
case KindOfVec: {
auto ad = source.getArrayData();
assert(ad->isVecArray());
if (ad->isStatic()) {
auto value = new APCTypedValue(APCTypedValue::StaticVec{}, ad);
return {value->getHandle(), sizeof(APCTypedValue)};
}
return APCArray::MakeSharedVec(ad, level, unserializeObj);
}
case KindOfPersistentDict:
case KindOfDict: {
auto ad = source.getArrayData();
assert(ad->isDict());
if (ad->isStatic()) {
auto value = new APCTypedValue(APCTypedValue::StaticDict{}, ad);
return {value->getHandle(), sizeof(APCTypedValue)};
}
return APCArray::MakeSharedDict(ad, level, unserializeObj);
}
case KindOfPersistentKeyset:
case KindOfKeyset: {
auto ad = source.getArrayData();
assert(ad->isKeyset());
if (ad->isStatic()) {
auto value = new APCTypedValue(APCTypedValue::StaticKeyset{}, ad);
return {value->getHandle(), sizeof(APCTypedValue)};
}
return APCArray::MakeSharedKeyset(ad, level, unserializeObj);
}
case KindOfPersistentArray:
case KindOfArray: {
auto ad = source.getArrayData();
assert(ad->isPHPArray());
if (ad->isStatic()) {
auto value = new APCTypedValue(APCTypedValue::StaticArr{}, ad);
return {value->getHandle(), sizeof(APCTypedValue)};
}
return APCArray::MakeSharedArray(ad, level, unserializeObj);
}
//.........这里部分代码省略.........
示例2: Create
APCHandle* APCHandle::Create(const Variant& source,
size_t& size,
bool serialized,
bool inner /* = false */,
bool unserializeObj /* = false */) {
auto type = source.getType(); // this gets rid of the ref, if it was one
switch (type) {
case KindOfBoolean: {
auto value = new APCTypedValue(type,
static_cast<int64_t>(source.getBoolean()));
size = sizeof(APCTypedValue);
return value->getHandle();
}
case KindOfInt64: {
auto value = new APCTypedValue(type, source.getInt64());
size = sizeof(APCTypedValue);
return value->getHandle();
}
case KindOfDouble: {
auto value = new APCTypedValue(type, source.getDouble());
size = sizeof(APCTypedValue);
return value->getHandle();
}
case KindOfUninit:
case KindOfNull: {
auto value = new APCTypedValue(type);
size = sizeof(APCTypedValue);
return value->getHandle();
}
case KindOfStaticString: {
if (serialized) goto StringCase;
auto value = new APCTypedValue(type, source.getStringData());
size = sizeof(APCTypedValue);
return value->getHandle();
}
StringCase:
case KindOfString: {
StringData* s = source.getStringData();
if (serialized) {
// It is priming, and there might not be the right class definitions
// for unserialization.
return APCObject::MakeShared(apc_reserialize(s), size);
}
auto const st = lookupStaticString(s);
if (st) {
APCTypedValue* value = new APCTypedValue(KindOfStaticString, st);
size = sizeof(APCTypedValue);
return value->getHandle();
}
assert(!s->isStatic()); // would've been handled above
if (!inner && apcExtension::UseUncounted) {
StringData* st = StringData::MakeUncounted(s->slice());
APCTypedValue* value = new APCTypedValue(st);
size = sizeof(APCTypedValue) + st->size();
return value->getHandle();
}
return APCString::MakeShared(type, s, size);
}
case KindOfArray:
return APCArray::MakeShared(source.getArrayData(),
size,
inner,
unserializeObj);
case KindOfResource:
// TODO Task #2661075: Here and elsewhere in the runtime, we convert
// Resources to the empty array during various serialization operations,
// which does not match Zend behavior. We should fix this.
size = sizeof(APCArray);
return APCArray::MakeShared();
case KindOfObject:
return unserializeObj ?
APCObject::Construct(source.getObjectData(), size) :
APCObject::MakeShared(apc_serialize(source), size);
default:
return nullptr;
}
}