BaseMixin

The base class for any IRule or ILogic mixin objects.  There are certain classes of rules or logic that require some kind of plugin architecture so that they can be extended by other modules.  For example, at the start of the game, one IRule may handle initializing all of the Game data.  However, what if other plugin modules have new data that needs to be initialized?  Unless there was some way to notify that one IRule that there were other things that needed to be initialized, the situation would be hopeless.

Enter BaseMixin.  The BaseMixin class provides a base class for new classes of mixin interfaces.  An IRule may be derived from a mixin interface so that it supports being extended.  The BaseMixin class stores a string-based hash map internally.  In the RuleEngine, when an IRule is executed, the RuleEngine checks to see if the IRule has BaseMixin in its inheritancy chart (via a dynamic_cast<>).  If so, the RuleEngine looks up in its internal string-based hash map to see if there are any mixin names for the IRule.  If so, it copies those hash pairs into the BaseMixin hash map.  A mixin value is nothing more than the name of another IRule or piece of ILogic that somehow extends the IRule with the mixin interface.  It is up to the particular derived mixin interface to determine what it does with the actual mixin names.  BaseMixin provides two means of accessing the hash map.  If the derived mixin interface just wants to iterate through all of the available mixins, it can use the hash_begin and hash_end functions to iterate.  If it needs to lookup the value at a particular key, it can use the hash_value function.  See LogicBooleanMixin or RuleExtensionMixin for examples of derived mixin interfaces.

Project

RulesCore

Include

BaseMixin.h

Summary
The base class for any IRule or ILogic mixin objects.
Returns the mixin name at the given key.
Returns an iterator to the start of the mixin hash map.
Returns an iterator to the end of the mixin hash map.
The string-based hash of mixin names.

Protected

Summary
Returns the mixin name at the given key.
Returns an iterator to the start of the mixin hash map.
Returns an iterator to the end of the mixin hash map.

Destructor

Functions

hash_value

const wxString &hash_value(const wxString &key)

Returns the mixin name at the given key.  If none exists, an empty string is returned.  It is up to the calling function to decide what to do with it.

Parameters

keyThe key to look up in the mixin hash map.

Returns

A const reference to a string containing the mixin name at the given key.

hash_begin

IRuleEngine::StringHash::const_iterator hash_begin() const

Returns an iterator to the start of the mixin hash map.

Returns

A const iterator to the start of the mixin hash map.

hash_end

IRuleEngine::StringHash::const_iterator hash_end() const

Returns an iterator to the end of the mixin hash map.

Returns

A const iterator to the end of the mixin hash map.

Private

Summary
The string-based hash of mixin names.

Variables

mStringHash

IRuleEngine::StringHash mStringHash

The string-based hash of mixin names.

The interface for a single game rule.
The interface of a single piece of game logic.
const wxString &hash_value(const wxString &key)
Returns the mixin name at the given key.
IRuleEngine::StringHash::const_iterator hash_begin() const
Returns an iterator to the start of the mixin hash map.
IRuleEngine::StringHash::const_iterator hash_end() const
Returns an iterator to the end of the mixin hash map.
IRuleEngine::StringHash mStringHash
The string-based hash of mixin names.
Still volatile.
The default implementation of the IRuleEngine interface.
A mixin object for ILogic that makes true or false decisions.
A mixin object for IRules that extends the IRule with other IRules.
RulesCore is the HOSS of Cities3D.