From a993d31910b63a1f897e470842934e6ffefad32c Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 13 Nov 2009 22:25:09 +0000 Subject: added core::InfoType, refactored game::ShipModel as core::Info subclass, introduced core::Label --- src/core/info.h | 148 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 109 insertions(+), 39 deletions(-) (limited to 'src/core/info.h') diff --git a/src/core/info.h b/src/core/info.h index 9f1fab8..13f38f8 100644 --- a/src/core/info.h +++ b/src/core/info.h @@ -12,48 +12,101 @@ #include #include +#include "core/label.h" #include "model/model.h" namespace core { +/** + * @brief an object class information record + * Describes a class of object + */ +class InfoType : public Label +{ +public: + /** + * @brief create a server side object class information record + */ + InfoType(const char* label); + + /** + * @brief create a client side object class information record + */ + InfoType(const unsigned int id); + + virtual ~InfoType(); + + /* ---- inspectors ------------------------------------------------- */ + + inline const unsigned int id() const { + return infotype_id; + } + +private: + + unsigned int infotype_id; + + + /* ---- static infoclass registry ---------------------------------- */ + +public: + /// clear infotype registry + static void clear(); + + /// search the infotype registry for a label + static InfoType *find(const std::string & label); + + /// search the infotype registry for an id + static InfoType *find(const unsigned int id); + + +private: + /// info registry type definition + typedef std::vector Registry; + + static Registry infotype_registry; + static unsigned int infotype_id_counter; + +}; // class InfoType + /** * @brief an information record * An information record holds extended information about a specific entity or item class. * This information isexchanged between server and the client, and can be used to build * HUD widgets/ */ -class Info +class Info : public Label { public: /// type definition for the text description typedef std::deque Text; - /// create a new labeled information record + /** + * @brief create a new server-side information record + * This is a server-side constructor and assigns an id + */ Info(); - /// create a new labeled information record - Info(const std::string & label); - + /** + * @brief create a new client-side information record + * This is a client-side constructor + */ Info(const unsigned int id); /// delete the information record - ~Info(); + virtual ~Info(); /* ---- inspectors ------------------------------------------------- */ inline const unsigned int id() const { return info_id; } - - inline const std::string & label() const { - return info_label; - } - inline const std::string & name() const { - return info_name; + inline const InfoType* type() const { + return info_type; } - + inline const std::string & modelname() const { return info_modelname; } @@ -62,6 +115,10 @@ public: return info_model; } + inline const long price() const { + return info_price; + } + inline const unsigned long ×tamp() const { return info_timestamp; } @@ -73,38 +130,38 @@ public: /* ---- mutators --------------------------------------------------- */ - void set_label(const std::string & name); - - void set_label(const char *name); - - void set_name(const std::string & name); - - void set_name(const char *name); - void set_modelname(const std::string & modelname); void set_modelname(const char *modelname); void set_model(const model::Model *model); + void set_price(const long price); + /// set the timestamp void set_timestamp(const unsigned long timestamp); /// add a line of info text void add_text(const std::string & text); + /// add a line of info text + void add_text(const char *text); + /// clear the info text void clear_text(); - /// print info to sys::con_out - void print() const; + /// print info to the system console + virtual void print() const; /// clear the timestamp void clear_timestamp(); - /// add a line of info text - void add_text(const char *text); +protected: + + /// set the info class id + void set_type(const InfoType *type); +public: /* ---- serializers ------------------------------------------------ */ /// serialize a server-to-client update on a stream @@ -114,17 +171,14 @@ public: void receive_server_update(std::istream &is); private: - - unsigned int info_id; + const InfoType* info_type; - std::string info_label; - std::string info_name; + unsigned int info_id; + long info_price; + unsigned long info_timestamp; std::string info_modelname; - + const model::Model* info_model; - - long info_credits; - unsigned long info_timestamp; Text info_text; @@ -133,12 +187,13 @@ private: public: /// info registry type definition typedef std::vector Registry; - + /// the info registry static inline Registry & registry() { return info_registry; } - /// search the info registry for a labeled item + + /// search the info registry for a labeled item static Info *find(const char * label); /// search the info registry for a label @@ -147,18 +202,33 @@ public: /// search the info registry for an id static Info *find(const unsigned int id); + /// search the info registry for a record with a matching label or name + static Info *search(const std::string & searchstr); + + /// search the info registry for a labeled item, belonging to a specific class + static Info *find(const InfoType *type, const char * label); + + /// search the info registry for a label, belonging to a specific class + static Info *find(const InfoType *type, const std::string & label); + + /// search the info registry for an id, belonging to a specific class + static Info *find(const InfoType *type, const unsigned int id); + + /// search the info registry for a record with a matching label or name and belonging to a specific class + static Info *search(const InfoType *type, const std::string & searchstr); + /// clear the info registry static void clear(); /// list the info registry static void list(); -private: - /// add a record to the info registry - static void add(Info *info); + /// list a single class in the info registry + static void list_class(const InfoType *type); +private: static Registry info_registry; - static unsigned int static_info_id_counter; + static unsigned int info_id_counter; }; } -- cgit v1.2.3