⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kr_plugin.h

📁 这是法国Kaleido公司提供了一个手机mmi设计平台
💻 H
字号:
/***************************************************************************
KR_Plugin.h  -
-------------------
begin                : Fri Jan 28 2005
copyright            : (C) 2005 by DigitalAirways
email                : info@digitalairways.com
***************************************************************************/

/*
* Copyright (c) 2000-2004 DigitalAirways, sarl. All Rights Reserved.
*
* This software is the confidential and proprietary information of
* DigitalAirways, sarl. ("Confidential Information").  You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with DigitalAirways.
* A copy of this license is included in the licence.txt file included
* in this software package.
*/

/*
**************************************************************
* TODO
**************************************************************

-



**************************************************************
* HISTORY
**************************************************************

-
*/

#ifndef __KR_PLUGIN__
#define __KR_PLUGIN__

#include "KR_Object.h"
#include "KR_KRuntime.h"
#include "EB_GContext.h"
#include "EB_BinReader.h"

#define STAT_EVAL_OK				0x00000000
#define STAT_EVAL_UNKNOWN_SYMBOL	0x00000001
#define STAT_EVAL_SYNTAX_ERROR		0x00000002


class KREBDLIBS_API Plugin: public Object {

protected:
	SmallArrayList* fLocalData ;

public :

	DEFINE_NEW(Plugin);
	DEFINE_DELETE(Plugin);

	Plugin(GContext* newGContext) : Object(newGContext) {
		fLocalData = NULL ;
	}

	virtual	~Plugin() {
		flushLocalData();
	}


	// BinaryMarshalizable

	virtual void complete(Serializer* /*serializer*/){}

	virtual void marshalRestore(ObjectReader* /*reader*/, long /*version*/, Group** /*previousGroup*/, View** /*previousView*/, Option** /*previousOption*/){}

	// Plugin

	virtual void postRestoreInternal(long version){
		postRestore(version);
	}

	virtual void postRestore(long /*version*/){	}

	/*
	* Local data management
	*/
/*
<kaleidoc>
<filename>Plugin</filename>
<page>
<api>
    <class>Plugin</class>
    <method>insertQueryString</method>
    <java></java>
    <cpp>void insertQueryString(char* newString)</cpp>
    <descr>
        <p>This method may be used to add/update new parameters to the current set of local parameters. It keeps pointers to the strings provided to insertQueryString. So it is important:</p>
       <itemlist>
            <item><p>not to use constant strings as source strings as they may be modified by the parser,</p></item>
           <item><p>not to delete the source strings while they are still referenced and used there.</p></item>
       </itemlist>
    </descr>
</api>
</page>
</kaleidoc>
*/
	void insertQueryString(char* newString)	{
		fLocalData = SmallArrayList::insertQueryString(newString, fLocalData);
	}

	void flushLocalData() {
		SAFE_DELETE(fLocalData) ;
	}

/*
 <kaleidoc>
<filename>Plugin</filename>
<page>
<api>
     <class>Plugin</class>
     <method>evaluateString</method>
     <java></java>
     <cpp>virtual char* Plugin::evaluateString(char* source, int *status=NULL)</cpp>
     <descr>
         <p>This method allows evaluating the string source and it returns the result of this evaluation. If status!=NULL, status will be updated by the method (cf. STAT_EVAL_xxxx in KR_Plugin.h).</p>
         <note>The ownership of source is not transferred to the method evaluateString, but the ownership of the returned value is transferred to the caller.</note>
     </descr>
 </api>
</page>
</kaleidoc>
*/
	virtual char* evaluateString(char* source, int *status=NULL)
	{
		if(status) *status=STAT_EVAL_OK ;
		return xstrdup((char*) getContext()->findData(source)) ;
	}

/*
<kaleidoc>
<filename>Plugin</filename>
<page>
<api>
    <class>Plugin</class>
    <method>findStrData</method>
    <java></java>
    <cpp>char* findStrData(char* varName, char* defValue)</cpp>
    <descr>
        <p>This method allows finding back the values currently associated to the keys in the current set of local parameters. This value is considered as a string. If there is no value currently associated to the key varName, defValue is returned.</p>
        <p>This method accepts values coded as $mycode. In this case, mycode is evaluated by Plugin::evaluateString() and findStrData() is using the GContext's tmpBuffer to store and free the value returned by evaluateString().</p>
    </descr>
</api>
</page>
</kaleidoc>
*/

	/*
	* BEWARE: this method uses the GContext's tmpBuffer.
	*/
	char* findStrData(char* varName, char* defValue)			{
		if(!fLocalData) return defValue ;
		char* val = fLocalData->findStrHTValue(varName, defValue) ;
		if(val && *val=='$')
		{
			char* rslt = evaluateString(val+1) ;
			if(!rslt) return NULL;
			char* tmp = getContext()->getTmpBuffer() ;
			strcpy(tmp, rslt) ;
			SAFE_FREE(rslt);
			return tmp ;
		}
		return val ;
	}
/*
<kaleidoc>
<filename>Plugin</filename>
<page>
<api>
    <class>Plugin</class>
    <method>findIntData</method>
    <java></java>
    <cpp>int findIntData(char* varName, int defValue)</cpp>
    <descr>
        <p>This method allows finding back the value currently associated to the keys in the current set of local parameters. This value is then converted into a integer value. If there is no value currently associated to the key varName, defValue is returned.</p>
        <p>This method accepts values coded as $mycode. In this case, mycode is evaluated by Plugin::evaluateString() and findIntData() returns the "atoi" of the result of the evaluation.</p>
    </descr>
</api>
</page>
</kaleidoc>

*/
	int findIntData(char* varName, int defValue,char** endptr = NULL)
	{
		if(!fLocalData) return defValue ;
		char* val = fLocalData->findStrHTValue(varName, NULL) ;
		if(val && *val=='$')
		{
			char* rslt = evaluateString(val+1) ;
			int iRslt = a2i(rslt,endptr);
			SAFE_DELETE(rslt);
			return iRslt ;
		}
		return fLocalData->findIntHTValue(varName, defValue, endptr) ;
	}


#ifdef DEV_CONSISTENCY
	virtual char *getInfo(int itemType, int itemIdx)
	{
		return defaultGetInfo(itemType, itemIdx);
	}
#ifdef DEV_DEBUG
	virtual void verboseInfo(int verboseLevel, char* intro)
	{
		Verbose(verboseLevel, "%s version=%s desc=%s last updted=%s\n",
			intro,
			getInfo(CSTCY_VERSION, 0),
			getInfo(CSTCY_DESCR, 0),
			getInfo(CSTCY_UPDDATE, 0)) ;
	}
#endif // def DEV_DEBUG
#endif // def DEV_CONSISTENCY

};

typedef Plugin* pPlugin ;
typedef pPlugin (*PluginInstanciator)(GContext* newGContext) ;

#endif // __KR_PLUGIN__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -