コード例 #1
0
ファイル: class.cpp プロジェクト: bsumirak/ugcore
bool ExportedConstructor::check_consistency(std::string classname) const
{
//	flag to indicate, that unnamed parameter is found
	bool bUndeclaredParameterFound = false;

//	loop method parameters
	for(int j=0; j<params_in().size(); j++)
	{
		if(!params_in().parameter_named(j))
		{
		//	print error output, indicate parameter by 1, ..., NumParams
			if(!bUndeclaredParameterFound)
			{
				bUndeclaredParameterFound = true;
				UG_ERR_LOG("#### Registry ERROR: Unregistered Class used in ");
				UG_ERR_LOG("Constructor of class "<<classname.c_str());
				UG_ERR_LOG("': Parameter " << j+1);
			}
			else
			{	UG_ERR_LOG(", " << j+1);	}
		}
	}

//	check if undeclared parameter has been found
	if(bUndeclaredParameterFound) {UG_ERR_LOG("\n"); return false;}

//	everything ok
	return true;
}
コード例 #2
0
void* ClassCastProvider::
cast_to_base_class(void* pDerivVoid, const ClassNameNode*& node, const std::string& baseName)
{
//	find way to base class
	std::vector<size_t> vWay;
	if(!ClassNameTreeWay(vWay, *node, baseName))
	{
		UG_ERR_LOG("ERROR in ClassCastProvider::cast_to_base_class: Request"
				" to cast from derived class '"<< node->name()<<"' to "
				" base class '"<<baseName<<"', but no such base class in"
				" registered class hierarchy.");
		throw new UGError_ClassCastFailed(node->name(), baseName);
	}

	void* currPtr = pDerivVoid;
	const ClassNameNode* pCurrNode = node;

//	cast all the way down
	while(!vWay.empty())
	{
	//	get base class to cast to
		const ClassNameNode* pBaseClassNode = &pCurrNode->base_class(vWay.back());

	//	get name pair
		std::pair<const ClassNameNode*, const ClassNameNode*> namePair(pBaseClassNode, pCurrNode);

	//	find in map
		std::map<std::pair<const ClassNameNode*, const ClassNameNode*>, CastFunc>::iterator it;
		it = m_mmCast.find(namePair);

		if(it == m_mmCast.end())
		{
			UG_ERR_LOG("ERROR in ClassCastProvider::cast_to_base_class:"
					" Request intermediate cast from derived class '" <<
					pCurrNode->name() <<"' to direct base class '"
					<<pBaseClassNode->name()<<"', but no such cast "
					" function registered.");
			throw new UGError_ClassCastFailed(node->name(), baseName);
		}

	//	get cast function
		CastFunc pCastFunc = it->second;

	//	cast
		currPtr = (*pCastFunc)(currPtr);

	//	set node to base class
		pCurrNode = pBaseClassNode;

	//	pop way
		vWay.pop_back();
	}

//	write current node on exit
	node = pCurrNode;

//	return current pointer
	return currPtr;
}
コード例 #3
0
ファイル: lua_util.cpp プロジェクト: miho/ugcore
/// UGLuaErrLog.
int UGLuaErrLog(lua_State *L)
{
	std::stringstream ss;
	GetToStringFromStack(L, ss);
	ss << "\n";
	UG_ERR_LOG(ss.str());
	GetLogAssistant().flush();
	return 0;
}
コード例 #4
0
ファイル: class.cpp プロジェクト: bsumirak/ugcore
bool IExportedClass::check_consistency() const
{
//	get class name vector of all parents
	const std::vector<const char*>* vClassNames = class_names();

//	check if class name vector correct
	if(vClassNames==NULL)
	{
		UG_ERR_LOG("#### Registry ERROR:"
				" Class name vector of parent classes missing for "
				"class '"<<this->name()<<"'.\n");
		return false;
	}

//	loop all base classes
	for(size_t i = 0; i < (*vClassNames).size(); ++i)
	{
	//	get name of base class
		const char* baseName = (*vClassNames)[i];

	//	check the name
		if(baseName == NULL || *baseName == '\0' || baseName[0] == '[')
		{
			if(i>0){
			UG_ERR_LOG("#### Registry ERROR:"
					" base class "<<i<<" of class '"<<this->name()<<
					"' has not been named.\n");
				return false;
			}
			else{
			UG_ERR_LOG("#### Registry ERROR:"
					" Class '"<<this->name()<<"' has not been named.\n");
				return false;
			}
		}
	}

//	everything ok
	return true;
}
コード例 #5
0
bool LoadPlugins(const char* pluginPath, string parentGroup, bridge::Registry& reg, bool bPrefixGroup)
{
	PROFILE_FUNC();
	typedef void (*FctInitPlugin)(ug::bridge::Registry*, string);

	bool bSuccess = true;

//	first we'll try to find all plugins in the given path
	vector<string> files;

	GetFilesInDirectory(files, pluginPath);

	string prefixStr = GetDynamicLibraryPrefix();
	string suffixStr = string(".").append(GetDynamicLibrarySuffix());

	int prefixLen = prefixStr.size();
	int suffixLen = suffixStr.size(); // includes '.'

	for(size_t i = 0; i < files.size(); ++i){

	//	extract the plugins name from the file-name
		int nameStart = prefixLen;
		int nameLength = (int)files[i].size() - suffixLen - nameStart;

	//	exclude MAC OS X hidden folder custom file ".DS_Store" from plugin consideration
		#ifdef __APPLE__
			if(files[i].compare(".DS_Store") == 0) continue;
		#endif

	//	check that plugin name can exist
		if(nameLength <= 0)
		{
			UG_ERR_LOG("Plugin-filename '" << files[i] <<
					"' too short. Ignoring plugin.\n");
			bSuccess = false;
			continue;
		}

	//	check for prefix
		if(files[i].compare(0,prefixLen,prefixStr) != 0)
		{
			UG_ERR_LOG("Plugin-filename '" << files[i] << "' does not "
					"start with Plugin prefix '"<<prefixStr<<"'. Ignoring plugin.\n");
			bSuccess = false;
			continue;
		}

	//	check for suffix
		if(files[i].compare(files[i].size()-suffixLen,suffixLen,suffixStr) != 0)
		{
			UG_ERR_LOG("Plugin-filename '" << files[i] << "' does not "
					"end with Plugin suffix '"<<suffixStr<<"'. Ignoring plugin.\n");
			bSuccess = false;
			continue;
		}

	//	load the library
		string fullPluginName(pluginPath);
		fullPluginName.append("/").append(files[i]);


		DynLibHandle libHandle;
		try{
			libHandle = OpenLibrary(fullPluginName.c_str());
		}
		catch(std::string errMsg)
		{
			UG_ERR_LOG("PLUGIN-ERROR: Couldn't open plugin " << files[i] << endl);
			UG_ERR_LOG("Error Message: " << errMsg << "\n");
			UG_ERR_LOG("NOTE: This could be due to incompatible build settings in ugshell and the plugin.\n");
			bSuccess = false;
			continue;
		}


	//	find the plugins init function
		string pluginName = files[i].substr(nameStart, nameLength);
		string fctName("InitUGPlugin_");
		fctName.append(pluginName);

		FctInitPlugin fctInitPlugin =
				(FctInitPlugin) GetLibraryProcedure(libHandle, fctName.c_str());

		if(!fctInitPlugin){
			UG_ERR_LOG("PLUGIN-ERROR: Couldn't find entry point " <<  fctName
					<< " in plugin " << files[i] << endl);
			CloseLibrary(libHandle);
			bSuccess = false;
			continue;
		}

//#define DEBUG_PLUGINS
#ifdef DEBUG_PLUGINS
		UG_LOG("Loaded plugin " << pluginName << " from " << fullPluginName << "\n");
		size_t numClassesPre = reg.num_classes();
		size_t numFunctionsPre = reg.num_functions();
		UG_LOG("Call " << fctName << "... ");
#endif

		// added this for better docu generation
		// this way, we can distinguish what plugin did what classes/functions etc.
		std::string group;
		if(bPrefixGroup)
			group = std::string("(Plugin) ") + pluginName + std::string(" ") + parentGroup;
		else
			group = parentGroup;

	//	call the init method
		fctInitPlugin(&reg, group);
#ifdef DEBUG_PLUGINS
		UG_LOG("added " << reg.num_classes() - numClassesPre << " classes, " << reg.num_functions()-numFunctionsPre << " functions, "
				<< "group = " << group << "\n")
#endif

		loadedPlugins.push_back(libHandle);
		loadedPluginNames.push_back(pluginName);
	}

//	make sure that the registry is updated
	reg.registry_changed();

	return bSuccess;
}