constify inventory item serialization

This commit is contained in:
Giuseppe Bilotta 2011-08-10 23:22:44 +02:00
parent ecd5c5f920
commit 88a9bae160
2 changed files with 14 additions and 19 deletions

View File

@ -320,7 +320,7 @@ void InventoryList::clearItems()
//setDirty(true); //setDirty(true);
} }
void InventoryList::serialize(std::ostream &os) void InventoryList::serialize(std::ostream &os) const
{ {
//os.imbue(std::locale("C")); //os.imbue(std::locale("C"));
@ -661,7 +661,7 @@ Inventory & Inventory::operator = (const Inventory &other)
return *this; return *this;
} }
void Inventory::serialize(std::ostream &os) void Inventory::serialize(std::ostream &os) const
{ {
for(u32 i=0; i<m_lists.size(); i++) for(u32 i=0; i<m_lists.size(); i++)
{ {

View File

@ -49,7 +49,7 @@ public:
virtual const char* getName() const = 0; virtual const char* getName() const = 0;
// Shall write the name and the parameters // Shall write the name and the parameters
virtual void serialize(std::ostream &os) = 0; virtual void serialize(std::ostream &os) const = 0;
// Shall make an exact clone of the item // Shall make an exact clone of the item
virtual InventoryItem* clone() = 0; virtual InventoryItem* clone() = 0;
#ifndef SERVER #ifndef SERVER
@ -133,7 +133,7 @@ public:
{ {
return "MaterialItem"; return "MaterialItem";
} }
virtual void serialize(std::ostream &os) virtual void serialize(std::ostream &os) const
{ {
//os.imbue(std::locale("C")); //os.imbue(std::locale("C"));
os<<"MaterialItem2"; os<<"MaterialItem2";
@ -208,18 +208,13 @@ public:
{ {
return "MBOItem"; return "MBOItem";
} }
virtual void serialize(std::ostream &os) virtual void serialize(std::ostream &os) const
{ {
for(;;) std::string sane_string(m_inventorystring);
{ str_replace_char(sane_string, '|', '?');
size_t t = m_inventorystring.find('|');
if(t == std::string::npos)
break;
m_inventorystring[t] = '?';
}
os<<getName(); os<<getName();
os<<" "; os<<" ";
os<<m_inventorystring; os<<sane_string;
os<<"|"; os<<"|";
} }
virtual InventoryItem* clone() virtual InventoryItem* clone()
@ -266,7 +261,7 @@ public:
{ {
return "CraftItem"; return "CraftItem";
} }
virtual void serialize(std::ostream &os) virtual void serialize(std::ostream &os) const
{ {
os<<getName(); os<<getName();
os<<" "; os<<" ";
@ -343,7 +338,7 @@ public:
{ {
return "ToolItem"; return "ToolItem";
} }
virtual void serialize(std::ostream &os) virtual void serialize(std::ostream &os) const
{ {
os<<getName(); os<<getName();
os<<" "; os<<" ";
@ -461,7 +456,7 @@ public:
InventoryList(std::string name, u32 size); InventoryList(std::string name, u32 size);
~InventoryList(); ~InventoryList();
void clearItems(); void clearItems();
void serialize(std::ostream &os); void serialize(std::ostream &os) const;
void deSerialize(std::istream &is); void deSerialize(std::istream &is);
InventoryList(const InventoryList &other); InventoryList(const InventoryList &other);
@ -525,7 +520,7 @@ public:
Inventory(const Inventory &other); Inventory(const Inventory &other);
Inventory & operator = (const Inventory &other); Inventory & operator = (const Inventory &other);
void serialize(std::ostream &os); void serialize(std::ostream &os) const;
void deSerialize(std::istream &is); void deSerialize(std::istream &is);
InventoryList * addList(const std::string &name, u32 size); InventoryList * addList(const std::string &name, u32 size);
@ -591,7 +586,7 @@ struct InventoryAction
static InventoryAction * deSerialize(std::istream &is); static InventoryAction * deSerialize(std::istream &is);
virtual u16 getType() const = 0; virtual u16 getType() const = 0;
virtual void serialize(std::ostream &os) = 0; virtual void serialize(std::ostream &os) const = 0;
virtual void apply(InventoryContext *c, InventoryManager *mgr) = 0; virtual void apply(InventoryContext *c, InventoryManager *mgr) = 0;
}; };
@ -639,7 +634,7 @@ struct IMoveAction : public InventoryAction
return IACTION_MOVE; return IACTION_MOVE;
} }
void serialize(std::ostream &os) void serialize(std::ostream &os) const
{ {
os<<"Move "; os<<"Move ";
os<<count<<" "; os<<count<<" ";