本文整理汇总了C++中StringDataPtr类的典型用法代码示例。如果您正苦于以下问题:C++ StringDataPtr类的具体用法?C++ StringDataPtr怎么用?C++ StringDataPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringDataPtr类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: typeMismatchError
void
FreezeScript::TransformVisitor::visitEnum(const EnumDataPtr& dest)
{
Slice::TypePtr type = dest->getType();
if(_info->doDefaultTransform(type))
{
string name;
EnumDataPtr e = EnumDataPtr::dynamicCast(_src);
if(e && isCompatible(type, _src->getType()))
{
name = e->toString();
}
else
{
StringDataPtr s = StringDataPtr::dynamicCast(_src);
if(s)
{
name = s->getValue();
}
else
{
typeMismatchError(type, _src->getType());
return;
}
}
if(!dest->setValueAsString(name))
{
conversionError(type, _src->getType(), name);
}
}
_info->executeCustomTransform(dest, _src);
}
示例2: conversionError
void
FreezeScript::TransformVisitor::visitInteger(const IntegerDataPtr& dest)
{
Slice::TypePtr type = dest->getType();
if(_info->doDefaultTransform(type))
{
IntegerDataPtr i = IntegerDataPtr::dynamicCast(_src);
if(i)
{
dest->setValue(i->getValue(), false);
}
else
{
StringDataPtr s = StringDataPtr::dynamicCast(_src);
if(s)
{
string str = s->getValue();
Ice::Long value;
if(IceUtil::stringToInt64(str, value))
{
dest->setValue(value, false);
}
else
{
conversionError(type, _src->getType(), str);
}
}
else
{
typeMismatchError(type, _src->getType());
}
}
}
_info->executeCustomTransform(dest, _src);
}
示例3: if
void
FreezeScript::AssignVisitor::visitBoolean(const BooleanDataPtr& dest)
{
StringDataPtr s = StringDataPtr::dynamicCast(_src);
if(s)
{
string v = s->getValue();
if(v == "true")
{
dest->setValue(true);
}
else if(v == "false")
{
dest->setValue(false);
}
else
{
conversionError(dest->getType(), _src->getType(), v);
}
}
else
{
dest->setValue(_src->booleanValue(_convert));
}
}
示例4: strtod
void
FreezeScript::TransformVisitor::visitDouble(const DoubleDataPtr& dest)
{
Slice::TypePtr type = dest->getType();
if(_info->doDefaultTransform(type))
{
DoubleDataPtr d = DoubleDataPtr::dynamicCast(_src);
if(d)
{
dest->setValue(d->doubleValue());
}
else
{
StringDataPtr s = StringDataPtr::dynamicCast(_src);
if(s)
{
string str = s->stringValue();
const char* start = str.c_str();
char* end;
double v = strtod(start, &end);
if(errno == ERANGE)
{
rangeError(str, type);
}
else
{
while(*end)
{
if(!isspace(*end))
{
conversionError(type, _src->getType(), str);
return;
}
end++;
}
if(!*end)
{
dest->setValue(v);
}
}
}
else
{
typeMismatchError(type, _src->getType());
}
}
}
_info->executeCustomTransform(dest, _src);
}
示例5: rangeError
void
FreezeScript::AssignVisitor::visitEnum(const EnumDataPtr& dest)
{
Slice::TypePtr type = dest->getType();
IntegerDataPtr i = IntegerDataPtr::dynamicCast(_src);
if(i)
{
if(_convert)
{
Ice::Long l = i->integerValue();
if(l < 0 || l > INT_MAX || !dest->setValue(static_cast<Ice::Int>(l)))
{
rangeError(i->toString(), type);
}
}
else
{
conversionError(type, i->getType(), i->toString());
}
}
else
{
string name;
EnumDataPtr e = EnumDataPtr::dynamicCast(_src);
if(e && isCompatible(type, _src->getType()))
{
name = e->toString();
}
else
{
StringDataPtr s = StringDataPtr::dynamicCast(_src);
if(s)
{
name = s->getValue();
}
else
{
typeMismatchError(type, _src->getType());
}
}
if(!dest->setValueAsString(name))
{
conversionError(type, _src->getType(), name);
}
}
}
示例6: typeMismatchError
void
FreezeScript::AssignVisitor::visitProxy(const ProxyDataPtr& dest)
{
ProxyDataPtr p = ProxyDataPtr::dynamicCast(_src);
if(p)
{
dest->setValue(p->getValue());
}
else
{
StringDataPtr s = StringDataPtr::dynamicCast(_src);
if(s)
{
dest->setValue(s->getValue(), false);
}
else
{
typeMismatchError(dest->getType(), _src->getType());
}
}
}
示例7: if
void
FreezeScript::TransformVisitor::visitBoolean(const BooleanDataPtr& dest)
{
Slice::TypePtr type = dest->getType();
if(_info->doDefaultTransform(type))
{
BooleanDataPtr b = BooleanDataPtr::dynamicCast(_src);
if(b)
{
dest->setValue(b->getValue());
}
else
{
StringDataPtr s = StringDataPtr::dynamicCast(_src);
if(s)
{
string v = s->getValue();
if(v == "true")
{
dest->setValue(true);
}
else if(v == "false")
{
dest->setValue(false);
}
else
{
conversionError(type, _src->getType(), v);
}
}
else
{
typeMismatchError(type, _src->getType());
}
}
}
_info->executeCustomTransform(dest, _src);
}
示例8:
void
FreezeScript::AssignVisitor::visitString(const StringDataPtr& dest)
{
dest->setValue(_src->stringValue(_convert));
}
示例9: find
bool
FreezeScript::invokeMemberFunction(const string& name, const DataPtr& target, const DataList& args, DataPtr& result,
const DataFactoryPtr& factory, const ErrorReporterPtr& errorReporter)
{
//
// string
//
StringDataPtr targetStr = StringDataPtr::dynamicCast(target);
if(targetStr)
{
if(name == "find")
{
StringDataPtr argData;
IntegerDataPtr startData;
if(args.size() > 0)
{
argData = StringDataPtr::dynamicCast(args[0]);
}
if(args.size() > 1)
{
startData = IntegerDataPtr::dynamicCast(args[1]);
}
if(args.size() == 0 || args.size() > 2 || !argData || (args.size() == 2 && !startData))
{
errorReporter->error("invalid arguments to find(string str[, int len])");
}
string targ = targetStr->stringValue();
string arg = argData->stringValue();
string::size_type pos;
if(startData)
{
string::size_type start = static_cast<string::size_type>(startData->integerValue());
pos = targ.find(arg, start);
}
else
{
pos = targ.find(arg);
}
result = factory->createInteger(pos == string::npos ? -1 : static_cast<Ice::Long>(pos), false);
return true;
}
else if(name == "substr")
{
IntegerDataPtr startData;
IntegerDataPtr lenData;
if(args.size() > 0)
{
startData = IntegerDataPtr::dynamicCast(args[0]);
}
if(args.size() > 1)
{
lenData = IntegerDataPtr::dynamicCast(args[1]);
}
if(args.size() == 0 || args.size() > 2 || !startData || (args.size() == 2 && !lenData))
{
errorReporter->error("invalid arguments to substr(int start[, int len])");
}
string targ = targetStr->stringValue();
string::size_type start = static_cast<string::size_type>(startData->integerValue());
string::size_type len = string::npos;
if(lenData)
{
len = static_cast<string::size_type>(lenData->integerValue());
}
if(start > targ.size())
{
ostringstream ostr;
ostr << "substr() starting position (" << start << ") is greater than string length ("
<< targ.size() << ")";
errorReporter->error(ostr.str());
}
result = factory->createString(targ.substr(start, len), false);
return true;
}
else if(name == "replace")
{
IntegerDataPtr startData;
IntegerDataPtr lenData;
StringDataPtr strData;
if(args.size() == 3)
{
startData = IntegerDataPtr::dynamicCast(args[0]);
lenData = IntegerDataPtr::dynamicCast(args[1]);
strData = StringDataPtr::dynamicCast(args[2]);
}
if(args.size() != 3 || !startData || !lenData || !strData)
{
errorReporter->error("invalid arguments to replace(int start, int len, string val)");
}
string targ = targetStr->stringValue();
string::size_type start = static_cast<string::size_type>(startData->integerValue());
string::size_type len = static_cast<string::size_type>(lenData->integerValue());
string str = strData->stringValue();
if(start > targ.size())
{
ostringstream ostr;
ostr << "replace() starting position (" << start << ") is greater than string length ("
<< targ.size() << ")";
errorReporter->error(ostr.str());
}
//.........这里部分代码省略.........
示例10: if
bool
FreezeScript::invokeGlobalFunction(const Ice::CommunicatorPtr& communicator, const string& name, const DataList& args,
DataPtr& result, const DataFactoryPtr& factory,
const ErrorReporterPtr& errorReporter)
{
//
// Global function.
//
if(name == "typeOf")
{
if(args.size() != 1)
{
errorReporter->error("typeOf() requires one argument");
}
result = factory->createString(typeToString(args.front()->getType()), false);
return true;
}
else if(name == "generateUUID")
{
if(args.size() != 0)
{
errorReporter->error("generateUUID() accepts no arguments");
}
result = factory->createString(IceUtil::generateUUID(), false);
return true;
}
else if(name == "stringToIdentity")
{
StringDataPtr str;
if(args.size() > 0)
{
str = StringDataPtr::dynamicCast(args.front());
}
if(args.size() != 1 || !str)
{
errorReporter->error("stringToIdentity() requires a string argument");
}
//
// Parse the identity string.
//
string idstr = str->stringValue();
Ice::Identity id;
try
{
id = communicator->stringToIdentity(idstr);
}
catch(const Ice::IdentityParseException& ex)
{
errorReporter->error("error in stringToIdentity():\n" + ex.str);
}
//
// Create a data representation of Ice::Identity.
//
Slice::UnitPtr unit = str->getType()->unit();
Slice::TypeList l = unit->lookupType("::Ice::Identity", false);
assert(!l.empty());
DataPtr identity = factory->create(l.front(), false);
StringDataPtr member;
member = StringDataPtr::dynamicCast(identity->getMember("name"));
assert(member);
member->setValue(id.name);
member = StringDataPtr::dynamicCast(identity->getMember("category"));
assert(member);
member->setValue(id.category);
result = identity;
return true;
}
else if(name == "identityToString")
{
StructDataPtr identity;
if(args.size() > 0)
{
identity = StructDataPtr::dynamicCast(args.front());
}
if(identity)
{
Slice::TypePtr argType = identity->getType();
Slice::StructPtr st = Slice::StructPtr::dynamicCast(argType);
if(!st || st->scoped() != "::Ice::Identity")
{
identity = 0;
}
}
if(args.size() != 1 || !identity)
{
errorReporter->error("identityToString() requires a argument of type ::Ice::Identity");
}
//
// Compose the identity.
//
Ice::Identity id;
StringDataPtr member;
member = StringDataPtr::dynamicCast(identity->getMember("name"));
assert(member);
id.name = member->stringValue();
member = StringDataPtr::dynamicCast(identity->getMember("category"));
assert(member);
//.........这里部分代码省略.........