Index: ps/trunk/source/tools/atlas/AtlasObject/AtlasObject.h
===================================================================
--- ps/trunk/source/tools/atlas/AtlasObject/AtlasObject.h (revision 22160)
+++ ps/trunk/source/tools/atlas/AtlasObject/AtlasObject.h (revision 22161)
@@ -1,196 +1,196 @@
-/* Copyright (C) 2015 Wildfire Games.
+/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see .
*/
// Public interface to almost all of AtlasObject.
// (See AtlasObjectText for the rest of it).
//
// Tries to include as few headers as possible, to minimise its impact
// on compile times.
#ifndef INCLUDED_ATLASOBJECT
#define INCLUDED_ATLASOBJECT
#if defined(_WIN32)
# define _CRT_SECURE_NO_WARNINGS // Disable deprecation warning in VS2008
#endif
#include // for wchar_t
#include
class wxString;
//////////////////////////////////////////////////////////////////////////
// Mostly-private bits:
// Helper class to let us define a conversion operator only for AtSmartPtr
template struct ConstCastHelper { operator ConstSmPtr (); };
template struct ConstCastHelper { };
// Simple reference-counted pointer. class T must contain a reference count,
// initialised to 0. An external implementation (in AtlasObjectImpl.cpp)
// provides the inc_ref and dec_ref methods, so that this header file doesn't
// need to know their implementations.
template class AtSmartPtr : public ConstCastHelper, T>
{
friend struct ConstCastHelper, T>;
private:
void inc_ref();
void dec_ref();
T* ptr;
public:
// Constructors
AtSmartPtr() : ptr(NULL) {}
explicit AtSmartPtr(T* p) : ptr(p) { inc_ref(); }
// Copy constructor
AtSmartPtr(const AtSmartPtr& r) : ptr(r.ptr) { inc_ref(); }
// Assignment operators
AtSmartPtr& operator=(T* p) { dec_ref(); ptr = p; inc_ref(); return *this; }
AtSmartPtr& operator=(const AtSmartPtr& r) { if (&r != this) { dec_ref(); ptr = r.ptr; inc_ref(); } return *this; }
// Destructor
~AtSmartPtr() { dec_ref(); }
// Allow conversion from non-const T* to const T*
//operator AtSmartPtr () { return AtSmartPtr(ptr); } // (actually provided by ConstCastHelper)
// Override ->
T* operator->() const { return ptr; }
// Test whether the pointer is pointing to anything
- explicit operator bool() const { return ptr != NULL; }
+ explicit operator bool() const { return ptr != nullptr; }
};
template
ConstCastHelper::operator ConstSmPtr ()
{
return ConstSmPtr(static_cast*>(this)->ptr);
}
// A few required declarations
class AtObj;
class AtNode;
class AtIterImpl;
//////////////////////////////////////////////////////////////////////////
// Public bits:
// AtIter is an iterator over AtObjs - use it like:
//
// for (AtIter thing = whatever["thing"]; thing.defined(); ++thing)
// DoStuff(thing);
//
// to handle XML data like:
//
//
// Stuff 1
// Stuff 2
//
class AtIter
{
public:
// Increment the iterator; or make it undefined, if there weren't any
// AtObjs left to iterate over
AtIter& operator++ ();
// Return whether this iterator has an AtObj to point to
bool defined() const;
// Return whether this iterator is pointing to a non-contentless AtObj
bool hasContent() const;
// Return the number of AtObjs that will be iterated over (including the current one)
size_t count() const;
// Return an iterator to the children matching 'key'. (That is, children
// of the AtObj currently pointed to by this iterator)
const AtIter operator[] (const char* key) const;
// Return the AtObj currently pointed to by this iterator
const AtObj operator* () const;
// Return the string value of the AtObj currently pointed to by this iterator
operator const wchar_t* () const;
// Private implementation. (But not 'private:', because it's a waste of time
// adding loads of friend functions)
- AtSmartPtr p;
+ AtSmartPtr m_Impl;
};
class AtObj
{
public:
AtObj() {}
- AtObj(const AtObj& r) : p(r.p) {}
+ AtObj(const AtObj& r) : m_Node(r.m_Node) {}
// Return an iterator to the children matching 'key'
const AtIter operator[] (const char* key) const;
// Return the string value of this object
operator const wchar_t* () const;
// Return the floating point value of this object
double getDouble() const;
// Return the integer value of this object
int getInt() const;
// Check whether the object contains anything (even if those things are empty)
- bool defined() const { return (bool)p; }
+ bool defined() const { return static_cast(m_Node); }
// Check recursively whether there's actually any non-empty data in the object
bool hasContent() const;
// Add or set a child. The wchar_t* and wxString& versions create a new
// AtObj with the appropriate string value, then use that as the child.
//
// These alter the AtObj's internal pointer, and the pointed-to data is
// never actually altered. Copies of this AtObj (including copies stored
// inside other AtObjs) will not be affected.
void add(const char* key, const wchar_t* value);
void add(const char* key, const wxString& value);
void add(const char* key, AtObj& data);
void set(const char* key, const wchar_t* value);
void set(const char* key, const wxString& value);
void set(const char* key, AtObj& data);
void setBool(const char* key, bool value);
void setDouble(const char* key, double value);
void setInt(const char* key, int value);
void setString(const wchar_t* value);
void addOverlay(AtObj& data);
- AtSmartPtr p;
+ AtSmartPtr m_Node;
};
// Miscellaneous utility functions:
namespace AtlasObject
{
// Returns AtObj() on failure - test with AtObj::defined()
AtObj LoadFromXML(const std::string& xml);
// Returns AtObj() on failure - test with AtObj::defined()
AtObj LoadFromJSON(const std::string& json);
// Returns UTF-8-encoded XML document string.
// Returns empty string on failure.
std::string SaveToXML(AtObj& obj);
// Returns UTF-8-encoded JSON string.
// Returns empty string on failure.
std::string SaveToJSON(AtObj& obj);
AtObj TrimEmptyChildren(AtObj& obj);
}
#endif // INCLUDED_ATLASOBJECT
Index: ps/trunk/source/tools/atlas/AtlasObject/AtlasObjectImpl.cpp
===================================================================
--- ps/trunk/source/tools/atlas/AtlasObject/AtlasObjectImpl.cpp (revision 22160)
+++ ps/trunk/source/tools/atlas/AtlasObject/AtlasObjectImpl.cpp (revision 22161)
@@ -1,347 +1,346 @@
-/* Copyright (C) 2015 Wildfire Games.
+/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see .
*/
#include "AtlasObject.h"
#include "AtlasObjectImpl.h"
#include
#include
#include
#define ATSMARTPTR_IMPL(T) \
template<> void AtSmartPtr::inc_ref() \
{ \
- if (ptr) ++ptr->refcount; \
+ if (ptr) ++ptr->m_Refcount; \
} \
\
template<> void AtSmartPtr::dec_ref() \
{ \
- if (ptr && --ptr->refcount == 0) \
+ if (ptr && --ptr->m_Refcount == 0) \
delete ptr; \
} // (Don't set ptr=NULL, since it should never be possible for an
// unreferenced pointer to exist; I would rather see it die in debug
// mode if that ever happens, instead of just silently ignoring the error.)
ATSMARTPTR_IMPL(AtNode)
ATSMARTPTR_IMPL(const AtNode)
ATSMARTPTR_IMPL(AtIterImpl)
//////////////////////////////////////////////////////////////////////////
const AtIter AtIter::operator [] (const char* key) const
{
- if (p)
- return p->iter->second->getChild(key);
+ if (m_Impl)
+ return m_Impl->iter->second->getChild(key);
else
return AtIter();
}
AtIter::operator const wchar_t* () const
{
- if (p)
- return p->iter->second->value.c_str();
+ if (m_Impl)
+ return m_Impl->iter->second->m_Value.c_str();
else
return L"";
}
//AtIter::operator const AtObj () const
const AtObj AtIter::operator * () const
{
- if (p)
+ if (m_Impl)
{
AtObj ret;
- ret.p = p->iter->second;
+ ret.m_Node = m_Impl->iter->second;
return ret;
}
else
return AtObj();
}
AtIter& AtIter::operator ++ ()
{
- assert(p);
+ assert(m_Impl);
// Increment the internal iterator, and stop if we've run out children
// to iterate over.
- if (p && ++p->iter == p->iter_upperbound)
- p = NULL;
+ if (m_Impl && ++m_Impl->iter == m_Impl->iter_upperbound)
+ m_Impl = nullptr;
return *this;
}
bool AtIter::defined() const
{
- return (bool)p;
+ return static_cast(m_Impl);
}
bool AtIter::hasContent() const
{
- if (!p)
+ if (!m_Impl)
return false;
- if (! p->iter->second)
+ if (!m_Impl->iter->second)
return false;
- return p->iter->second->hasContent();
+ return m_Impl->iter->second->hasContent();
}
size_t AtIter::count() const
{
- if (!p)
+ if (!m_Impl)
return 0;
- return std::distance(p->iter, p->iter_upperbound);
+ return std::distance(m_Impl->iter, m_Impl->iter_upperbound);
}
//////////////////////////////////////////////////////////////////////////
const AtIter AtObj::operator [] (const char* key) const
{
- if (p)
- return p->getChild(key);
+ if (m_Node)
+ return m_Node->getChild(key);
else
// This object doesn't exist, so return another object that doesn't exist
return AtIter();
}
AtObj::operator const wchar_t* () const
{
- if (p)
- return p->value.c_str();
+ if (m_Node)
+ return m_Node->m_Value.c_str();
else
return L"";
}
double AtObj::getDouble() const
{
double val = 0;
- if (p)
+ if (m_Node)
{
std::wstringstream s;
- s << p->value;
+ s << m_Node->m_Value;
s >> val;
}
return val;
}
int AtObj::getInt() const
{
int val = 0;
- if (p)
+ if (m_Node)
{
std::wstringstream s;
- s << p->value;
+ s << m_Node->m_Value;
s >> val;
}
return val;
}
void AtObj::add(const char* key, AtObj& data)
{
- if (!p)
- p = new AtNode();
+ if (!m_Node)
+ m_Node = new AtNode();
- p = p->addChild(key, data.p);
+ m_Node = m_Node->addChild(key, data.m_Node);
}
void AtObj::add(const char* key, const wxString& value)
{
add(key, value.wc_str());
}
void AtObj::add(const char* key, const wchar_t* value)
{
const AtNode* o = new AtNode(value);
- if (!p)
- p = new AtNode();
+ if (!m_Node)
+ m_Node = new AtNode();
- p = p->addChild(key, AtNode::Ptr(o));
+ m_Node = m_Node->addChild(key, AtNode::Ptr(o));
}
void AtObj::set(const char* key, AtObj& data)
{
- if (!p)
- p = new AtNode();
+ if (!m_Node)
+ m_Node = new AtNode();
- p = p->setChild(key, data.p);
+ m_Node = m_Node->setChild(key, data.m_Node);
}
void AtObj::set(const char* key, const wxString& value)
{
set(key, value.wc_str());
}
void AtObj::set(const char* key, const wchar_t* value)
{
const AtNode* o = new AtNode(value);
- if (!p)
- p = new AtNode();
+ if (!m_Node)
+ m_Node = new AtNode();
- p = p->setChild(key, AtNode::Ptr(o));
+ m_Node = m_Node->setChild(key, AtNode::Ptr(o));
}
void AtObj::setBool(const char* key, bool value)
{
AtNode* o = new AtNode(value ? L"true" : L"false");
- o->children.insert(AtNode::child_pairtype("@boolean", AtNode::Ptr(new AtNode())));
+ o->m_Children.insert(AtNode::child_pairtype("@boolean", AtNode::Ptr(new AtNode())));
- if (!p)
- p = new AtNode();
+ if (!m_Node)
+ m_Node = new AtNode();
- p = p->setChild(key, AtNode::Ptr(o));
+ m_Node = m_Node->setChild(key, AtNode::Ptr(o));
}
void AtObj::setDouble(const char* key, double value)
{
std::wstringstream str;
str << value;
AtNode* o = new AtNode(str.str().c_str());
- o->children.insert(AtNode::child_pairtype("@number", AtNode::Ptr(new AtNode())));
+ o->m_Children.insert(AtNode::child_pairtype("@number", AtNode::Ptr(new AtNode())));
- if (!p)
- p = new AtNode();
+ if (!m_Node)
+ m_Node = new AtNode();
- p = p->setChild(key, AtNode::Ptr(o));
+ m_Node = m_Node->setChild(key, AtNode::Ptr(o));
}
void AtObj::setInt(const char* key, int value)
{
std::wstringstream str;
str << value;
AtNode* o = new AtNode(str.str().c_str());
- o->children.insert(AtNode::child_pairtype("@number", AtNode::Ptr(new AtNode())));
+ o->m_Children.insert(AtNode::child_pairtype("@number", AtNode::Ptr(new AtNode())));
- if (!p)
- p = new AtNode();
+ if (!m_Node)
+ m_Node = new AtNode();
- p = p->setChild(key, AtNode::Ptr(o));
+ m_Node = m_Node->setChild(key, AtNode::Ptr(o));
}
void AtObj::setString(const wchar_t* value)
{
- if (!p)
- p = new AtNode();
+ if (!m_Node)
+ m_Node = new AtNode();
- p = p->setValue(value);
+ m_Node = m_Node->setValue(value);
}
void AtObj::addOverlay(AtObj& data)
{
- if (!p)
- p = new AtNode();
+ if (!m_Node)
+ m_Node = new AtNode();
- p = p->addOverlay(data.p);
+ m_Node = m_Node->addOverlay(data.m_Node);
}
bool AtObj::hasContent() const
{
- if (!p)
+ if (!m_Node)
return false;
- return p->hasContent();
+ return m_Node->hasContent();
}
//////////////////////////////////////////////////////////////////////////
const AtIter AtNode::getChild(const char* key) const
{
// Find the range of matching children
- AtNode::child_maptype::const_iterator it = children.lower_bound(key);
- AtNode::child_maptype::const_iterator it_upper = children.upper_bound(key);
+ AtNode::child_maptype::const_iterator it = m_Children.lower_bound(key);
+ AtNode::child_maptype::const_iterator it_upper = m_Children.upper_bound(key);
if (it == it_upper) // No match found
return AtIter();
AtIter obj;
- obj.p = new AtIterImpl(it, it_upper);
+ obj.m_Impl = new AtIterImpl(it, it_upper);
return obj;
}
bool AtNode::hasContent() const
{
- if (value.length())
+ if (m_Value.length())
return true;
- for (child_maptype::const_iterator it = children.begin(); it != children.end(); ++it)
- if (it->second && it->second->hasContent())
+ for (const child_maptype::value_type& child : m_Children)
+ if (child.second && child.second->hasContent())
return true;
return false;
}
const AtNode::Ptr AtNode::setValue(const wchar_t* value) const
{
AtNode* newNode = new AtNode();
- newNode->children = children;
- newNode->value = value;
+ newNode->m_Children = m_Children;
+ newNode->m_Value = value;
return AtNode::Ptr(newNode);
}
const AtNode::Ptr AtNode::setChild(const char* key, const AtNode::Ptr &data) const
{
AtNode* newNode = new AtNode(this);
- newNode->children.erase(key);
- newNode->children.insert(AtNode::child_pairtype(key, data));
+ newNode->m_Children.erase(key);
+ newNode->m_Children.insert(AtNode::child_pairtype(key, data));
return AtNode::Ptr(newNode);
}
const AtNode::Ptr AtNode::addChild(const char* key, const AtNode::Ptr &data) const
{
AtNode* newNode = new AtNode(this);
- newNode->children.insert(AtNode::child_pairtype(key, data));
+ newNode->m_Children.insert(AtNode::child_pairtype(key, data));
return AtNode::Ptr(newNode);
}
const AtNode::Ptr AtNode::addOverlay(const AtNode::Ptr &data) const
{
AtNode* newNode = new AtNode(this);
// Delete old childs that are also in the overlay
- for (AtNode::child_maptype::const_iterator it = data->children.begin(); it != data->children.end(); ++it)
- newNode->children.erase(it->first);
+ for (AtNode::child_maptype::const_iterator it = data->m_Children.begin(); it != data->m_Children.end(); ++it)
+ newNode->m_Children.erase(it->first);
// Add the overlay childs back in
- for (AtNode::child_maptype::const_iterator it = data->children.begin(); it != data->children.end(); ++it)
- newNode->children.insert(*it);
+ for (AtNode::child_maptype::const_iterator it = data->m_Children.begin(); it != data->m_Children.end(); ++it)
+ newNode->m_Children.insert(*it);
return AtNode::Ptr(newNode);
}
//////////////////////////////////////////////////////////////////////////
AtObj AtlasObject::TrimEmptyChildren(AtObj& obj)
{
AtObj ret;
- for (AtNode::child_maptype::const_iterator it = obj.p->children.begin();
- it != obj.p->children.end(); ++it)
+ for (const AtNode::child_maptype::value_type& child : obj.m_Node->m_Children)
{
- if (it->second && it->second->hasContent())
+ if (child.second && child.second->hasContent())
{
AtObj node;
- node.p = it->second;
- ret.add(it->first.c_str(), node);
+ node.m_Node = child.second;
+ ret.add(child.first.c_str(), node);
}
}
return ret;
}
Index: ps/trunk/source/tools/atlas/AtlasObject/AtlasObjectImpl.h
===================================================================
--- ps/trunk/source/tools/atlas/AtlasObject/AtlasObjectImpl.h (revision 22160)
+++ ps/trunk/source/tools/atlas/AtlasObject/AtlasObjectImpl.h (revision 22161)
@@ -1,86 +1,86 @@
-/* Copyright (C) 2009 Wildfire Games.
+/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see .
*/
#include "AtlasObject.h"
#include
#ifdef _MSC_VER
// Avoid complaints about unreachable code; the optimiser is realising
// that some code is incapable of throwing, then warning about the catch
// block that will never be executed.
#pragma warning(disable: 4702)
#include