App/Toponaming: Minor refactoring and tests for StringID
This commit is contained in:
committed by
Chris Hennes
parent
2e5f43e69b
commit
c9f73bda9e
@@ -102,7 +102,7 @@ PyObject* StringID::getPyObject()
|
||||
|
||||
PyObject* StringID::getPyObjectWithIndex(int index)
|
||||
{
|
||||
auto* res = new StringIDPy(this);
|
||||
auto res = new StringIDPy(this);
|
||||
res->_index = index;
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include <CXX/Objects.hxx>
|
||||
#include <utility>
|
||||
|
||||
#include <Base/PyObjectBase.h>
|
||||
|
||||
|
||||
namespace Data
|
||||
{
|
||||
@@ -170,12 +172,19 @@ public:
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
/// Returns the postfix
|
||||
QByteArray postfix() const
|
||||
{
|
||||
return _postfix;
|
||||
}
|
||||
|
||||
/// Sets the postfix
|
||||
void setPostfix(QByteArray postfix)
|
||||
{
|
||||
_postfix = std::move(postfix);
|
||||
}
|
||||
|
||||
PyObject* getPyObject() override;
|
||||
/// Returns a Python tuple containing both the text and index
|
||||
PyObject* getPyObjectWithIndex(int index);
|
||||
@@ -186,7 +195,7 @@ public:
|
||||
* The format is #<id>. And if index is non zero, then #<id>:<index>. Both
|
||||
* <id> and <index> are in hex format.
|
||||
*/
|
||||
std::string toString(int index) const;
|
||||
std::string toString(int index = 0) const;
|
||||
|
||||
/// Light weight structure of holding a string ID and associated index
|
||||
struct IndexID
|
||||
@@ -244,20 +253,18 @@ public:
|
||||
std::string dataToText(int index) const;
|
||||
|
||||
/** Get the content of this StringID as QByteArray
|
||||
* @param bytes: output bytes
|
||||
* @param index: optional index.
|
||||
*/
|
||||
void toBytes(QByteArray& bytes, int index) const
|
||||
QByteArray dataToBytes(int index = 0) const
|
||||
{
|
||||
QByteArray res(_data);
|
||||
if (index != 0) {
|
||||
res += QByteArray::number(index);
|
||||
}
|
||||
if (_postfix.size() != 0) {
|
||||
bytes = _data + _postfix;
|
||||
}
|
||||
else if (index != 0) {
|
||||
bytes = _data + QByteArray::number(index);
|
||||
}
|
||||
else {
|
||||
bytes = _data;
|
||||
res += _postfix;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Mark this StringID as used
|
||||
@@ -530,7 +537,7 @@ public:
|
||||
void toBytes(QByteArray& bytes) const
|
||||
{
|
||||
if (_sid) {
|
||||
_sid->toBytes(bytes, _index);
|
||||
bytes = _sid->dataToBytes(_index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user