dtGame::MessageFactory Class Reference

#include <messagefactory.h>

List of all members.

Public Member Functions

 MessageFactory (const std::string &name, const MachineInfo &machine, const std::string &desc="")
 Constructor.
 ~MessageFactory ()
 Destructor.
template<typename T>
void RegisterMessageType (const MessageType &type)
 Function in which all supported message types will be registered.
const std::string & GetName () const
 Gets the name of the factory.
const std::string & GetDescription () const
 Gets the description of the factory.
const MachineInfoGetMachineInfo () const
 Gets the name of the factory.
bool IsMessageTypeSupported (const MessageType &msg) const
 Tells is a message type is supported.
void GetSupportedMessageTypes (std::vector< const MessageType * > &vec)
 Gets a list of supported types.
const MessageTypeGetMessageTypeById (unsigned short id) const
 Returns a MessageType for the corresponding id.
const MessageTypeGetMessageTypeByName (const std::string &name) const
 Returns a MessageType for the corresponding name.
template<typename MessageClassName>
void CreateMessage (const MessageType &msgType, dtCore::RefPtr< MessageClassName > &result)
 Creates a message from the factory and fills a passed in refptr.
dtCore::RefPtr< MessageCreateMessage (const MessageType &msgType)
 Creates a message from the factory.
dtCore::RefPtr< MessageCloneMessage (const Message &msg)
 Make a copy of a message.

Classes

class  MessageFactoryException


Constructor & Destructor Documentation

dtGame::MessageFactory::MessageFactory ( const std::string &  name,
const MachineInfo machine,
const std::string &  desc = "" 
)

Constructor.

dtGame::MessageFactory::~MessageFactory (  ) 

Destructor.


Member Function Documentation

template<typename T>
void dtGame::MessageFactory::RegisterMessageType ( const MessageType type  )  [inline]

Function in which all supported message types will be registered.

Parameters:
The type to register
Note:
The template should be the class the MessageType corresponds to

const std::string& dtGame::MessageFactory::GetName (  )  const [inline]

Gets the name of the factory.

Returns:
The name

const std::string& dtGame::MessageFactory::GetDescription (  )  const [inline]

Gets the description of the factory.

Returns:
The description

const MachineInfo& dtGame::MessageFactory::GetMachineInfo (  )  const [inline]

Gets the name of the factory.

Returns:
The name

bool dtGame::MessageFactory::IsMessageTypeSupported ( const MessageType msg  )  const

Tells is a message type is supported.

Returns:
True if it is, false if not

void dtGame::MessageFactory::GetSupportedMessageTypes ( std::vector< const MessageType * > &  vec  ) 

Gets a list of supported types.

Parameters:
The vector to fill

const MessageType & dtGame::MessageFactory::GetMessageTypeById ( unsigned short  id  )  const

Returns a MessageType for the corresponding id.

Note:
this throws an exception rather than returning a NULL pointer when the id is not found because One should never call this with an invalid id.
Returns:
A reference to the MessageType
Exceptions:
dtUtil::Exception with enum MessageFactoryException::TYPE_NOT_REGISTERED if the type is not found.

const MessageType * dtGame::MessageFactory::GetMessageTypeByName ( const std::string &  name  )  const

Returns a MessageType for the corresponding name.

Returns:
A pointer to the MessageType or NULL if there was no matching message type.

template<typename MessageClassName>
void dtGame::MessageFactory::CreateMessage ( const MessageType msgType,
dtCore::RefPtr< MessageClassName > &  result 
) [inline]

Creates a message from the factory and fills a passed in refptr.

This is templated so one can pass in a ref ptr to the actual subclass of dtGame::Message and fill it without having to do a cast outside the method.

Parameters:
msgType The type of message to generate
result A RefPtr to fill with the created message.
Returns:
A pointer to the message, or NULL if error
Exceptions:
dtUtil::Exception if the given message type is not registered.

dtCore::RefPtr< Message > dtGame::MessageFactory::CreateMessage ( const MessageType msgType  ) 

Creates a message from the factory.

This only returns a poiner to a Message. One should use the templated version of the method unless there is no need to have a subclass of Message.

Parameters:
msgType The type of message to generate
Returns:
A pointer to the message, or NULL if error
Exceptions:
dtUtil::Exception if the given message type is not registered.

dtCore::RefPtr< Message > dtGame::MessageFactory::CloneMessage ( const Message msg  ) 

Make a copy of a message.

It makes sure the right type is created and then calls the message to copy the data.

Parameters:
msg the message to clone
the clone.
Exceptions:
dtUtil::Exception if the message cannot be cloned.


http://www.delta3d.org
2.0.0 generated 14 Feb 2008