From 4293e8854a30443e4d5818fc55df404976dbfd9b Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 14 Nov 2009 14:14:21 +0000 Subject: update the info system, fixes network info exchange --- src/core/info.cc | 97 ++++++-------------------------------------------------- 1 file changed, 10 insertions(+), 87 deletions(-) (limited to 'src/core/info.cc') diff --git a/src/core/info.cc b/src/core/info.cc index 8f843c4..ca23d79 100644 --- a/src/core/info.cc +++ b/src/core/info.cc @@ -16,33 +16,21 @@ namespace core /* ---- class InfoType --------------------------------------------- */ -// server-side constructor, assigns id InfoType::InfoType(const char *label) { - infotype_id_counter++; - infotype_id = infotype_id_counter; if (label) set_label(label); infotype_registry.push_back(this); } -// client-side constructor, receives id -InfoType::InfoType(const unsigned int id) -{ - infotype_id = id; - infotype_registry.push_back(this); -} - InfoType::~InfoType() { - infotype_id = 0; } /* ---- static InfoType registry ----------------------------------- */ InfoType::Registry InfoType::infotype_registry; -unsigned int InfoType::infotype_id_counter = 0; void InfoType::clear() { @@ -51,8 +39,6 @@ void InfoType::clear() delete infotype; } infotype_registry.clear(); - infotype_id_counter = 0; - } InfoType *InfoType::find(const std::string & label) @@ -69,28 +55,12 @@ InfoType *InfoType::find(const std::string & label) return 0; } -InfoType *InfoType::find(const unsigned int id) -{ - if (!id) - return 0; - - for (Registry::iterator it = infotype_registry.begin(); it != infotype_registry.end(); it++) { - InfoType *infotype = (*it); - if (infotype->id() == id) { - return infotype; - } - } - return 0; -} - /* ---- class Info ------------------------------------------------- */ // server-side constructor, assigns id -Info::Info() +Info::Info(const InfoType *type) { - info_id_counter++; - info_id = info_id_counter; - info_type = 0; + info_type = type; info_model = 0; info_timestamp = 0; @@ -99,18 +69,6 @@ Info::Info() info_registry.push_back(this); } -// client-side constructor, receives id -Info::Info(const unsigned int id) -{ - info_id = id; - info_type = 0; - - info_timestamp = 0; - info_model = 0; - info_price = 0; - - info_registry.push_back(this); -} Info::~Info() { @@ -119,6 +77,7 @@ Info::~Info() info_text.clear(); info_timestamp = 0; info_model = 0; + info_type = 0; } void Info::set_type(const InfoType *type) @@ -175,7 +134,7 @@ void Info::clear_text() void Info::serialize_server_update(std::ostream & os) const { - os << " \"" << label() << "\" \"" << name() << "\" \"" << modelname() << "\" " << info_text.size() << " "; + os << '"' << name() << "\" \"" << modelname() << "\" " << info_text.size() << " "; for (Text::const_iterator it = info_text.begin(); it != info_text.end(); it++) { if (it != info_text.begin()) @@ -190,13 +149,8 @@ void Info::receive_server_update(std::istream &is) std::string n; char c; - // read label - while ((is.get(c)) && (c != '"')); - while ((is.get(c)) && (c != '"')) - n += c; - set_label(n); - // read name + n.clear(); while ((is.get(c)) && (c != '"')); while ((is.get(c)) && (c != '"')) n += c; @@ -207,7 +161,6 @@ void Info::receive_server_update(std::istream &is) while ((is.get(c)) && (c != '"')); while ((is.get(c)) && (c != '"')) n += c; - set_modelname(n); // read info text @@ -226,19 +179,19 @@ 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; 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 << " label: ^B" << label() << " ^Nname: ^B" << name() << " ^Nmodel: ^B" << modelname() << "^N" << std::endl; + con_print << " type: ^B" << type()->label() << " ^Nlabel: ^B" << label() << " ^Nname: ^B" << name() << " ^Nmodel: ^B" << modelname() << "^N" << std::endl; } } /* ---- static info registry --------------------------------------- */ Info::Registry Info::info_registry; -unsigned int Info::info_id_counter = 0; Info *Info::find(const char *label) { @@ -268,20 +221,6 @@ Info *Info::find(const std::string & label) return 0; } -Info *Info::find(const 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::search(const std::string & searchstr) { if (!searchstr.size()) @@ -337,20 +276,6 @@ Info *Info::find(const InfoType *type, const std::string & label) return 0; } -Info *Info::find(const InfoType *type, const unsigned int id) -{ - if (!id) - return 0; - - for (Registry::iterator it = info_registry.begin(); it != info_registry.end(); it++) { - Info *info = (*it); - if ((info->type() == type) && (info->id() == id)) { - return info; - } - } - return 0; -} - Info *Info::search(const InfoType *type, const std::string & searchstr) { if (!searchstr.size()) @@ -387,7 +312,6 @@ void Info::clear() delete info; } info_registry.clear(); - info_id_counter = 0; InfoType::clear(); } @@ -404,20 +328,19 @@ void Info::list() con_print << info_registry.size() << " info " << aux::plural("record", info_registry.size()) << std::endl; } -void Info::list_class(const InfoType *type) +void Info::list(const InfoType *type) { size_t count = 0; for (Registry::iterator it = info_registry.begin(); it != info_registry.end(); it++) { core::Info *info = (*it); if (info->type() == type) { - count++; - + count++; con_print << " " << "^B" << aux::pad_right(info->label(), 12) << "^N " << info->name() << "^N" << std::endl; } } - con_print << count << " info " << aux::plural("record", count) << std::endl; + con_print << count << " " << type->label() << " info " << aux::plural("record", count) << std::endl; } } -- cgit v1.2.3