本文整理汇总了C++中DynamicObject::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ DynamicObject::getType方法的具体用法?C++ DynamicObject::getType怎么用?C++ DynamicObject::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicObject
的用法示例。
在下文中一共展示了DynamicObject::getType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _filter
/**
* Recursively filter input to output.
*
* @param filter the fitler to use.
* @param in the input object.
* @param out the filtered output object.
*/
static void _filter(
DynamicObject& filter, DynamicObject& in, DynamicObject& out)
{
if(!in.isNull())
{
DynamicObjectType inType = in->getType();
if(inType == Map)
{
// check if this object matches filter
if(_filterOne(filter, in))
{
out["@"]->append(in);
}
}
if(inType == Map || inType == Array)
{
// filter each object
DynamicObjectIterator i = in.getIterator();
while(i->hasNext())
{
_filter(filter, i->next(), out);
}
}
}
}
示例2: write
bool JsonWriter::write(DynamicObject& dyno, OutputStream* os)
{
bool rval = true;
if(mStrict)
{
rval = !dyno.isNull();
DynamicObjectType type;
if(rval)
{
type = dyno->getType();
}
if(!rval || !(type == Map || type == Array))
{
ExceptionRef e = new Exception(
"No JSON top-level Map or Array found.",
"monarch.data.json.JsonWriter.InvalidJson");
Exception::set(e);
rval = false;
}
}
if(rval)
{
ByteBuffer b(1024);
BufferedOutputStream bos(&b, os);
rval = write(dyno, &bos, mIndentLevel) && bos.flush();
}
return rval;
}
示例3: _applyContext
/**
* Recursively applies context to the given input object.
*
* @param ctx the context to use.
* @param usedCtx the used context values.
* @param predicate the related predicate or NULL if none.
* @param in the input object.
* @param out the contextualized output object.
*/
static void _applyContext(
DynamicObject& ctx, DynamicObject& usedCtx,
const char* predicate, DynamicObject& in, DynamicObject& out)
{
if(in.isNull())
{
out.setNull();
}
else
{
// initialize output
DynamicObjectType inType = in->getType();
out->setType(inType);
if(inType == Map)
{
// add context to each property in the map
char* tmp = NULL;
DynamicObjectIterator i = in.getIterator();
while(i->hasNext())
{
// compact predicate
DynamicObject& next = i->next();
DynamicObject cp(NULL);
const char* p;
if(strcmp(i->getName(), "@") == 0)
{
p = "@";
}
else
{
cp = _compactString(ctx, usedCtx, NULL, i->getName(), &tmp);
p = cp;
}
// recurse
_applyContext(ctx, usedCtx, p, next, out[p]);
}
free(tmp);
}
else if(inType == Array)
{
// apply context to each object in the array
DynamicObjectIterator i = in.getIterator();
while(i->hasNext())
{
DynamicObject& next = i->next();
_applyContext(ctx, usedCtx, predicate, next, out->append());
}
}
// only strings need context applied, numbers & booleans don't
else if(inType == String)
{
// compact string
char* tmp = NULL;
out = _compactString(ctx, usedCtx, predicate, in->getString(), &tmp);
free(tmp);
}
}
}
示例4: isValid
bool Map::isValid(
DynamicObject& obj,
ValidatorContext* context)
{
bool rval = true;
if(!obj.isNull() && obj->getType() == monarch::rt::Map)
{
Validators::iterator i;
for(i = mValidators.begin(); i != mValidators.end(); ++i)
{
// only add a "." if this is not a root map
if(context->getDepth() != 0)
{
context->pushPath(".");
}
context->pushPath(i->first);
if(obj->hasMember(i->first))
{
// do not short-circuit to ensure all keys tested
if(!i->second.validator->isValid(obj[i->first], context))
{
rval = false;
}
}
else if(!i->second.validator->isOptional(context))
{
rval = false;
DynamicObject detail =
context->addError("monarch.validation.MissingField", &obj);
detail["validator"] = "monarch.validator.Map";
detail["message"] = "A required field has not been specified.";
detail["key"] = i->first;
}
context->popPath();
if(context->getDepth() > 0)
{
context->popPath();
}
}
}
else
{
rval = false;
DynamicObject detail =
context->addError("monarch.validation.TypeError", &obj);
detail["validator"] = "monarch.validator.Map";
detail["message"] = "The given object type must a mapping (Map) type";
}
return rval;
}
示例5: isValid
bool Contains::isValid(
DynamicObject& obj,
ValidatorContext* context)
{
bool rval = false;
// check if objects are equal
rval = (obj == mObject);
// if not equal, check if target contains the validation object
if(!rval && !obj.isNull() &&
(obj->getType() == Array || obj->getType() == Map))
{
DynamicObjectIterator i = obj.getIterator();
while(!rval && i->hasNext())
{
DynamicObject& next = i->next();
rval = (next == mObject);
}
}
if(!rval)
{
DynamicObject detail =
context->addError("monarch.validation.NotFound", &obj);
detail["validator"] = "monarch.validator.Contains";
detail["expectedValue"] = mObject;
detail["message"] = mErrorMessage ? mErrorMessage :
"The input object was not equal to or found in the validator.";
}
if(rval)
{
context->addSuccess();
}
return rval;
}
示例6: paramsToElement
// a helper function that converts message parameters into a dom element
static void paramsToElement(SoapMessage& msg, DynamicObject& params, Element& e)
{
if(params->getType() == Map)
{
DynamicObjectIterator pi = params.getIterator();
while(pi->hasNext())
{
DynamicObject& p = pi->next();
// add param element
Element param;
param["name"] = pi->getName();
param["namespace"] = msg["namespace"]->getString();
e["children"][pi->getName()]->append(param);
paramsToElement(msg, p, param);
}
}
else
{
// use 0/1 for booleans
e["data"] = (params->getType() == Boolean) ?
(params->getBoolean() ? "1" : "0") : params->getString();
}
}
示例7: _removeContext
/**
* Recursively removes context from the given input object.
*
* @param ctx the context to use (changes during recursion as necessary).
* @param in the input object.
* @param out the normalized output object.
* @param bnodeId the last blank node ID used.
*
* @return true on success, false on failure with exception set.
*/
static bool _removeContext(
DynamicObject& ctx, DynamicObject& in, DynamicObject& out, int& bnodeId)
{
bool rval = true;
if(in.isNull())
{
out.setNull();
}
else
{
// initialize output
DynamicObjectType inType = in->getType();
out->setType(inType);
// update context
if(inType == Map && in->hasMember("#"))
{
ctx = in["#"];
}
if(inType == Map)
{
rval = _normalize(ctx, in, NULL, &out, bnodeId);
}
else if(inType == Array)
{
// strip context from each object in the array
DynamicObjectIterator i = in.getIterator();
while(i->hasNext())
{
DynamicObject& next = i->next();
rval = _removeContext(ctx, next, out->append(), bnodeId);
}
}
}
return rval;
}
示例8: _normalize
/**
* Recursively normalizes the given input object.
*
* Input: A subject with predicates and possibly embedded other subjects.
* Output: Either a map of normalized subjects OR a tree of normalized subjects.
*
* Normalization Algorithm:
*
* Replace the existing context if the input has '#'.
*
* For each key-value:
* 1. Split the key on a colon and look for prefix in the context. If found,
* expand the key to an IRI, else it is already an IRI, add <>, save the
* new predicate to add to the output.
* 2. If value is a Map, then it is a subject, set the predicate to the
* subject's '@' IRI value and recurse into it. Else goto #3.
* 3. Look up the key in the context to find type coercion info. If not found,
* goto #4, else goto #5.
* 4. Check the value for an integer, double, or boolean. If matched, set
* type according to xsd types. If not matched, look for <>, if found,
* do CURIE vs. IRI check like #1 and create appropriate value.
* 5. If type coercion entry is a string, encode the value using the specific
* type. If it is an array, check the type in order of preference. If an
* unrecognized type (non-xsd, non-IRI) is provided, throw an exception.
*
* @param ctx the context to use (changes during recursion as necessary).
* @param in the input object.
* @param subjects a map of normalized subjects.
* @param out a tree normalized objects.
* @param bnodeId the last blank node ID used.
*
* @return true on success, false on failure with exception set.
*/
static bool _normalize(
DynamicObject ctx, DynamicObject& in,
DynamicObject* subjects, DynamicObject* out, int& bnodeId)
{
bool rval = true;
// FIXME: validate context (check for non-xsd types in type coercion arrays)
if(!in.isNull())
{
// update context
if(in->hasMember("#"))
{
ctx = in["#"];
}
// vars for normalization state
DynamicObject subject(NULL);
if(subjects != NULL)
{
subject = DynamicObject();
subject->setType(Map);
// assign blank node ID as needed
if(!in->hasMember("@"))
{
string bnodeKey = _createBlankNodeId(++bnodeId);
subject["@"] = bnodeKey.c_str();
}
}
string nKey;
// iterate over key-values
DynamicObjectIterator i = in.getIterator();
while(rval && i->hasNext())
{
DynamicObject& value = i->next();
const char* key = i->getName();
// skip context keys
if(key[0] == '#')
{
continue;
}
// get normalized key
nKey = _normalizeValue(ctx, key, RDF_TYPE_IRI, NULL, NULL);
// put values in an array for single code path
DynamicObject values;
values->setType(Array);
if(value->getType() == Array)
{
values.merge(value, true);
// preserve array structure when not using subjects map
if(out != NULL)
{
(*out)[nKey.c_str()]->setType(Array);
}
}
else
{
values->append(value);
}
// normalize all values
//.........这里部分代码省略.........
示例9: _normalizeValue
/**
* Normalizes a value using the given context.
*
* @param ctx the context.
* @param value the value to normalize.
* @param type the expected RDF type, use RDF_TYPE_UNKNOWN if not known.
* @param predicate an optional predicate for the value (used to look up
* type coercion info).
* @param usedCtx a context to update if a value was used from "ctx".
*
* @return the normalized string.
*/
static string _normalizeValue(
DynamicObject& ctx, DynamicObject value,
RdfType type, const char* predicate, DynamicObject* usedCtx)
{
string rval;
// "@" or "a"/RDF_TYPE predicates have values that are IRIs or CURIEs
if(predicate != NULL &&
(strcmp(predicate, "@") == 0 || strcmp(predicate, "a") == 0 ||
strcmp(predicate, RDF_TYPE_NORM) == 0))
{
type = RDF_TYPE_IRI;
}
// IRI "@" is already normalized
if(type == RDF_TYPE_IRI && strcmp(value, "@") == 0)
{
rval.assign(value);
}
// IRI "a" is special rdf type
else if(type == RDF_TYPE_IRI && strcmp(value, "a") == 0)
{
rval.assign(RDF_TYPE_NORM);
}
else
{
string datatype;
// look for type coercion info
if(type == RDF_TYPE_UNKNOWN && predicate != NULL &&
!ctx.isNull() && ctx->hasMember("#types") &&
ctx["#types"]->hasMember(predicate))
{
DynamicObject& tci = ctx["#types"][predicate];
if(usedCtx != NULL)
{
(*usedCtx)["#types"][predicate] = tci.clone();
}
// handle specific type
if(tci->getType() == String)
{
rval = value->getString();
datatype = _normalizeValue(ctx, tci, RDF_TYPE_IRI, NULL, usedCtx);
type = (strcmp(datatype.c_str(), XSD_ANY_URI_NORM) == 0) ?
RDF_TYPE_IRI : RDF_TYPE_TYPED_LITERAL;
}
// handle type preferences in order
else
{
DynamicObjectIterator ti = tci.getIterator();
while(type == RDF_TYPE_UNKNOWN && ti->hasNext())
{
// FIXME: if value works w/type, set value, datatype, type
//type = RDF_TYPE_TYPED_LITERAL;
}
}
}
// determine type from DynamicObjectType
else if(type == RDF_TYPE_UNKNOWN && value->getType() != String)
{
type = RDF_TYPE_TYPED_LITERAL;
rval = value->getString();
// handle native xsd types
if(value->isNumber())
{
datatype = value->isInteger() ? XSD_INTEGER : XSD_DOUBLE;
}
else if(value->getType() == Boolean)
{
datatype = XSD_BOOLEAN;
}
else
{
// FIXME: this should never happen?
datatype = XSD_ANY_TYPE;
}
}
else
{
// JSON-LD decode
RdfType t = type;
_decode(value, type, rval, datatype);
if(type == RDF_TYPE_TYPED_LITERAL)
{
_expandCurie(ctx, datatype.c_str(), datatype, usedCtx);
}
//.........这里部分代码省略.........
示例10: isValid
bool Int::isValid(
DynamicObject& obj,
ValidatorContext* context)
{
bool rval;
DynamicObjectType objType;
rval = !obj.isNull();
if(rval)
{
objType = obj->getType();
if(objType == String)
{
objType = DynamicObject::determineType(obj->getString());
}
// type check
rval =
objType == Int32 ||
objType == UInt32 ||
objType == Int64 ||
objType == UInt64;
}
if(!rval)
{
DynamicObject detail =
context->addError("monarch.validation.ValueError", &obj);
detail["validator"] = "monarch.validator.Int";
detail["message"] =
mErrorMessage ? mErrorMessage :
"The given value type is required to be an integer.";
}
// absolute value of dyno value
uint64_t val = 0;
// flag if val is negative
bool valneg = false;
// get value for min/max check
if(rval)
{
// get value and sign
switch(objType)
{
case Int32:
case Int64:
{
int64_t raw = obj->getInt64();
valneg = (raw < 0);
val = (uint64_t)(valneg ? -raw : raw);
break;
}
case UInt32:
case UInt64:
{
valneg = false;
val = obj->getUInt64();
break;
}
default:
// never get here
break;
}
}
// min check
if(rval)
{
if(mMinNegative != valneg)
{
// signs are different
// val meets the minimum unless val is negative
rval = !valneg;
}
else
{
// signs are the same
// val meets the minimum if:
// 1. val is positive and larger than mMin
// 2. val is negative and smaller than mMin
rval = (!valneg ? val >= mMin : val <= mMin);
}
// set exception on failure
if(!rval)
{
DynamicObject detail =
context->addError("monarch.validation.ValueError", &obj);
detail["validator"] = "monarch.validator.Int";
detail["message"] = mErrorMessage ? mErrorMessage :
"The given integer value is less than the required minimum "
"integer value.";
detail["expectedMin"] = mMin;
}
}
// max check
if(rval)
//.........这里部分代码省略.........