Rename OctalCodePtr related functions

This commit is contained in:
Ryan Huffman 2016-05-11 10:43:22 -07:00
parent 35f147f557
commit 5fc18eafda
5 changed files with 15 additions and 14 deletions

View file

@ -73,7 +73,7 @@ void JurisdictionMap::copyContents(const JurisdictionMap& other) {
OctalCodePtr rootOctalCode;
OctalCodePtrList endNodes;
std::tie(rootOctalCode, endNodes) = other.getRootOctalCodeAndEndNodes();
std::tie(rootOctalCode, endNodes) = other.getRootAndEndNodeOctalCodes();
init(rootOctalCode, endNodes);
}
@ -83,7 +83,7 @@ JurisdictionMap::~JurisdictionMap() {
JurisdictionMap::JurisdictionMap(NodeType_t type) : _rootOctalCode(nullptr) {
_nodeType = type;
OctalCodePtr rootCode = allocateOctalCodePtr(1);
OctalCodePtr rootCode = createOctalCodePtr(1);
*rootCode = 0;
OctalCodePtrList emptyEndNodes;
@ -125,7 +125,7 @@ JurisdictionMap::JurisdictionMap(const char* rootHexCode, const char* endNodesHe
}
}
std::tuple<OctalCodePtr, OctalCodePtrList> JurisdictionMap::getRootOctalCodeAndEndNodes() const {
std::tuple<OctalCodePtr, OctalCodePtrList> JurisdictionMap::getRootAndEndNodeOctalCodes() const {
std::lock_guard<std::mutex> lock(_octalCodeMutex);
return std::tuple<OctalCodePtr, OctalCodePtrList>(_rootOctalCode, _endNodes);
}
@ -291,7 +291,7 @@ int JurisdictionMap::unpackFromPacket(ReceivedMessage& message) {
_endNodes.clear();
if (bytes > 0 && bytes <= message.getBytesLeftToRead()) {
_rootOctalCode = allocateOctalCodePtr(bytes);
_rootOctalCode = createOctalCodePtr(bytes);
message.read(reinterpret_cast<char*>(_rootOctalCode.get()), bytes);
// if and only if there's a root jurisdiction, also include the end nodes
@ -303,7 +303,7 @@ int JurisdictionMap::unpackFromPacket(ReceivedMessage& message) {
message.readPrimitive(&bytes);
if (bytes <= message.getBytesLeftToRead()) {
auto endNodeCode = allocateOctalCodePtr(bytes);
auto endNodeCode = createOctalCodePtr(bytes);
message.read(reinterpret_cast<char*>(endNodeCode.get()), bytes);
// if the endNodeCode was 0 length then don't add it

View file

@ -51,7 +51,8 @@ public:
bool writeToFile(const char* filename);
bool readFromFile(const char* filename);
std::tuple<OctalCodePtr, OctalCodePtrList> JurisdictionMap::getRootOctalCodeAndEndNodes() const;
// Provide an atomic way to get both the rootOctalCode and endNodeOctalCodes.
std::tuple<OctalCodePtr, OctalCodePtrList> JurisdictionMap::getRootAndEndNodeOctalCodes() const;
OctalCodePtr getRootOctalCode() const;
OctalCodePtrList getEndNodeOctalCodes() const;

View file

@ -116,14 +116,14 @@ void OctreeSceneStats::copyFromOther(const OctreeSceneStats& other) {
// Now copy the values from the other
if (other._jurisdictionRoot) {
auto bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(other._jurisdictionRoot.get()));
_jurisdictionRoot = allocateOctalCodePtr(bytes);
_jurisdictionRoot = createOctalCodePtr(bytes);
memcpy(_jurisdictionRoot.get(), other._jurisdictionRoot.get(), bytes);
}
for (size_t i = 0; i < other._jurisdictionEndNodes.size(); i++) {
auto& endNodeCode = other._jurisdictionEndNodes[i];
if (endNodeCode) {
auto bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(endNodeCode.get()));
auto endNodeCodeCopy = allocateOctalCodePtr(bytes);
auto endNodeCodeCopy = createOctalCodePtr(bytes);
memcpy(endNodeCodeCopy.get(), endNodeCode.get(), bytes);
_jurisdictionEndNodes.push_back(endNodeCodeCopy);
}
@ -156,7 +156,7 @@ void OctreeSceneStats::sceneStarted(bool isFullScene, bool isMoving, OctreeEleme
// setup jurisdictions
if (jurisdictionMap) {
std::tie(_jurisdictionRoot, _jurisdictionEndNodes) = jurisdictionMap->getRootOctalCodeAndEndNodes();
std::tie(_jurisdictionRoot, _jurisdictionEndNodes) = jurisdictionMap->getRootAndEndNodeOctalCodes();
} else {
_jurisdictionRoot = nullptr;
_jurisdictionEndNodes.clear();
@ -470,7 +470,7 @@ int OctreeSceneStats::unpackFromPacket(ReceivedMessage& packet) {
_jurisdictionRoot = nullptr;
_jurisdictionEndNodes.clear();
} else {
_jurisdictionRoot = allocateOctalCodePtr(bytes);
_jurisdictionRoot = createOctalCodePtr(bytes);
packet.read(reinterpret_cast<char*>(_jurisdictionRoot.get()), bytes);
// if and only if there's a root jurisdiction, also include the end elements
@ -484,7 +484,7 @@ int OctreeSceneStats::unpackFromPacket(ReceivedMessage& packet) {
packet.readPrimitive(&bytes);
auto endNodeCode = allocateOctalCodePtr(bytes);
auto endNodeCode = createOctalCodePtr(bytes);
packet.read(reinterpret_cast<char*>(endNodeCode.get()), bytes);
_jurisdictionEndNodes.push_back(endNodeCode);

View file

@ -304,7 +304,7 @@ bool isAncestorOf(const unsigned char* possibleAncestor, const unsigned char* po
return true;
}
OctalCodePtr allocateOctalCodePtr(size_t size) {
OctalCodePtr createOctalCodePtr(size_t size) {
return OctalCodePtr(new unsigned char[size], std::default_delete<unsigned char[]>());
}
@ -315,7 +315,7 @@ OctalCodePtr hexStringToOctalCode(const QString& input) {
int byteArrayIndex = 0;
// allocate byte array based on half of string length
auto bytes = allocateOctalCodePtr(input.length() / HEX_BYTE_SIZE);
auto bytes = createOctalCodePtr(input.length() / HEX_BYTE_SIZE);
// loop through the string - 2 bytes at a time converting
// it to decimal equivalent and store in byte array

View file

@ -61,7 +61,7 @@ typedef enum {
OctalCodeComparison compareOctalCodes(const unsigned char* code1, const unsigned char* code2);
OctalCodePtr allocateOctalCodePtr(size_t size);
OctalCodePtr createOctalCodePtr(size_t size);
QString octalCodeToHexString(const unsigned char* octalCode);
OctalCodePtr hexStringToOctalCode(const QString& input);