本文整理汇总了C++中TypeManager类的典型用法代码示例。如果您正苦于以下问题:C++ TypeManager类的具体用法?C++ TypeManager怎么用?C++ TypeManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TypeManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: check_compatible
PyObject*
check_compatible(PyObject* self, PyObject* args)
{
PyObject *tmcap;
int from, to;
if (!PyArg_ParseTuple(args, "Oii", &tmcap, &from, &to)) {
return NULL;
}
TypeManager *tm = unwrap_TypeManager(tmcap);
if(!tm) {
BAD_TM_ARGUMENT;
return NULL;
}
switch(tm->isCompatible(Type(from), Type(to))){
case TCC_EXACT:
return PyString_FromString("exact");
case TCC_PROMOTE:
return PyString_FromString("promote");
case TCC_CONVERT_SAFE:
return PyString_FromString("safe");
case TCC_CONVERT_UNSAFE:
return PyString_FromString("unsafe");
default:
Py_RETURN_NONE;
}
}
示例2: getReturnType
xqtref_t fn_remove::getReturnType(const fo_expr* caller) const
{
TypeManager* tm = caller->get_type_manager();
return tm->create_type_x_quant(*caller->get_arg(0)->get_return_type(),
SequenceType::QUANT_QUESTION);
}
示例3: ZORBA_ASSERT
SequenceType SequenceType::createSchemaAttributeType(
const StaticContext_t& sctx,
const String& uri,
const String& localName,
Quantifier quant)
{
ZORBA_ASSERT(sctx != NULL);
static_context* sctx2 = Unmarshaller::getInternalStaticContext(sctx);
TypeManager* tm = sctx2->get_typemanager();
zstring& ns = Unmarshaller::getInternalString(uri);
zstring& local = Unmarshaller::getInternalString(localName);
store::Item_t qname;
ZORBA_ASSERT(!local.empty());
GENV_ITEMFACTORY->createQName(qname, ns, "", local);
try
{
xqtref_t res = tm->create_schema_attribute_type(qname, quant, QueryLoc::null);
return Unmarshaller::createSequenceType(res.getp());
}
catch (...)
{
return Unmarshaller::createSequenceType(NULL);
}
}
示例4: serialize
std::string Serializer::serialize(const TypeManager &typeManager)
{
rapidjson::Document document;
{
rapidjson::Value moduleTypesValue;
moduleTypesValue.SetArray();
for(unsigned int i=0; i<typeManager.numUserTypes(); ++i){
rapidjson::Value moduleTypeValue;
jsonifyModuleType(*typeManager.getUserType(i), moduleTypeValue, document);
moduleTypesValue.PushBack(moduleTypeValue, document.GetAllocator());
}
document.SetObject();
document.AddMember("moduleTypes", moduleTypesValue, document.GetAllocator());
}
//TODO remove this line when rapidjson have fixed their bug (radix separator is decided by locale, instead of set to .)
setlocale(LC_NUMERIC, "POSIX");
//make an std::string from the document
StdStringStreamWrapper streamWrapper;
rapidjson::PrettyWriter<StdStringStreamWrapper> writer(streamWrapper);
document.Accept(writer);
return streamWrapper.stream.str();
}
示例5: createAtomicOrUnionType
SequenceType SequenceType::createAtomicOrUnionType(
const StaticContext_t& sctx,
const String& uri,
const String& localName,
Quantifier quant)
{
TypeManager* tm;
if (sctx == NULL)
{
tm = &GENV_TYPESYSTEM;
}
else
{
static_context* sctx2 = Unmarshaller::getInternalStaticContext(sctx);
tm = sctx2->get_typemanager();
}
zstring& ns = Unmarshaller::getInternalString(uri);
zstring& local = Unmarshaller::getInternalString(localName);
store::Item_t qname;
GENV_ITEMFACTORY->createQName(qname, ns, "", local);
xqtref_t type = tm->create_named_type(qname, quant, QueryLoc::null, false);
if (type->isGenAtomicAny())
return Unmarshaller::createSequenceType(type.getp());
return Unmarshaller::createSequenceType(NULL);
}
示例6: set_compatible
PyObject*
set_compatible(PyObject* self, PyObject* args)
{
PyObject *tmcap;
int from, to, by;
if (!PyArg_ParseTuple(args, "Oiii", &tmcap, &from, &to, &by)) {
return NULL;
}
TypeManager *tm = unwrap_TypeManager(tmcap);
if (!tm) {
BAD_TM_ARGUMENT;
return NULL;
}
TypeCompatibleCode tcc;
switch (by) {
case 'p': // promote
tcc = TCC_PROMOTE;
break;
case 's': // safe convert
tcc = TCC_CONVERT_SAFE;
break;
case 'u': // unsafe convert
tcc = TCC_CONVERT_UNSAFE;
break;
default:
PyErr_SetString(PyExc_ValueError, "Unknown TCC");
return NULL;
}
tm->addCompatibility(Type(from), Type(to), tcc);
Py_RETURN_NONE;
}
示例7: createJSONArrayType
SequenceType SequenceType::createJSONArrayType(Quantifier q)
{
TypeManager* tm = &GENV_TYPESYSTEM;
xqtref_t res = tm->create_json_type(store::StoreConsts::jsonArray, q);
return Unmarshaller::createSequenceType(res.getp());
}
示例8: select_overload
PyObject*
select_overload(PyObject* self, PyObject* args)
{
PyObject *tmcap, *sigtup, *ovsigstup;
int allow_unsafe;
if (!PyArg_ParseTuple(args, "OOOi", &tmcap, &sigtup, &ovsigstup,
&allow_unsafe)) {
return NULL;
}
TypeManager *tm = unwrap_TypeManager(tmcap);
if (!tm) {
BAD_TM_ARGUMENT;
}
Py_ssize_t sigsz = PySequence_Size(sigtup);
Py_ssize_t ovsz = PySequence_Size(ovsigstup);
Type *sig = new Type[sigsz];
Type *ovsigs = new Type[ovsz * sigsz];
for (int i = 0; i < sigsz; ++i) {
sig[i] = Type(PyNumber_AsSsize_t(PySequence_Fast_GET_ITEM(sigtup,
i), NULL));
}
for (int i = 0; i < ovsz; ++i) {
PyObject *cursig = PySequence_Fast_GET_ITEM(ovsigstup, i);
for (int j = 0; j < sigsz; ++j) {
long tid = PyNumber_AsSsize_t(PySequence_Fast_GET_ITEM(cursig,
j), NULL);
ovsigs[i * sigsz + j] = Type(tid);
}
}
int selected = -42;
int matches = tm->selectOverload(sig, ovsigs, selected, sigsz, ovsz,
(bool) allow_unsafe);
delete [] sig;
delete [] ovsigs;
if (matches > 1) {
PyErr_SetString(PyExc_TypeError, "Ambigous overloading");
return NULL;
} else if (matches == 0) {
PyErr_SetString(PyExc_TypeError, "No compatible overload");
return NULL;
}
return PyLong_FromLong(selected);
}
示例9: createElementType
SequenceType SequenceType::createElementType(
const StaticContext_t& sctx,
const String& nodeUri,
const String& nodeLocalName,
const String& typeUri,
const String& typeLocalName,
bool nillable,
Quantifier quant)
{
TypeManager* tm;
if (sctx == NULL)
{
tm = &GENV_TYPESYSTEM;
}
else
{
static_context* sctx2 = Unmarshaller::getInternalStaticContext(sctx);
tm = sctx2->get_typemanager();
}
zstring& nodeNS = Unmarshaller::getInternalString(nodeUri);
zstring& nodeLocal = Unmarshaller::getInternalString(nodeLocalName);
store::Item_t nodeQName;
if (!nodeLocal.empty())
GENV_ITEMFACTORY->createQName(nodeQName, nodeNS, "", nodeLocal);
zstring& typeNS = Unmarshaller::getInternalString(typeUri);
zstring& typeLocal = Unmarshaller::getInternalString(typeLocalName);
store::Item_t typeQName;
xqtref_t contentType;
if (!typeLocal.empty())
{
GENV_ITEMFACTORY->createQName(typeQName, typeNS, "", typeLocal);
contentType = tm->create_named_type(typeQName, QUANT_ONE, QueryLoc::null, false);
if (contentType == NULL)
return Unmarshaller::createSequenceType(NULL);
}
xqtref_t res = tm->create_node_type(store::StoreConsts::elementNode,
nodeQName,
contentType,
quant,
nillable,
false);
return Unmarshaller::createSequenceType(res.getp());
}
示例10: createNamespaceType
SequenceType SequenceType::createNamespaceType(Quantifier quant)
{
TypeManager* tm = &GENV_TYPESYSTEM;
xqtref_t res = tm->create_node_type(store::StoreConsts::namespaceNode,
NULL,
NULL,
quant,
false,
false);
return Unmarshaller::createSequenceType(res.getp());
}
示例11: validateSimpleContent
void SchemaValidatorImpl::validateSimpleContent(
store::Item *typeQName,
zstring newValue,
std::vector<store::Item_t>& resultList)
{
TypeManager* typeManager = theSctx->get_typemanager();
Schema* schema = typeManager->getSchema();
ZORBA_ASSERT( schema );
const xqtref_t& targetType =
schema->createXQTypeFromTypeName(typeManager, typeQName);
schema->parseUserSimpleTypes(newValue, targetType, resultList, QueryLoc::null,
false);
}
示例12: getReturnType
xqtref_t fn_data::getReturnType(const fo_expr* caller) const
{
const QueryLoc& loc = caller->get_loc();
TypeManager* tm = caller->get_type_manager();
RootTypeManager& RTM = GENV_TYPESYSTEM;
xqtref_t argType = caller->get_arg(0)->get_return_type();
if (TypeOps::is_subtype(tm, *argType, *RTM.ANY_ATOMIC_TYPE_STAR, loc))
return argType; // includes () case
SequenceType::Quantifier q = argType->get_quantifier();
if (argType->type_kind() == XQType::NODE_TYPE_KIND)
{
const NodeXQType& nType = static_cast<const NodeXQType&>(*argType);
store::StoreConsts::NodeKind nodeKind = nType.get_node_kind();
if (nodeKind == store::StoreConsts::piNode ||
nodeKind == store::StoreConsts::commentNode)
{
return tm->create_builtin_atomic_type(store::XS_STRING, q);
}
if (nodeKind == store::StoreConsts::documentNode ||
nodeKind == store::StoreConsts::textNode)
{
return tm->create_builtin_atomic_type(store::XS_UNTYPED_ATOMIC, q);
}
xqtref_t cType = nType.get_content_type();
if (cType != NULL)
{
if (cType->isList())
{
const XQType* itemType = static_cast<const UserDefinedXQType*>(cType.getp())->
getListItemType();
return tm->create_type(*itemType, SequenceType::QUANT_STAR);
}
else if (TypeOps::is_equal(tm, *cType, *RTM.UNTYPED_ATOMIC_TYPE_ONE))
{
return tm->create_builtin_atomic_type(store::XS_UNTYPED_ATOMIC, q);
}
else if (TypeOps::is_equal(tm, *cType, *RTM.UNTYPED_TYPE))
{
return tm->create_builtin_atomic_type(store::XS_UNTYPED_ATOMIC, q);
}
else if (TypeOps::is_subtype(tm, *cType, *RTM.ANY_ATOMIC_TYPE_STAR, loc))
{
return tm->create_type(*cType, q);
}
}
}
return RTM.ANY_ATOMIC_TYPE_STAR;
}
示例13: isPossibleSimpleContentRevalidation
bool SchemaValidatorImpl::isPossibleSimpleContentRevalidation(
store::Item* typeQName)
{
TypeManager* typeManager = theSctx->get_typemanager();
//StaticContextConsts::validation_mode_t mode = theSctx->validation_mode();
Schema* schema = typeManager->getSchema();
if ( !schema )
{
// no schema available no change to pul
return false;
}
xqtref_t schemaType = schema->createXQTypeFromTypeName(typeManager, typeQName);
if ( schemaType.getp() )
return isPossibleSimpleContentRevalImpl(schemaType);
else
return false;
}
示例14: createDocumentType
SequenceType SequenceType::createDocumentType(
const SequenceType& contentType,
Quantifier quant)
{
const XQType* contentType2 = Unmarshaller::getInternalType(contentType);
TypeManager* tm = (contentType2 == NULL ?
&GENV_TYPESYSTEM :
contentType2->get_manager());
store::Item_t qname;
xqtref_t res = tm->create_node_type(store::StoreConsts::documentNode,
qname,
contentType2,
quant,
false,
false);
return Unmarshaller::createSequenceType(res.getp());
}
示例15: main
int main() {
TypeManager tm;
Type t_int32 = tm.get("int32");
Type t_float = tm.get("float");
Type t_int64 = tm.get("int64");
tm.addConversion(t_int32, t_float);
tm.addConversion(t_float, t_int32);
tm.addConversion(t_float, t_int64);
tm.addPromotion(t_int32, t_int64);
cout << "int32 -> float "
<< TCCString(tm.isCompatible(tm.get("int32"), tm.get("float")))
<< EOL;
cout << "int32 -> int64 "
<< TCCString(tm.isCompatible(tm.get("int32"), tm.get("int64")))
<< EOL;
Type sig[] = {t_int32, t_float};
Type ovsigs[] = {
t_float, t_float,
t_int64, t_int64,
t_int32, t_float,
};
int sel = tm.selectOverload(sig, ovsigs, 2, 3);
cout << "Selected " << sel << '\n';
return 0;
}