Beispiel #1
0
void initModel(_md)
{
	/* initialize vectors */
	initVect(preds_m,		Pred);
	initVect(funcs_m,		Func);
	initVect(axioms_m,		Axiom);
	initVect(taskPtrs_m,	Task*);
	initVect(tmpFacts_m,	Fact);
	initVect(restrs_m,		Restriction);
	initVect(types_m,		DataType);

	/* create standart datatypes */
	addDataType("Boolean",	modelPtr);
	addDataType("Integer",	modelPtr);
	addDataType("Real",		modelPtr);
	
	/* CONST_TRUE, CONST_FALSE */
	//~ DataType* boolPtr = ptr(DataType, types_m) + DT_BOOL;
	DataType* boolPtr = getTypePtr(DT_BOOL);
	addBack(boolPtr->constNames, char*, getDynamicStr("True"));
	addBack(boolPtr->constNames, char*, getDynamicStr("False"));
	
	/* create arithmetic fuctions */
	size_t funcNum;
	DataTypeId paramTypes[] = {DT_INT, DT_INT};
	
	for (funcNum = 0; funcNum < ARITHMETIC_FUNCTION_COUNT; ++funcNum)
	{	
		Func func = createFunc(	(char*)ARITH_FUNCTION_NAMES[funcNum],
								ARITH_FUNCTION_PAR_COUNTS[funcNum],
								paramTypes, DT_REAL);
		addFunc(func, modelPtr);
	}
	
	/* create arithmetic relations */
	size_t predNum;
	
	for (predNum = 0; predNum < ARITHMETIC_RELATIONS_COUNT; ++predNum)
	{	
		Pred pred = createFunc(	(char*)ARITH_RELATION_NAMES[predNum],
								ARITH_RELATION_PAR_COUNTS[predNum],
								paramTypes, DT_BOOL);
		addPred(pred, modelPtr);
	}
	
	/* other initialization */
	initVect(modelPtr->errors, Error);
	initVect(modelPtr->sources, Source);
	modelPtr->currSrcPtr = NULL;
	modelPtr->totalFactCt = 0;
	modelPtr->debugStream = modelPtr->errorStream = NULL;
}
Beispiel #2
0
//-------------------------------------------------------------------------------------
bool DataTypes::loadTypes(std::string& file)
{
	TiXmlNode* node = NULL;
	SmartPointer<XML> xml(new XML(Resmgr::getSingleton().matchRes(file).c_str()));

	if(xml == NULL || !xml->isGood())
		return false;

	node = xml->getRootNode();

	if(node == NULL)
	{
		// root节点下没有子节点了
		return true;
	}

	XML_FOR_BEGIN(node)
	{
		std::string type = "";
		std::string aliasName = xml->getKey(node);
		TiXmlNode* childNode = node->FirstChild();

		// 不允许前面加_, 因为内部产生的一些临时结构前面使用了_, 避免误判
		if (aliasName[0] == '_')
		{
			ERROR_MSG(fmt::format("DataTypes::loadTypes: Not allowed to use the prefix \"_\"! aliasName={}\n",
				aliasName.c_str()));

			return false;
		}

		if(childNode != NULL)
		{
			type = xml->getValStr(childNode);
			if(type == "FIXED_DICT")
			{
				FixedDictType* fixedDict = new FixedDictType;
				
				if(fixedDict->initialize(xml.get(), childNode, aliasName))
				{
					addDataType(aliasName, fixedDict);
				}
				else
				{
					ERROR_MSG(fmt::format("DataTypes::loadTypes: parse FIXED_DICT [{}] error!\n", 
						aliasName.c_str()));
					
					delete fixedDict;
					return false;
				}
			}
			else if(type == "ARRAY")
			{
				FixedArrayType* fixedArray = new FixedArrayType;
				
				if(fixedArray->initialize(xml.get(), childNode, aliasName))
				{
					addDataType(aliasName, fixedArray);
				}
				else
				{
					ERROR_MSG(fmt::format("DataTypes::loadTypes: parse ARRAY [{}] error!\n", 
						aliasName.c_str()));
					
					delete fixedArray;
					return false;
				}
			}
			else
			{
				DataType* dataType = getDataType(type);
				if(dataType == NULL)
				{
					ERROR_MSG(fmt::format("DataTypes::loadTypes: can't fount type {} by alias[{}].\n", 
						type.c_str(), aliasName.c_str()));
					
					return false;
				}

				addDataType(aliasName, dataType);
			}
		}
	}
	XML_FOR_END(node);
	
	return true;
}
Beispiel #3
0
//-------------------------------------------------------------------------------------
bool DataTypes::initialize(std::string file)
{
	// 初始化一些基础类别
	addDataType("UINT8",		new IntType<uint8>);
	addDataType("UINT16",		new IntType<uint16>);
	addDataType("UINT64",		new UInt64Type);
	addDataType("UINT32",		new UInt32Type);

	addDataType("INT8",			new IntType<int8>);
	addDataType("INT16",		new IntType<int16>);
	addDataType("INT32",		new IntType<int32>);
	addDataType("INT64",		new Int64Type);

	addDataType("STRING",		new StringType);
	addDataType("UNICODE",		new UnicodeType);
	addDataType("FLOAT",		new FloatType);
	addDataType("DOUBLE",		new DoubleType);
	addDataType("PYTHON",		new PythonType);
	addDataType("PY_DICT",		new PyDictType);
	addDataType("PY_TUPLE",		new PyTupleType);
	addDataType("PY_LIST",		new PyListType);
	addDataType("ENTITYCALL",	new EntityCallType);
	addDataType("BLOB",			new BlobType);

	addDataType("VECTOR2",		new Vector2Type);
	addDataType("VECTOR3",		new Vector3Type);
	addDataType("VECTOR4",		new Vector4Type);
	return loadTypes(file);
}