cinterface.h

Engine/source/cinterface/cinterface.h

More...

Classes:

Public Defines

define
CALL_CINTERFACE_FUNCTION(name, ...) { char *v[] = { __VA_ARGS__ }; (name, v, sizeof(v) / sizeof(*v));}

Detailed Description

Public Defines

CALL_CINTERFACE_FUNCTION(name, ...) { char *v[] = { __VA_ARGS__ }; (name, v, sizeof(v) / sizeof(*v));}
 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#pragma once
25#include "platform/platformDlibrary.h"
26#include "console/engineAPI.h"
27#include "console/simBase.h"
28
29#define CALL_CINTERFACE_FUNCTION(name, ...){const char *v[] = { __VA_ARGS__ }; CInterface::CallFunction(name, v, sizeof(v) / sizeof(*v));}
30
31class CInterface {
32   typedef bool(*IsMethodCallback)(const char* className, const char* methodName);
33   typedef void(*CallMainCallback)();
34   typedef const char* (*CallFunctionCallback)(const char* nameSpace, const char* name, const char **argv, int argc, bool *result);
35   typedef const char* (*CallMethodCallback)(const char* className, const char* classNamespace, U32 object, const char* name, const char **argv, int argc, bool *result);
36   IsMethodCallback mIsMethodCallback;
37   CallFunctionCallback mFunctionCallback;
38   CallMethodCallback mMethodCallback;
39   CallMainCallback mMainCallback;
40   const char* _CallFunction(const char* nameSpace, const char* name, const char **argv, int argc, bool *result) const;
41   const char* _CallMethod(const char* className, const char* classNamespace, U32 object, const char* name, const char **argv, int argc, bool *res) const;
42   void _CallMain(bool *res) const;
43   bool _isMethod(const char* className, const char* methodName) const;
44public:
45   CInterface()
46   {
47      mFunctionCallback = NULL;
48      mMethodCallback = NULL;
49      mIsMethodCallback = NULL;
50      mMainCallback = NULL;
51   }
52
53   static const char* CallFunction(const char* nameSpace, const char* name, const char **argv, int argc, bool *result);
54   static const char* CallMethod(SimObject* obj, const char* name, const char **argv, int argc, bool *res);
55   static void CallMain(bool *res);
56   static bool isMethod(const char* className, const char* methodName);
57   static CInterface& GetCInterface();
58   void SetCallFunctionCallback(void* ptr) { mFunctionCallback = (CallFunctionCallback)ptr; };
59   void SetCallMethodCallback(void* ptr) { mMethodCallback = (CallMethodCallback)ptr; };
60   void SetCallIsMethodCallback(void* ptr) { mIsMethodCallback = (IsMethodCallback)ptr; };
61   void SetMainCallback(void* ptr) { mMainCallback = (CallMainCallback)ptr; };
62};
63