/* core/info.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_CORE_INFO_H__ #define __INCLUDED_CORE_INFO_H__ #include #include #include #include #include "core/label.h" #include "model/model.h" namespace core { /** * @brief an information card category * The InfoType groups information records of the same type */ class InfoType : public Label { public: /// info registry type definition typedef std::vector Registry; /** * @brief create a new information card category * The constructor automaticly adds the instance to the registry */ InfoType(const char* label); virtual ~InfoType(); /* ---- static infoclass registry ---------------------------------- */ /// clear infotype registry static void clear(); /// search the infotype registry for a label static InfoType *find(const std::string & label); inline static const Registry ®istry() { return infotype_registry; } /// list the infotypes static void list(); private: static Registry infotype_registry; }; // class InfoType /** * @brief an information card * An information record holds extended information about a specific entity or item class. * This information is exchanged between server and the client, and can be used to build * HUD widgets. */ class Info : public Label { public: /// type definition for the text description typedef std::deque Text; /** * @brief create a new server-side information card * This constructor assigns an id */ Info(const InfoType *type, const char *label = 0); /** * @brief create a new client-side information card */ Info(const unsigned int id); /// delete the information record virtual ~Info(); /* ---- inspectors ------------------------------------------------- */ inline const unsigned int id() const { return info_id; } inline const InfoType* type() const { return info_type; } inline const std::string & modelname() const { return info_modelname; } inline const long price() const { return info_price; } inline const float volume() const { return info_volume; } /** * @brief timestamp * The timestamp is used client-side, a non-zero value * indicates the time when the info was last requested. * If the info has been received from the server, the timestamp * is set to 0 */ inline const unsigned long ×tamp() const { return info_timestamp; } /** * @brief text description */ inline const Text & text() const { return info_text; } /* ---- mutators --------------------------------------------------- */ void set_id(const unsigned int); void set_modelname(const std::string & modelname); void set_modelname(const char *modelname); /** * @brief associated price, in credits */ void set_price(const long price); /** * @brief associated volume, in cubic meters */ void set_volume(const float volume); /// set the timestamp void set_timestamp(const unsigned long timestamp); /// add a line of info text void add_line(const std::string & text); /// add a line of info text void add_line(const char *text); /// add info text without newline void add_text(const std::string & text); /// add info text without newline void add_text(const char *text); /// clear the info text void clear_text(); /// print info to the system console virtual void print() const; /// clear the timestamp void clear_timestamp(); /// set the info class type void set_type(const InfoType *type); public: /* ---- serializers ------------------------------------------------ */ /// serialize a server-to-client update on a stream void serialize_server_update(std::ostream & os) const; /// receive a server-to-client update from a stream void receive_server_update(std::istream &is); private: const InfoType* info_type; unsigned int info_id; long info_price; float info_volume; unsigned long info_timestamp; std::string info_modelname; Text info_text; /* ---- static info registry --------------------------------------- */ public: /** * @brief info registry type definition */ typedef std::vector Registry; /** * @brief the info registry */ static inline Registry & registry() { return info_registry; } /** * @brief search the info registry for a record with the specified id */ static Info *find(const unsigned int id); /** * @brief search the info registry for a labeled item */ static Info *find(const char * label); /** * @brief search the info registry for a label */ static Info *find(const std::string & label); /** * @brief search the info register for a pointer */ static Info *find(const Info *info); /// 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 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(); /// print the list header static void list_header(); /// list a single record static void list(const Info *info); /// list the info registry static void list(); /// list a single class in the info registry static void list(const InfoType *type); private: static Registry info_registry; }; } #endif // __INCLUDED_CORE_INFO_H__