Adorable Fuzzball |
Sharoth wrote:Exxxxxcellent! Release... the 501st NyanTroopers to invade Sharoth's workplace servers.Ambrosia Slaad wrote:He's busy baking you a trojan fruitcake filled with terracotta Cosmos to steal your hoard.NOOOOOOOOOO!!!!! ~runs off to protect my hoard~
MEWWWWWWWWWWWWWWWW!!
John Napier 698 |
So, in an effort to understand this, (and you can blame/thank Orthos for me resurrecting this thread) I'll try to apply my knowledge of C++ to this. Beginning with Post #1.
*Ahem*
class OExpandingLoaf;
class OPartialLoaf : public OExpandingLoaf;
class RegionLoaf : public OExpandingLoaf;
class OVirtualLoaf : public OExpandingLoaf;
class InnerLoaf;
class SplitLoaf : public InnerLoaf;
class DspLoaf : public InnerLoaf;
So, when we talk about loaves of a particular type becoming loaves of other types, we're talking about Polymorphism. Therefore
class OPartialLoaf : public OExpandingLoaf
{
public:
RegionLoaf OPartialLoaf::RegionLoaf();
SplitLoaf OPartialLoaf::SplitLoaf();
};
class OVirtualLoaf : public OExpandingLoaf
{
public:
RegionLoaf OVirtualLoaf::RegionLoaf();
SplitLoaf OVirtualLoaf::SplitLoaf();
};
class RegionLoaf : public OExpandingLoaf
{
public:
SplitLoaf RegionLoaf::SplitLoaf();
};
Is there anything wrong with my understanding of the problem thus far?
John Napier 698 |
Post #1, part 2.
Let's call it a LoafWrapper. Its job is to pretend that it's a Loaf that can "become" other kinds of Loafs. It does this by keeping a private Loaf no one else can see. When asked to do anything, it lets the private Loaf do all the work. (And get none of the credit!) When asked to become some other kind of Loaf, it gets a new private Loaf of the requested type, and unceremoniously dumps the old private Loaf onto the garbage heap. LoafWrapper's kind of a jerk, I suppose.
Here's the problem: The Loafs that can become a SplitLoaf (OPartialLoaf, OVirtualLoaf and RegionLoaf) are actually cousins of SplitLoaf instead of siblings. If LoafWrapper is a member of the RegionLoaf family, then it can't pretend to be a SplitLoaf -- they're not directly related.
What family should LoafWrapper be a part of?
LoafWrapper should be a union of all loaf types, such that
union ULoaf
{
class OPartialLoaf OPL;
class RegionLoaf RL;
class OVirtualLoaf OVL;
class SplitLoaf SL;
class DspLoaf DL;
};
This means that LoafWrapper inherits the properties of all loaf types, so that
class LoafWrapper : public ULoaf;
The private Loaf is a Union of all loaf types, and LoafWrapper is a set of copy constructors using operator= overloading, returning a pointer to the new loaf type before deleting the pointer to the old loaf type.
Thus,
class LoafWrapper : public ULoaf
{
private:
ULoaf Loaf;
public:
RegionLoaf operator=( OPartialLoaf );
SplitLoaf operator=( OPartialLoaf);
RegionLoaf operator=( OVirtualLoaf );
SplitLoaf operator=( OVirtualLoaf );
SplitLoaf operator=( RegionLoaf );
};
LoafWrapper should be untyped, as it's a collection of helper functions.
Is my understanding of the second part clear?
John Napier 698 |
Post #7
There are, of course, any number of ways to solve the Loaf question. Perhaps the LoafWrapper is inherently impossible. (I don't think so, but haven't determined whether it is yet. I'm lazy like that.)
So introduce a notification center. If you have a Loaf which might become another kind of Loaf, you tell the notification center you'd like to be notified when your Loaf becomes something else.
A Loaf, when asked to become another kind of Loaf, would then post a notification saying, "I was this Loaf, but now I'm this other Loaf." The notification center then informs everyone who was interested in that particular Loaf about the change. In response, you switch your reference to the original Loaf to the new Loaf.
This would work, but I don't think it's scalable. There are probably going to be millions of Loafs, and who knows if the notification center can handle that kind of burden?
(Now, given that the Loafs are part of the Ent, perhaps the notification center would be built using an Ent! Then it would be scalable, but in a weird way that makes my head spin.)
Ah. A new term. The Ent. A walking tree of long memory.
So now, LoafWrapper has a new public member called notification, which is a structure containing two members OldLoafType and NewLoafType, which are both short integers, so that
struct SNotification
{
short OldLoafType;
short NewLoafType;
};
and LoafWrapper becomes
class LoafWrapper : public ULoaf
{
private:
ULoaf Loaf;
public:
struct SNotification Notification;
RegionLoaf operator=( OPartialLoaf );
SplitLoaf operator=( OPartialLoaf);
RegionLoaf operator=( OVirtualLoaf );
SplitLoaf operator=( OVirtualLoaf );
SplitLoaf operator=( RegionLoaf );
};
The members of Notification are set by the copy constructors. When the program reads the values of Notification, both members are set to zero. The actual values held in OldLoafType and NewLoafType are implementation defined, and non-zero.
So an Ent would be an array or list with SNotification members, so that
struct SNotification Ent[MAX_INT]; // an arbitrary number, 2GB
Gary Teter Senior Software Developer |