CEL plugin template by Darek
$NAME$ should be replaced by name of the plugin. Needs only different capitalizing sometimes. You can use it manually or as snippet in KDevelop.
Interface
#ifndef __CEL_PF_$NAME$__ #define __CEL_PF_$NAME$__ #include "cstypes.h" #include "csutil/scf.h" /** * $NAME$ property class. * * This property class supports the following actions (add prefix * 'cel.action.' to get the ID of the action and add prefix 'cel.parameter.' * to get the ID of the parameter): * * This property class supports the following properties (add prefix * 'cel.property.' to get the ID of the property: */ struct iPc$NAME$ : public virtual iBase { SCF_INTERFACE (iPc$NAME$, 0, 0, 1); }; #endif // __CEL_PF_$NAME$__
Header
#ifndef __CEL_PF_$NAME$FACT__ #define __CEL_PF_$NAME$FACT__ #include "cstypes.h" #include "csutil/scf.h" #include "physicallayer/propclas.h" #include "physicallayer/propfact.h" #include "physicallayer/facttmpl.h" #include "celtool/stdpcimp.h" #include "celtool/stdparams.h" struct iObjectRegistry; /** * Factory for $NAME$. */ CEL_DECLARE_FACTORY($NAME$) /** * This is a $NAME$ property class. */ class celPc$NAME$ : public scfImplementationExt1< celPc$NAME$, celPcCommon, iPc$NAME$> { private: // action parameters static csStringID id_a; static csStringID id_b; static csStringID id_c; celOneParameterBlock* params; // actions enum actionids { action_a = 0, action_b, action_c }; // properties enum propids { propid_a = 0, propid_b, propid_c }; static PropertyHolder propinfo; public: celPc$NAME$ (iObjectRegistry* object_reg); virtual ~celPc$NAME$ (); virtual const char* GetName () const { return "pc$NAME$"; } virtual csPtr<iCelDataBuffer> Save (); virtual bool Load (iCelDataBuffer* databuf); virtual bool PerformActionIndexed (int, iCelParameterBlock* params, celData& ret); virtual bool SetPropertyIndexed (int, bool); virtual bool GetPropertyIndexed (int, bool*&); }; #endif // __CEL_PF_$NAME$FACT__
Code
#include "cssysdef.h" #include "plugins/propclass/$NAME$/$NAME$.h" #include "physicallayer/pl.h" #include "physicallayer/entity.h" #include "physicallayer/persist.h" #include "physicallayer/datatype.h" #include "behaviourlayer/behave.h" #include "celtool/stdparams.h" #include "ivaria/reporter.h" CS_IMPLEMENT_PLUGIN CEL_IMPLEMENT_FACTORY ($NAME$, "pc$NAME$") static bool Report (iObjectRegistry* object_reg, const char* msg, ...) { va_list arg; va_start (arg, msg); csRef<iReporter> rep (csQueryRegistry<iReporter> (object_reg)); if (rep) rep->ReportV (CS_REPORTER_SEVERITY_ERROR, "cel.propclass.$NAME$", msg, arg); else { csPrintfV (msg, arg); csPrintf ("\n"); fflush (stdout); } va_end (arg); return false; } csStringID celPc$NAME$::id_a = csInvalidStringID; csStringID celPc$NAME$::id_b = csInvalidStringID; csStringID celPc$NAME$::id_c = csInvalidStringID; PropertyHolder celPc$NAME$::propinfo; celPc$NAME$::celPc$NAME$ (iObjectRegistry* object_reg) : scfImplementationType (this, object_reg) { if (id_a == csInvalidStringID) { id_a = pl->FetchStringID ("cel.parameter.a"); id_b = pl->FetchStringID ("cel.parameter.b"); id_c = pl->FetchStringID ("cel.parameter.c"); } params = new celOneParameterBlock (); params->SetParameterDef (id_a, "a"); propholder = &propinfo; if (!propinfo.actions_done) { AddAction (action_a, "cel.action.A"); AddAction (action_b, "cel.action.B"); AddAction (action_c, "cel.action.C"); } propinfo.SetCount (3); AddProperty (propid_a, "cel.property.a", CEL_DATA_BOOL, false, "Description A.", 0); AddProperty (propid_b, "cel.property.b", CEL_DATA_BOOL, false, "Description B.", 0); AddProperty (propid_c, "cel.property.c", CEL_DATA_BOOL, false, "Description C.", 0); } celPc$NAME$::~celPc$NAME$ () { delete params; } #define $NAME$_SERIAL 1 csPtr<iCelDataBuffer> celPc$NAME$::Save () { csRef<iCelDataBuffer> databuf = pl->CreateDataBuffer ($NAME$_SERIAL); return csPtr<iCelDataBuffer> (databuf); } bool celPc$NAME$::Load (iCelDataBuffer* databuf) { int serialnr = databuf->GetSerialNumber (); if (serialnr != $NAME$_SERIAL) return Report (object_reg, "Serialnr != $NAME$_SERIAL. Cannot load."); return true; } bool celPc$NAME$::PerformActionIndexed (int idx, iCelParameterBlock* params, celData& ret) { switch (idx) { case action_a: { return true; } case action_b: { return true; } case action_c: { return true; } default: return false; } } bool celPc$NAME$::SetPropertyIndexed (int idx, bool val) { switch (idx) { case propid_a: { return true; } case propid_b: { return true; } case propid_c: { return true; } default: return false; } } bool celPc$NAME$::GetPropertyIndexed (int idx, bool& val) { switch (idx) { case propid_a: { return true; } case propid_b: { return true; } case propid_c: { return true; } default: return false; } }