Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/info.cc')
-rw-r--r--src/core/info.cc85
1 files changed, 72 insertions, 13 deletions
diff --git a/src/core/info.cc b/src/core/info.cc
index ca23d79..dc7a8b3 100644
--- a/src/core/info.cc
+++ b/src/core/info.cc
@@ -56,19 +56,46 @@ InfoType *InfoType::find(const std::string & label)
}
/* ---- class Info ------------------------------------------------- */
+unsigned int info_id_counter = 0;
-// server-side constructor, assigns id
+// server-side constructor, assigns an id
Info::Info(const InfoType *type)
{
+ info_id_counter++;
+ info_id = info_id_counter;
info_type = type;
+ info_registry.push_back(this);
info_model = 0;
info_timestamp = 0;
info_price = 0;
+}
+// client-side constructor, does not assign an id
+Info::Info(const InfoType *type, const std::string & label)
+{
+ info_id = 0;
+ info_type = type;
info_registry.push_back(this);
+
+ info_model = 0;
+ info_timestamp = 0;
+ info_price = 0;
+
+ set_label(label);
}
+// client-side constructor, does not assign an id
+Info::Info(const unsigned int id)
+{
+ info_id = id;
+ info_type = 0;
+ info_registry.push_back(this);
+
+ info_model = 0;
+ info_timestamp = 0;
+ info_price = 0;
+}
Info::~Info()
{
@@ -80,6 +107,11 @@ Info::~Info()
info_type = 0;
}
+void Info::set_id(const unsigned int id)
+{
+ info_id = id;
+}
+
void Info::set_type(const InfoType *type)
{
info_type = type;
@@ -179,13 +211,11 @@ void Info::receive_server_update(std::istream &is)
void Info::print() const
{
- con_print << " type: ^B" << type()->label() << " ^Nlabel: ^B" << label() << " ^Nname: ^B" << name() << " ^Nmodel: ^B" << modelname() << "^N" << std::endl;
+ con_print << " id: ^B" << std::setw(4) << id() << " type: ^B" << (type() ? type()->label() : "NULL") << " ^Nlabel: ^B" << label() << " ^Nname: ^B" << name() << " ^Nmodel: ^B" << modelname() << "^N" << std::endl;
if (info_text.size()) {
for (Text::const_iterator it = info_text.begin(); it != info_text.end(); it++) {
con_print << " " << (*it) << std::endl;
}
- } else {
- con_print << " type: ^B" << type()->label() << " ^Nlabel: ^B" << label() << " ^Nname: ^B" << name() << " ^Nmodel: ^B" << modelname() << "^N" << std::endl;
}
}
@@ -193,11 +223,25 @@ void Info::print() const
Info::Registry Info::info_registry;
+Info *Info::find(unsigned int id)
+{
+ if (!id)
+ return 0;
+
+ for (Registry::iterator it = info_registry.begin(); it != info_registry.end(); it++) {
+ Info *info = (*it);
+ if (info->id() == id) {
+ return info;
+ }
+ }
+ return 0;
+}
+
Info *Info::find(const char *label)
{
if (!label)
return 0;
-
+
for (Registry::iterator it = info_registry.begin(); it != info_registry.end(); it++) {
Info *info = (*it);
if (info->label().compare(label) == 0) {
@@ -312,18 +356,34 @@ void Info::clear()
delete info;
}
info_registry.clear();
+ info_id_counter = 0;
InfoType::clear();
}
+void Info::list_header()
+{
+ con_print << " "
+ << " id "
+ << "type "
+ << "label "
+ << "name" << std::endl;
+}
+void Info::list(const Info *info)
+{
+ con_print << " "
+ << "^B" << std::setw(4) << info->id() << " "
+ << "^B" << (info->type() ? aux::pad_right(info->type()->label(), 8) : "NULL ") << " "
+ << "^B" << aux::pad_right(info->label(), 12) << " "
+ << "^N" << info->name() << std::endl;
+}
+
void Info::list()
{
+ list_header();
for (Registry::iterator it = info_registry.begin(); it != info_registry.end(); it++) {
Info *info = (*it);
- con_print << " "
- << "^B" << aux::pad_right(info->type()->label(), 8) << "^N "
- << "^B" << aux::pad_right(info->label(), 12) << "^N "
- << info->name() << "^N" << std::endl;
+ list(info);
}
con_print << info_registry.size() << " info " << aux::plural("record", info_registry.size()) << std::endl;
}
@@ -331,13 +391,12 @@ void Info::list()
void Info::list(const InfoType *type)
{
size_t count = 0;
+ list_header();
for (Registry::iterator it = info_registry.begin(); it != info_registry.end(); it++) {
core::Info *info = (*it);
if (info->type() == type) {
- count++;
- con_print << " "
- << "^B" << aux::pad_right(info->label(), 12) << "^N "
- << info->name() << "^N" << std::endl;
+ count++;
+ list(info);
}
}
con_print << count << " " << type->label() << " info " << aux::plural("record", count) << std::endl;