On 04/03/2014 at 06:58, xxxxxxxx wrote:
Originally posted by xxxxxxxx
I won't guarantee that it compiles fine now, though. I think best might be if I give you
a working example.
Hi Niklas!
I got it working!
Here is code that compiles:
template<typename Type> inline Type* RetrieveTableX(NodeData* data)
{
return (Type* ) C4DOS.Bl->RetrieveTableX(data, 0);
}
class ButterFly;
class ButterFlyData : public NodeData
{
private:
Real _someValue;
public:
/* Called when ButterFly::SetSomeValue() is called. */
virtual void SetSomeValue(Real value)
{
_someValue = value;
}
virtual Real GetSomeValue()
{
return _someValue;
}
static ButterFlyData* NewButterFlyData()
{
return gNew ButterFlyData;
}
};
struct BUTTERFLYPLUGIN : public NODEPLUGIN
{
void (ButterFlyData::*SetSomeValue)(Real);
Real (ButterFlyData::*GetSomeValue)();
};
class ButterFly : public BaseList2D
{
private:
ButterFly();
~ButterFly();
public:
void SetSomeValue(Real value) const
{
ButterFlyData* data = static_cast<ButterFlyData*>(GetNodeData());
if(!data)
return;// nullptr;
BUTTERFLYPLUGIN* method_table = RetrieveTableX<BUTTERFLYPLUGIN>(data);
if(!method_table)
return;// nullptr;
return (data->*method_table->SetSomeValue)(value);
}
Real GetSomeValue() const
{
ButterFlyData* data = static_cast<ButterFlyData*>(GetNodeData());
if(!data)
return -9.9;// nullptr;
BUTTERFLYPLUGIN* method_table = RetrieveTableX<BUTTERFLYPLUGIN>(data);
if(!method_table)
return -9.9;// nullptr;
return (data->*method_table->GetSomeValue)();
}
static ButterFly* Alloc()
{
return static_cast<ButterFly*>(BaseList2D::Alloc(ID_BUTTERFLY_PLUGIN));
}
static void Free(ButterFly* &ptr)
{
#ifdef DEBUG
if(!ptr)
{
DiagnosticOutput("Passed nullptr to ButterFly::Free()");
DebugStop();
}
if(!ptr->IsInstanceOf(ID_BUTTERFLY_PLUGIN))
{
DiagnosticOutput("Non-Butterfly Plugin node passed to ButterFly::Free()");
DebugStop();
}
#endif
if(ptr)
{
BaseList2D::Free((BaseList2D*&)ptr);
}
}
};
But I have this issue now, I cannot Register it:
1. Bool b = RegisterNodePlugin(ID_BUTTERFLY_PLUGIN, "butterfly", PLUGINFLAG_HIDE
2. , (NodeData* )ButterFlyData::NewButterFlyData
3. , NULL, 0, 0);
Line 2, have no idea how to write a DataAlloctator that will satisfy the compiler.
So I am stuck here. Can you help me out here? When this compiles, I think I have it!
Originally posted by xxxxxxxx
But let me ask you first: Why do you actually want to create a BaseList2D subclass? Any
special reason for this? As I said above already, it usually makes sense only when you
want to provide an API to your plugin for other developers.
Can we make a deal? When it compiles, and registers properly, so that I can use it, I will tell you. Ok?