本文整理汇总了C++中IObject::AddRef方法的典型用法代码示例。如果您正苦于以下问题:C++ IObject::AddRef方法的具体用法?C++ IObject::AddRef怎么用?C++ IObject::AddRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IObject
的用法示例。
在下文中一共展示了IObject::AddRef方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BIF_ObjCreate
void BIF_ObjCreate(ExprTokenType &aResultToken, ExprTokenType *aParam[], int aParamCount)
{
IObject *obj = NULL;
if (aParamCount == 1) // L33: POTENTIALLY UNSAFE - Cast IObject address to object reference.
{
obj = (IObject *)TokenToInt64(*aParam[0]);
if (obj < (IObject *)1024) // Prevent some obvious errors.
obj = NULL;
else
obj->AddRef();
}
else
obj = Object::Create(aParam, aParamCount);
if (obj)
{
aResultToken.symbol = SYM_OBJECT;
aResultToken.object = obj;
// DO NOT ADDREF: after we return, the only reference will be in aResultToken.
}
else
{
aResultToken.symbol = SYM_STRING;
aResultToken.marker = _T("");
}
}
示例2: BIF_ObjInvoke
void BIF_ObjInvoke(ExprTokenType &aResultToken, ExprTokenType *aParam[], int aParamCount)
{
int invoke_type;
IObject *obj;
ExprTokenType *obj_param;
// Since ObjGet/ObjSet/ObjCall are not publicly accessible as functions, Func::mName
// (passed via aResultToken.marker) contains the actual flag rather than a name.
invoke_type = (int)(INT_PTR)aResultToken.marker;
// Set default return value; ONLY AFTER THE ABOVE.
aResultToken.symbol = SYM_STRING;
aResultToken.marker = _T("");
obj_param = *aParam; // aParam[0]. Load-time validation has ensured at least one parameter was specified.
++aParam;
--aParamCount;
if (obj = TokenToObject(*obj_param))
{
bool param_is_var = obj_param->symbol == SYM_VAR;
if (param_is_var)
// Since the variable may be cleared as a side-effect of the invocation, call AddRef to ensure the object does not expire prematurely.
// This is not necessary for SYM_OBJECT since that reference is already counted and cannot be released before we return. Each object
// could take care not to delete itself prematurely, but it seems more proper, more reliable and more maintainable to handle it here.
obj->AddRef();
obj->Invoke(aResultToken, *obj_param, invoke_type, aParam, aParamCount);
if (param_is_var)
obj->Release();
}
// Invoke meta-functions of g_MetaObject.
else if (INVOKE_NOT_HANDLED == g_MetaObject.Invoke(aResultToken, *obj_param, invoke_type | IF_META, aParam, aParamCount)
// If above did not handle it, check for attempts to access .base of non-object value (g_MetaObject itself).
// CALL is unsupported (for simplicity); SET is supported only in "multi-dimensional" mode: "".base[x]:=y
&& invoke_type != IT_CALL && (invoke_type == IT_SET ? aParamCount > 2 : aParamCount)
&& !_tcsicmp(TokenToString(*aParam[0]), _T("base")))
{
if (aParamCount > 1) // "".base[x] or similar
{
// Re-invoke g_MetaObject without meta flag or "base" param.
ExprTokenType base_token;
base_token.symbol = SYM_OBJECT;
base_token.object = &g_MetaObject;
g_MetaObject.Invoke(aResultToken, base_token, invoke_type, aParam + 1, aParamCount - 1);
}
else // "".base
{
// Return a reference to g_MetaObject. No need to AddRef as g_MetaObject ignores it.
aResultToken.symbol = SYM_OBJECT;
aResultToken.object = &g_MetaObject;
}
}
}