Skip to content

Commit

Permalink
remove const when used with shared_ptr since it did not prevent from …
Browse files Browse the repository at this point in the history
…the object being pointed to from being changed (only pointer encapsulated by shared_ptr itself)
  • Loading branch information
carltimmer committed Aug 29, 2024
1 parent 2e6d8d4 commit 72034fd
Show file tree
Hide file tree
Showing 25 changed files with 107 additions and 108 deletions.
22 changes: 11 additions & 11 deletions src/libsrc++/BaseStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ namespace evio {
*
* @param structure BaseStructure from which to copy data.
*/
void BaseStructure::transform(std::shared_ptr<BaseStructure> const structure) {
void BaseStructure::transform(std::shared_ptr<BaseStructure> structure) {
DataType dataType = structure->getHeader()->getDataType();

copyData(structure);
Expand Down Expand Up @@ -269,7 +269,7 @@ namespace evio {
* Copy just the data of another structure.
* @param other structure to copy data from.
*/
void BaseStructure::copyData(std::shared_ptr<BaseStructure> const other) {
void BaseStructure::copyData(std::shared_ptr<BaseStructure> other) {
// Copy over raw data
rawBytes = other->rawBytes;

Expand Down Expand Up @@ -385,7 +385,7 @@ namespace evio {
* or this node does not allow children.
* @see #isNodeDescendant
*/
void BaseStructure::insert(const std::shared_ptr<BaseStructure> newChild, size_t childIndex) {
void BaseStructure::insert(std::shared_ptr<BaseStructure> newChild, size_t childIndex) {
if (!allowsChildren) {
throw EvioException("node does not allow children");
}
Expand Down Expand Up @@ -488,7 +488,7 @@ namespace evio {
* array, or <code>-1</code> if the specified node is a not
* a child of this node.
*/
ssize_t BaseStructure::getIndex(const std::shared_ptr<BaseStructure> aChild) {
ssize_t BaseStructure::getIndex(std::shared_ptr<BaseStructure> aChild) {
if (aChild == nullptr) {
throw EvioException("argument is null");
}
Expand Down Expand Up @@ -587,7 +587,7 @@ namespace evio {
* @param aChild a child of this node to remove
* @throws EvioException if <code>aChild</code> is not a child of this node
*/
void BaseStructure::remove(const std::shared_ptr<BaseStructure> aChild) {
void BaseStructure::remove(std::shared_ptr<BaseStructure> aChild) {
if (!isNodeChild(aChild)) {
throw EvioException("argument is not a child");
}
Expand Down Expand Up @@ -643,7 +643,7 @@ namespace evio {
* @param anotherNode node to test as an ancestor of this node
* @return true if this node is a descendant of <code>anotherNode</code>
*/
bool BaseStructure::isNodeAncestor(const std::shared_ptr<BaseStructure> anotherNode) const {
bool BaseStructure::isNodeAncestor(std::shared_ptr<BaseStructure> anotherNode) const {
if (anotherNode == nullptr) {
return false;
}
Expand Down Expand Up @@ -837,7 +837,7 @@ namespace evio {
* specified node.
*/
std::vector<std::shared_ptr<BaseStructure>> BaseStructure::getPathToRoot (
const std::shared_ptr<BaseStructure> aNode, int depth) const {
std::shared_ptr<BaseStructure> aNode, int depth) const {

// Check for null, in case someone passed in a null node, or
// they passed in an element that isn't rooted at root.
Expand Down Expand Up @@ -977,7 +977,7 @@ namespace evio {
* @return true if <code>aNode</code> is a child of this node; false if
* <code>aNode</code> is null.
*/
bool BaseStructure::isNodeChild(const std::shared_ptr<BaseStructure> aNode) const {
bool BaseStructure::isNodeChild(std::shared_ptr<BaseStructure> aNode) const {
bool retval;

if (aNode == nullptr) {
Expand Down Expand Up @@ -1044,7 +1044,7 @@ namespace evio {
* @return the child of this node that immediately follows
* <code>aChild</code>.
*/
std::shared_ptr<BaseStructure> BaseStructure::getChildAfter(const std::shared_ptr<BaseStructure> aChild) {
std::shared_ptr<BaseStructure> BaseStructure::getChildAfter(std::shared_ptr<BaseStructure> aChild) {
if (aChild == nullptr) {
throw EvioException("argument is null");
}
Expand Down Expand Up @@ -1077,7 +1077,7 @@ namespace evio {
* is not a child of this node.
* @return the child of this node that immediately precedes <code>aChild</code>.
*/
std::shared_ptr<BaseStructure> BaseStructure::getChildBefore(const std::shared_ptr<BaseStructure> aChild) {
std::shared_ptr<BaseStructure> BaseStructure::getChildBefore(std::shared_ptr<BaseStructure> aChild) {
if (aChild == nullptr) {
throw EvioException("argument is null");
}
Expand Down Expand Up @@ -1112,7 +1112,7 @@ namespace evio {
* @throws EvioException if sibling has different parent.
* @return true if <code>anotherNode</code> is a sibling of this node.
*/
bool BaseStructure::isNodeSibling(const std::shared_ptr<BaseStructure> anotherNode) const {
bool BaseStructure::isNodeSibling(std::shared_ptr<BaseStructure> anotherNode) const {
bool retval;

if (anotherNode == nullptr) {
Expand Down
24 changes: 12 additions & 12 deletions src/libsrc++/BaseStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,19 +419,19 @@ namespace evio {

protected:

void setParent(const std::shared_ptr<BaseStructure> newParent);
void setParent(std::shared_ptr<BaseStructure> newParent);

public:

void insert(const std::shared_ptr<BaseStructure> newChild, size_t childIndex);
void insert(std::shared_ptr<BaseStructure> newChild, size_t childIndex);
void remove(size_t childIndex);

std::shared_ptr<BaseStructure> getParent() const;
std::vector<std::shared_ptr<BaseStructure>> & getChildren();
std::shared_ptr<BaseStructure> getChildAt(size_t index) const;

size_t getChildCount() const;
ssize_t getIndex(const std::shared_ptr<BaseStructure> aChild);
ssize_t getIndex(std::shared_ptr<BaseStructure> aChild);
std::vector<std::shared_ptr<BaseStructure>>::iterator childrenBegin();
std::vector<std::shared_ptr<BaseStructure>>::iterator childrenEnd();

Expand All @@ -443,15 +443,15 @@ namespace evio {
//

void removeFromParent();
void remove(const std::shared_ptr<BaseStructure> aChild);
void remove(std::shared_ptr<BaseStructure> aChild);
void removeAllChildren();
void add(std::shared_ptr<BaseStructure> newChild);

//
// Tree Queries
//

bool isNodeAncestor(const std::shared_ptr<BaseStructure> anotherNode) const;
bool isNodeAncestor(std::shared_ptr<BaseStructure> anotherNode) const;
bool isNodeDescendant(std::shared_ptr<BaseStructure> anotherNode);
std::shared_ptr<BaseStructure> getSharedAncestor(std::shared_ptr<BaseStructure> aNode);
bool isNodeRelated(std::shared_ptr<BaseStructure> aNode);
Expand All @@ -461,7 +461,7 @@ namespace evio {

protected:

std::vector<std::shared_ptr<BaseStructure>> getPathToRoot(const std::shared_ptr<BaseStructure> aNode, int depth) const;
std::vector<std::shared_ptr<BaseStructure>> getPathToRoot(std::shared_ptr<BaseStructure> aNode, int depth) const;

public:

Expand All @@ -474,17 +474,17 @@ namespace evio {
// Child Queries
//

bool isNodeChild(const std::shared_ptr<BaseStructure> aNode) const;
bool isNodeChild(std::shared_ptr<BaseStructure> aNode) const;
std::shared_ptr<BaseStructure> getFirstChild() const;
std::shared_ptr<BaseStructure> getLastChild() const;
std::shared_ptr<BaseStructure> getChildAfter(const std::shared_ptr<BaseStructure> aChild);
std::shared_ptr<BaseStructure> getChildBefore(const std::shared_ptr<BaseStructure> aChild);
std::shared_ptr<BaseStructure> getChildAfter(std::shared_ptr<BaseStructure> aChild);
std::shared_ptr<BaseStructure> getChildBefore(std::shared_ptr<BaseStructure> aChild);

//
// Sibling Queries
//

bool isNodeSibling(const std::shared_ptr<BaseStructure> anotherNode) const;
bool isNodeSibling(std::shared_ptr<BaseStructure> anotherNode) const;
size_t getSiblingCount() const;
std::shared_ptr<BaseStructure> getNextSibling();
std::shared_ptr<BaseStructure> getPreviousSibling();
Expand Down Expand Up @@ -622,7 +622,7 @@ namespace evio {

void clearData();
void copyData(BaseStructure const & other);
void copyData(std::shared_ptr<BaseStructure> const other);
void copyData(std::shared_ptr<BaseStructure> other);

protected:

Expand All @@ -637,7 +637,7 @@ namespace evio {

public:

void transform(std::shared_ptr<BaseStructure> const structure);
void transform(std::shared_ptr<BaseStructure> structure);

virtual StructureType getStructureType() const {return StructureType::STRUCT_UNKNOWN32;};

Expand Down
2 changes: 1 addition & 1 deletion src/libsrc++/BaseStructureHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace evio {
* Method to copy data from the fiven header to this one.
* @param head header to copy data from (source).
*/
void BaseStructureHeader::copy(std::shared_ptr<BaseStructureHeader> const head) {
void BaseStructureHeader::copy(std::shared_ptr<BaseStructureHeader> head) {
tag = head->tag;
dataType = head->dataType;
number = head->number;
Expand Down
2 changes: 1 addition & 1 deletion src/libsrc++/BaseStructureHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace evio {
protected:

void setPadding(uint8_t pad);
void copy(std::shared_ptr<BaseStructureHeader> const head);
void copy(std::shared_ptr<BaseStructureHeader> head);

public:

Expand Down
8 changes: 4 additions & 4 deletions src/libsrc++/ByteBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ namespace evio {
* Copy data and everything else from arg.
* @param srcBuf ByteBuffer to copy.
*/
void ByteBuffer::copy(const std::shared_ptr<const ByteBuffer> srcBuf) {
void ByteBuffer::copy(std::shared_ptr<const ByteBuffer> srcBuf) {
return copy(*(srcBuf.get()));
}

Expand All @@ -254,7 +254,7 @@ namespace evio {
* @param srcBuf ByteBuffer to copy.
* @return new ByteBuffer.
*/
std::shared_ptr<ByteBuffer> ByteBuffer::copyBuffer(const std::shared_ptr<const ByteBuffer> srcBuf) {
std::shared_ptr<ByteBuffer> ByteBuffer::copyBuffer(std::shared_ptr<const ByteBuffer> srcBuf) {

auto newBuf = std::make_shared<ByteBuffer>(srcBuf->totalSize);
newBuf->pos = srcBuf->pos;
Expand All @@ -280,7 +280,7 @@ namespace evio {
* @param position position in srcByf to start from.
* @param limit position in srcByf to end at.
*/
void ByteBuffer::copyData(const std::shared_ptr<const ByteBuffer> srcBuf, size_t position, size_t limit) {
void ByteBuffer::copyData(std::shared_ptr<const ByteBuffer> srcBuf, size_t position, size_t limit) {
// How many bytes do we copy?
size_t newSize = limit - position;

Expand Down Expand Up @@ -1361,7 +1361,7 @@ namespace evio {
* @throws overflow_error if insufficient space in this buffer
* for the remaining bytes in the source buffer.
*/
ByteBuffer & ByteBuffer::put(const std::shared_ptr<ByteBuffer> src) {
ByteBuffer & ByteBuffer::put(std::shared_ptr<ByteBuffer> src) {
return (put(*(src.get())));
}

Expand Down
8 changes: 4 additions & 4 deletions src/libsrc++/ByteBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ namespace evio {
ByteBuffer & compact();
ByteBuffer & zero();

static std::shared_ptr<ByteBuffer> copyBuffer(const std::shared_ptr<const ByteBuffer> srcBuf);
void copyData(const std::shared_ptr<const ByteBuffer> srcBuf, size_t pos, size_t limit);
static std::shared_ptr<ByteBuffer> copyBuffer(std::shared_ptr<const ByteBuffer> srcBuf);
void copyData(std::shared_ptr<const ByteBuffer> srcBuf, size_t pos, size_t limit);
void copy(const ByteBuffer & srcBuf);
void copy(const std::shared_ptr<const ByteBuffer> srcBuf);
void copy(std::shared_ptr<const ByteBuffer> srcBuf);
bool equals(const ByteBuffer & other);
void expand(size_t newSize);

Expand Down Expand Up @@ -181,7 +181,7 @@ namespace evio {

// Bulk byte writes
ByteBuffer & put(const ByteBuffer & src);
ByteBuffer & put(const std::shared_ptr<ByteBuffer> rc);
ByteBuffer & put(std::shared_ptr<ByteBuffer> rc);
ByteBuffer & put(const uint8_t * src, size_t length);
ByteBuffer & put(const std::vector<uint8_t> & src, size_t offset, size_t length);

Expand Down
24 changes: 12 additions & 12 deletions src/libsrc++/EventParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ namespace evio {
* @param structure the structure to start scanning.
* @param listener an listener to notify as each structure is visited.
*/
void EventParser::vistAllStructures(std::shared_ptr<BaseStructure> const structure,
std::shared_ptr<IEvioListener> const listener) {
void EventParser::vistAllStructures(std::shared_ptr<BaseStructure> structure,
std::shared_ptr<IEvioListener> listener) {
visitAllDescendants(structure, structure, listener, nullptr);
}

Expand All @@ -478,9 +478,9 @@ namespace evio {
* structures are passed. In this way, specific types of
* structures can be captured.
*/
void EventParser::vistAllStructures(std::shared_ptr<BaseStructure> const structure,
std::shared_ptr<IEvioListener> const listener,
std::shared_ptr<IEvioFilter> const filter) {
void EventParser::vistAllStructures(std::shared_ptr<BaseStructure> structure,
std::shared_ptr<IEvioListener> listener,
std::shared_ptr<IEvioFilter> filter) {
visitAllDescendants(structure, structure, listener, filter);
}

Expand All @@ -497,10 +497,10 @@ namespace evio {
* structures are passed. In this way, specific types of
* structures can be captured.
*/
void EventParser::visitAllDescendants(std::shared_ptr<BaseStructure> const topLevelStruct,
std::shared_ptr<BaseStructure> const structure,
std::shared_ptr<IEvioListener> const listener,
std::shared_ptr<IEvioFilter> const filter) {
void EventParser::visitAllDescendants(std::shared_ptr<BaseStructure> topLevelStruct,
std::shared_ptr<BaseStructure> structure,
std::shared_ptr<IEvioListener> listener,
std::shared_ptr<IEvioFilter> filter) {
if (listener != nullptr) {
bool accept = true;
if (filter != nullptr) {
Expand All @@ -513,7 +513,7 @@ namespace evio {
}

if (!(structure->isLeaf())) {
for (auto const child : structure->children) {
for (auto child : structure->children) {
visitAllDescendants(topLevelStruct, child, listener, filter);
}
}
Expand All @@ -528,8 +528,8 @@ namespace evio {
* this will return all the structures.
* @param structs vector to be filled with all structures that are accepted by filter.
*/
void EventParser::getMatchingStructures(std::shared_ptr<BaseStructure> const structure,
std::shared_ptr<IEvioFilter> const filter,
void EventParser::getMatchingStructures(std::shared_ptr<BaseStructure> structure,
std::shared_ptr<IEvioFilter> filter,
std::vector<std::shared_ptr<BaseStructure>> & structs) {
structs.clear();
structs.reserve(25);
Expand Down
22 changes: 11 additions & 11 deletions src/libsrc++/EventParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,20 @@ namespace evio {

// Scanning structures that have already been parsed

static void vistAllStructures(std::shared_ptr<BaseStructure> const structure,
std::shared_ptr<IEvioListener> const listener);
static void vistAllStructures(std::shared_ptr<BaseStructure> const structure,
std::shared_ptr<IEvioListener> const listener,
std::shared_ptr<IEvioFilter> const filter);
static void getMatchingStructures(std::shared_ptr<BaseStructure> const structure,
std::shared_ptr<IEvioFilter> const filter,
static void vistAllStructures(std::shared_ptr<BaseStructure> structure,
std::shared_ptr<IEvioListener> listener);
static void vistAllStructures(std::shared_ptr<BaseStructure> structure,
std::shared_ptr<IEvioListener> listener,
std::shared_ptr<IEvioFilter> filter);
static void getMatchingStructures(std::shared_ptr<BaseStructure> structure,
std::shared_ptr<IEvioFilter> filter,
std::vector<std::shared_ptr<BaseStructure>> & structs);
private:

static void visitAllDescendants(std::shared_ptr<BaseStructure> const topLevelStruct,
std::shared_ptr<BaseStructure> const structure,
std::shared_ptr<IEvioListener> const listener,
std::shared_ptr<IEvioFilter> const filter);
static void visitAllDescendants(std::shared_ptr<BaseStructure> topLevelStruct,
std::shared_ptr<BaseStructure> structure,
std::shared_ptr<IEvioListener> listener,
std::shared_ptr<IEvioFilter> filter);


};
Expand Down
6 changes: 3 additions & 3 deletions src/libsrc++/EventWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1143,9 +1143,9 @@ namespace evio {
* @throws EvioException if dictionary is in improper format
*/
void EventWriter::createCommonRecord(const std::string & xmlDict,
std::shared_ptr<EvioBank> const firstBank,
std::shared_ptr<EvioNode> const firstNode,
std::shared_ptr<ByteBuffer> const firstBuf) {
std::shared_ptr<EvioBank> firstBank,
std::shared_ptr<EvioNode> firstNode,
std::shared_ptr<ByteBuffer> firstBuf) {

// Create record if necessary, else clear it
if (commonRecord == nullptr) {
Expand Down
6 changes: 3 additions & 3 deletions src/libsrc++/EventWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,9 @@ namespace evio {
private:

void createCommonRecord(const std::string & xmlDict,
std::shared_ptr<EvioBank> const firstBank,
std::shared_ptr<EvioNode> const firstNode,
std::shared_ptr<ByteBuffer> const firstBuf);
std::shared_ptr<EvioBank> firstBank,
std::shared_ptr<EvioNode> firstNode,
std::shared_ptr<ByteBuffer> firstBuf);

void writeFileHeader() ;

Expand Down
Loading

0 comments on commit 72034fd

Please sign in to comment.