📄 _piclass.h
字号:
/*____________________________________________________________________________*\
*
Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.
These sources, libraries and applications are
FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
as long as the following conditions are adhered to.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*____________________________________________________________________________*|
*
* $Source: /cvsroot/pi3web/Pi3Web_200/Source/Pi2API/_PIClass.h,v $
* $Date: 2003/05/13 18:42:09 $
*
Description:
Implementation of the PIAPI class class. This class doesn't do a lot by
itself, mainly it serves to force the interfaces to the derived classes
as well as having a virtual Destructor.
\*____________________________________________________________________________*/
/* $HeaderTop:$ */
#ifndef _PICLASS_H_
#define _PICLASS_H_
#include <assert.h>
#include "Pi2API.h"
#include "PIString.h"
#include "_PIDB.h"
#include "_PIDBKey.h"
#include "PIDLL.h"
/*____________________________________________________________________________*\
*
Class:
Description:
\*____________________________________________________________________________*/
class _PIClass
{
public:
enum Type { IO, LOGIC, SLL };
enum Function {
ON_CLASS_LOAD=0,
CONSTRUCTOR,
COPYCONSTRUCTOR,
DESTRUCTOR,
/* this must always be last */
LAST_FUNCTION
};
typedef int (* PfnFunction)(void *, int, const char *[] );
private:
PIDLL *pDll;
PIString sName;
PIString sDescription;
PfnFunction aFunctionFrame[ LAST_FUNCTION ];
public:
_PIClass(
PIDLL *pTheDll,
const char *pClassName,
const char *pClassDescription,
PfnFunction *pFunctions,
_PIDB *pDB )
: pDll( pTheDll )
{
assert( pClassName && pClassDescription && pFunctions );
memcpy( aFunctionFrame, pFunctions, sizeof( aFunctionFrame ) );
sName = pClassName;
sDescription = pClassDescription;
onClassLoad( STARTUP, pDB );
};
virtual ~_PIClass()
{
onClassLoad( SHUTDOWN, 0 );
};
virtual Type GetType() const=0;
virtual const char *GetClassName() const=0;
/* --- accessor functions --- */
inline const PIString &GetName() const { return sName; };
inline const PIString &GetDescription() const { return sDescription; };
inline PIDLL *GetLibrary() const { return pDll; };
/* --- Implement function calls --- */
inline int onClassLoad( PIClass_LoadAction eLoadAction, _PIDB *pDB ) const
{
return (
( int (*)( PIClass_LoadAction eLoadAction, _PIDB * ) )
aFunctionFrame[ON_CLASS_LOAD] ) ( eLoadAction, pDB );
};
int Constructor( _PIObject *pObj, int iArgc, const char *ppArgv[] ) const;
int CopyConstructor( _PIObject *pObj, int iArgc,
const char *ppArgv[] ) const;
int Destructor( _PIObject *pObj, int iArgc, const char *ppArgv[] ) const;
/* --- static member functions */
static const _PIClass *Lookup( _PIDB *pDB, const char *pClassName );
static const _PIClass *Load( _PIDB *pDB, PIConfigDB *pConfigDB,
const char *pClassName );
static const _PIClass *LookupOrLoad( _PIDB *pDB, PIConfigDB *pConfigDB,
const char *pClassName );
};
#endif /* _PICLASS_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -