本文整理汇总了C++中DynamicObject::setType方法的典型用法代码示例。如果您正苦于以下问题:C++ DynamicObject::setType方法的具体用法?C++ DynamicObject::setType怎么用?C++ DynamicObject::setType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicObject
的用法示例。
在下文中一共展示了DynamicObject::setType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getDirectives
bool DirectiveService::getDirectives(
BtpAction* action, DynamicObject& in, DynamicObject& out)
{
bool rval = false;
UserId userId;
if(mNode->checkLogin(action, &userId))
{
rval = true;
// turn user ID into a key
char key[22];
snprintf(key, 22, "%" PRIu64, userId);
// return user's directive cache
mCacheLock.lock();
{
if(mDirectives->hasMember(key))
{
out = mDirectives[key];
}
else
{
out->setType(Map);
}
}
mCacheLock.unlock();
}
return rval;
}
示例2: filter
// FIXME: should this be using new JSON-LD frame stuff rather than this?
bool JsonLd::filter(
DynamicObject& context, DynamicObject& filter,
DynamicObject& in, DynamicObject& out, bool simplify)
{
bool rval;
DynamicObject normFilter;
DynamicObject normIn;
DynamicObject normOut;
normOut->setType(Map);
// remove contexts
rval =
removeContext(filter, normFilter) &&
removeContext(in, normIn);
// filter to the output
if(rval)
{
_filter(normFilter, normIn, normOut);
// FIXME: fixup graph
// Search normOut for unknown references that are in normIn and add them.
// Futher optimize by checking reference count and embedding data as
// needed. This will result in a graph that is as complete as the input
// with regard to references.
// flatten in the case of one result
if(simplify && normOut->hasMember("@") && normOut["@"]->length() == 1)
{
normOut = normOut["@"][0];
}
}
// add context to output
rval = rval && addContext(context, normOut, out);
return rval;
}
示例3:
/**
* Gets the field names and values for a particular X509_NAME.
*
* For instance, if the subject name is passed, then the "CN" (common name)
* value, "C" (country) value, etc. will be added to the output.
*
* @param name the X509_name, i.e. X509_get_subject_name(mX509).
* @param output the array to populate.
*/
static void _getX509NameValues(X509_NAME* name, DynamicObject& output)
{
output->setType(Array);
unsigned char* value;
X509_NAME_ENTRY* entry;
int count = X509_NAME_entry_count(name);
for(int i = 0; i < count; ++i)
{
entry = X509_NAME_get_entry(name, i);
// get entry name (object) and value (data)
ASN1_OBJECT* obj = X509_NAME_ENTRY_get_object(entry);
ASN1_STRING* str = X509_NAME_ENTRY_get_data(entry);
// convert name and value to strings
int nid = OBJ_obj2nid(obj);
const char* sn = OBJ_nid2sn(nid);
if(ASN1_STRING_to_UTF8(&value, str) != -1)
{
DynamicObject& item = output->append();
item["type"] = sn;
item["value"] = value;
OPENSSL_free(value);
}
}
}
示例4: _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);
}
}
}
示例5: getStats
DynamicObject DynamicObjectImpl::getStats()
{
DynamicObject rval;
rval->setType(Map);
#if defined(MO_DYNO_COUNTS) || defined(MO_DYNO_KEY_COUNTS)
#define MAKESTAT(d, s) \
MO_STMT_START { \
d["counts"]["live"] = s.counts.live; \
d["counts"]["dead"] = s.counts.dead; \
d["counts"]["max"] = s.counts.max; \
d["bytes"]["live"] = s.bytes.live; \
d["bytes"]["dead"] = s.bytes.dead; \
d["bytes"]["max"] = s.bytes.max; \
} MO_STMT_END
#endif // defined(MO_DYNO_COUNTS) || defined(MO_DYNO_KEY_COUNTS)
#ifdef MO_DYNO_COUNTS
#define GETSTAT(s, type) \
MO_STMT_START { \
DynamicObject& d = s[MO_STRINGIFY(type)]; \
MAKESTAT(d, _stats_counts[type]); \
} MO_STMT_END
GETSTAT(rval, Object);
GETSTAT(rval, String);
GETSTAT(rval, Boolean);
GETSTAT(rval, Int32);
GETSTAT(rval, UInt32);
GETSTAT(rval, Int64);
GETSTAT(rval, UInt64);
GETSTAT(rval, Double);
GETSTAT(rval, Map);
GETSTAT(rval, Array);
GETSTAT(rval, Key);
GETSTAT(rval, StringValue);
#undef GETSTAT
#endif // MO_DYNO_COUNTS
#ifdef MO_DYNO_KEY_COUNTS
{
_stats_key_counts_lock.lock();
DynamicObject& d = rval["KeyCounts"];
d["count"] = _stats_key_counts.size();
d["keys"]->setType(Map);
_StatsKeyMap::iterator i =
_stats_key_counts.begin();
for(; i != _stats_key_counts.end(); ++i)
{
// create new stat entry
DynamicObject& s = d["keys"][i->first];
MAKESTAT(s, _stats_key_counts[i->first]);
}
_stats_key_counts_lock.unlock();
}
#endif // MO_DYNO_KEY_COUNTS
return rval;
}
示例6:
DynamicObject& Exception::getDetails()
{
if(mDetails->isNull())
{
DynamicObject details;
details->setType(Map);
*mDetails = details;
}
return *mDetails;
}
示例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: runConfigManagerTest
static void runConfigManagerTest(TestRunner& tr)
{
tr.group("ConfigManager");
tr.test("init");
{
DynamicObject expect;
expect->setType(Map);
ConfigManager cm;
Config cfg;
cfg[ConfigManager::ID] = "config";
cfg[ConfigManager::MERGE]->setType(Map);
assert(cm.addConfig(cfg));
assertDynoCmp(cm.getConfig("config", true), cfg);
assertDynoCmp(cm.getConfig("config", false), expect);
assertDynoCmp(cm.getConfig("config"), expect);
}
tr.passIfNoException();
tr.test("init & clear");
{
DynamicObject expect;
expect->setType(Map);
ConfigManager cm;
Config cfg;
cfg[ConfigManager::ID] = "config";
cfg[ConfigManager::MERGE]->setType(Map);
assert(cm.addConfig(cfg));
cm.clear();
Config cfg2 = cm.getConfig("config");
assert(cfg2.isNull());
}
tr.passIfException();
tr.test("1 config");
{
DynamicObject expect;
expect->setType(Map);
expect["a"] = 0;
ConfigManager cm;
Config cfg;
cfg[ConfigManager::ID] = "config";
cfg[ConfigManager::MERGE]["a"] = 0;
assert(cm.addConfig(cfg));
assertNoExceptionSet();
assertDynoCmp(cm.getConfig("config"), expect);
}
tr.passIfNoException();
tr.test("config change");
{
ConfigManager cm;
Config cfg;
cfg[ConfigManager::ID] = "config";
cfg[ConfigManager::MERGE]["a"] = 0;
assert(cm.addConfig(cfg));
DynamicObject a;
a["a"] = 0;
assertDynoCmp(cm.getConfig("config"), a);
Config change = cm.getConfig("config", true);
change[ConfigManager::MERGE]["a"] = 1;
assert(cm.setConfig(change));
DynamicObject expect;
expect["a"] = 1;
assert(cm.getConfig("config") != a);
assertDynoCmp(cm.getConfig("config"), expect);
}
tr.passIfNoException();
tr.test("invalid set config");
{
ConfigManager cm;
Config cfg;
cfg[ConfigManager::ID] = "config";
cfg[ConfigManager::MERGE]["a"] = 0;
assert(!cm.setConfig(cfg));
}
tr.passIfException();
tr.test("double add config");
{
ConfigManager cm;
Config cfg;
cfg[ConfigManager::ID] = "config";
cfg[ConfigManager::MERGE]["a"] = 0;
assert(cm.addConfig(cfg));
cfg[ConfigManager::MERGE]["a"] = 1;
assert(cm.addConfig(cfg));
DynamicObject expect;
expect["a"] = 1;
assertDynoCmp(cm.getConfig("config"), expect);
}
tr.passIfNoException();
tr.test("add");
{
DynamicObject expect;
expect["a"] = 0;
expect["b"] = 1;
expect["c"] = 2;
//.........这里部分代码省略.........
示例9: runNodeMonitorTest
static void runNodeMonitorTest(TestRunner& tr)
{
tr.group("NodeMonitor");
tr.test("empty");
{
NodeMonitor nm;
DynamicObject expect;
expect->setType(Map);
DynamicObject all = nm.getAll();
assertDynoCmp(expect, all);
}
tr.passIfNoException();
tr.test("add1 init");
{
bool r;
NodeMonitor nm;
DynamicObject si;
si["init"] = "foo";
r = nm.addState("s", si);
assert(r);
DynamicObject expect;
expect["s"] = "foo";
DynamicObject all = nm.getAll();
assertDynoCmp(expect, all);
}
tr.passIfNoException();
tr.test("addN init");
{
bool r;
NodeMonitor nm;
DynamicObject si;
si["s"]["init"] = "foo";
si["u"]["init"] = (uint64_t)0;
si["i"]["init"] = (int64_t)0;
si["d"]["init"] = 0.;
r = nm.addStates(si);
assert(r);
DynamicObject expect;
expect["s"] = "foo";
expect["u"] = (uint64_t)0;
expect["i"] = (int64_t)0;
expect["d"] = 0.;
DynamicObject all = nm.getAll();
assertDynoCmp(expect, all);
}
tr.passIfNoException();
tr.test("remove");
{
bool r;
NodeMonitor nm;
DynamicObject si;
si["n"]["init"] = (uint64_t)0;
si["rem"]["init"] = (uint64_t)0;
r = nm.addStates(si);
assert(r);
DynamicObject s;
s["rem"].setNull();
r = nm.removeStates(s);
assert(r);
DynamicObject expect;
expect["n"] = (uint64_t)0;
DynamicObject all = nm.getAll();
assertDynoCmp(expect, all);
}
tr.passIfNoException();
tr.test("set");
{
bool r;
NodeMonitor nm;
DynamicObject si;
si["n"]["init"] = (uint64_t)0;
r = nm.addStates(si);
assert(r);
DynamicObject s;
s["n"] = (uint64_t)123;
r = nm.setStates(s);
assert(r);
DynamicObject expect;
expect["n"] = (uint64_t)123;
DynamicObject all = nm.getAll();
assertDynoCmp(expect, all);
}
tr.passIfNoException();
tr.test("adj");
//.........这里部分代码省略.........
示例10: addService
bool WebServiceContainer::addService(
WebServiceRef& service,
WebService::SecurityType st,
bool initialize,
const char* domain)
{
bool rval = true;
if(initialize)
{
rval = service->initialize();
}
if(rval)
{
// build list of domains to add service to
DynamicObject domains(NULL);
DynamicObject added;
added->setType(Array);
if(domain != NULL)
{
domains = DynamicObject();
domains->append(domain);
}
else
{
domains = mDefaultDomains;
}
HttpRequestServicer* hrs = &(*service);
const char* path = hrs->getPath();
// prevent other container access
mContainerLock.lockExclusive();
DynamicObjectIterator di = domains.getIterator();
while(rval && di->hasNext())
{
const char* dom = di->next()->getString();
rval = internalAddService(service, st, dom);
if(rval)
{
added->append(dom);
}
}
di = rval ? domains.getIterator() : added.getIterator();
while(di->hasNext())
{
const char* dom = di->next()->getString();
// success, add domain to http servicer
if(rval)
{
if(st == WebService::Secure || st == WebService::Both)
{
mHttpConnectionServicer.addRequestServicer(hrs, true, dom);
MO_CAT_DEBUG(MO_WS_CAT,
"Added secure web service: %s%s", dom, path);
}
if(st != WebService::Secure)
{
mHttpConnectionServicer.addRequestServicer(hrs, false, dom);
MO_CAT_DEBUG(MO_WS_CAT,
"Added non-secure web service: %s%s", dom, path);
}
}
// could not add service to all domains, so remove it
else
{
internalRemoveService(path, st, dom, NULL);
}
}
// permit access again
mContainerLock.unlockExclusive();
}
// failed to add service
if(!rval)
{
// service was initialized, so clean it up
if(initialize)
{
service->cleanup();
}
// set exception
ExceptionRef e = new Exception(
"Could not add web service.",
"monarch.ws.AddWebServiceFailure");
Exception::push(e);
}
return rval;
}
示例11: write
bool DomWriter::write(Element& e, OutputStream* os, int level)
{
DynamicObject nsPrefixMap;
nsPrefixMap->setType(Map);
return writeWithNamespaceSupport(e, os, level, nsPrefixMap);
}
示例12: normalize
bool JsonLd::normalize(DynamicObject& in, DynamicObject& out)
{
bool rval = true;
// initialize output
out->setType(Map);
out->clear();
// create map to store subjects
DynamicObject subjects;
subjects->setType(Map);
// initialize context
DynamicObject ctx(NULL);
if(in->hasMember("#"))
{
ctx = in["#"];
}
// put all subjects in an array for single code path
DynamicObject input;
input->setType(Array);
if(in->hasMember("@") && in["@"]->getType() == Array)
{
input.merge(in["@"], true);
}
else
{
input->append(in);
}
// do normalization
int bnodeId = 0;
DynamicObjectIterator i = input.getIterator();
while(rval && i->hasNext())
{
rval = _normalize(ctx, i->next(), &subjects, NULL, bnodeId);
}
// build output
if(rval)
{
// single subject
if(subjects->length() == 1)
{
DynamicObject subject = subjects.first();
out.merge(subject, false);
// FIXME: will need to check predicates for blank nodes as well...
// and fail if they aren't embeds?
// strip blank node '@'
if(_isBlankNode(out))
{
out->removeMember("@");
}
}
// multiple subjects
else
{
DynamicObject& array = out["@"];
array->setType(Array);
i = subjects.getIterator();
while(i->hasNext())
{
DynamicObject& next = i->next();
// FIXME: will need to check predicates for blank nodes as well...
// and fail if they aren't embeds?
// strip blank node '@'
if(_isBlankNode(next))
{
next->removeMember("@");
}
array->append(next);
}
}
}
return rval;
}
示例13: _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
//.........这里部分代码省略.........
示例14: buildParams
void DatabaseClient::buildParams(
SchemaObject& schema, DynamicObject& members, DynamicObject& params,
const char* tableAlias)
{
// ensure params is an array
params->setType(Array);
// create shared table alias object
DynamicObject taObj(NULL);
if(tableAlias != NULL)
{
taObj = DynamicObject();
taObj = tableAlias;
}
// map the given members object into a list of parameters that can
// be used to generate sql and set parameter values
DynamicObjectIterator i = schema["columns"].getIterator();
while(i->hasNext())
{
DynamicObject& column = i->next();
const char* memberName = column["memberName"]->getString();
// if the members map contains the given member name, create a param
// for it and append it to the params array
if(members->hasMember(memberName))
{
/* Note: The member value is either a value, map, or an array. If it's
* an array, then each entry in the array is either a value or a map.
*
* Create a single parameter for all values. Create an individual
* parameter for every map entry. This algorithm will store all maps
* in "p" and all values in "values". Then "values" will be added to
* "p". Then a new parameter will be created for each entry in "p".
*/
DynamicObject& mv = members[memberName];
DynamicObject p(Array);
DynamicObject values(Array);
// group maps and values
if(mv->getType() == Map)
{
p->append(mv);
}
else if(mv->getType() == Array)
{
DynamicObjectIterator mvi = mv.getIterator();
while(mvi->hasNext())
{
DynamicObject& next = mvi->next();
if(next->getType() == Map)
{
p->append(next);
}
else
{
values->append(next);
}
}
}
else
{
values->append(mv);
}
// treat values as a single param
if(values->length() > 0)
{
p->append(values);
}
// create params
DynamicObjectIterator pi = p.getIterator();
while(pi->hasNext())
{
DynamicObject& next = pi->next();
// add param
DynamicObject& param = params->append();
param["name"] = column["name"];
param["type"] = column["columnType"];
param["op"] = "=";
param["boolOp"] = "AND";
if(column->hasMember("encode"))
{
param["encode"] = column["encode"];
}
if(tableAlias != NULL)
{
param["tableAlias"] = taObj;
}
// if next param is a map, get operator and value
if(next->getType() == Map)
{
if(next->hasMember("op"))
{
param["op"] = next["op"].clone();
}
if(next->hasMember("boolOp"))
//.........这里部分代码省略.........