T2345: Replace instances of NULL with nullptr

revert lib/poems to remove nullptr changes.
Walking back changes to lib as needed.
This commit is contained in:
Anne Gunn
2020-09-11 09:54:15 -06:00
parent f524fa758d
commit ed57554e18
8 changed files with 67 additions and 67 deletions

View File

@ -110,21 +110,21 @@ void SystemProcessor::processArray(int** links, int numLinks)
do do
{ {
currentNode = findSingleLink(temp); //find the start of the next available chain currentNode = findSingleLink(temp); //find the start of the next available chain
if(currentNode != nullptr) if(currentNode != NULL)
{ {
headsOfSystems.Append(AddNewChain(currentNode)); //and add it to the headsOfSystems list of chains headsOfSystems.Append(AddNewChain(currentNode)); //and add it to the headsOfSystems list of chains
} }
} }
while(currentNode != nullptr); //repeat this until all chains have been added while(currentNode != NULL); //repeat this until all chains have been added
} }
POEMSChain * SystemProcessor::AddNewChain(POEMSNode * currentNode){ POEMSChain * SystemProcessor::AddNewChain(POEMSNode * currentNode){
if(currentNode == nullptr) //Termination condition; if the currentNode is null, then return null if(currentNode == NULL) //Termination condition; if the currentNode is null, then return null
{ {
return nullptr; return NULL;
} }
int * tmp; int * tmp;
POEMSNode * nextNode = nullptr; //nextNode stores the proposed next node to add to the chain. this will be checked to make sure no backtracking is occurring before being assigned as the current node. POEMSNode * nextNode = NULL; //nextNode stores the proposed next node to add to the chain. this will be checked to make sure no backtracking is occurring before being assigned as the current node.
POEMSChain * newChain = new POEMSChain; //make a new POEMSChain object. This will be the object returned POEMSChain * newChain = new POEMSChain; //make a new POEMSChain object. This will be the object returned
if(currentNode->links.GetNumElements() == 0) //if we have no links from this node, then the whole chain is only one node. Add this node to the chain and return it; mark node as visited for future reference if(currentNode->links.GetNumElements() == 0) //if we have no links from this node, then the whole chain is only one node. Add this node to the chain and return it; mark node as visited for future reference
@ -168,8 +168,8 @@ POEMSChain * SystemProcessor::AddNewChain(POEMSNode * currentNode){
newChain->listOfNodes.Append(tmp); //append the last node before branch (node shared jointly with branch chains) newChain->listOfNodes.Append(tmp); //append the last node before branch (node shared jointly with branch chains)
//re-mark as visited, just to make sure //re-mark as visited, just to make sure
ListElement<POEMSNode> * tempNode = currentNode->links.GetHeadElement(); //go through all of the links, one at a time that branch ListElement<POEMSNode> * tempNode = currentNode->links.GetHeadElement(); //go through all of the links, one at a time that branch
POEMSChain * tempChain = nullptr; //temporary variable to hold data POEMSChain * tempChain = NULL; //temporary variable to hold data
while(tempNode != nullptr) //when we have followed all links, stop while(tempNode != NULL) //when we have followed all links, stop
{ {
if(setLinkVisited(tempNode->value, currentNode)) //dont backtrack, or create closed loops if(setLinkVisited(tempNode->value, currentNode)) //dont backtrack, or create closed loops
{ {
@ -187,12 +187,12 @@ POEMSNode * SystemProcessor::findSingleLink(TreeNode * aNode)
//This function takes the root of a search tree containing POEMSNodes and returns a POEMSNode corresponding to the start of a chain in the //This function takes the root of a search tree containing POEMSNodes and returns a POEMSNode corresponding to the start of a chain in the
//system. It finds a node that has not been visited before, and only has one link; this node will be used as the head of the chain. //system. It finds a node that has not been visited before, and only has one link; this node will be used as the head of the chain.
{ {
if(aNode == nullptr) if(aNode == NULL)
{ {
return nullptr; return NULL;
} }
POEMSNode * returnVal = (POEMSNode *)aNode->GetAuxData(); //get the poemsnode data out of the treenode POEMSNode * returnVal = (POEMSNode *)aNode->GetAuxData(); //get the poemsnode data out of the treenode
POEMSNode * detectLoneLoops = nullptr; //is used to handle a loop that has no protruding chains POEMSNode * detectLoneLoops = NULL; //is used to handle a loop that has no protruding chains
if(returnVal->visited == false) if(returnVal->visited == false)
{ {
detectLoneLoops = returnVal; //if we find any node that has not been visited yet, save it detectLoneLoops = returnVal; //if we find any node that has not been visited yet, save it
@ -202,15 +202,15 @@ POEMSNode * SystemProcessor::findSingleLink(TreeNode * aNode)
return returnVal; //return the node is it meets this criteria return returnVal; //return the node is it meets this criteria
} }
returnVal = findSingleLink(aNode->Left()); //otherwise, check the left subtree returnVal = findSingleLink(aNode->Left()); //otherwise, check the left subtree
if(returnVal == nullptr) //and if we find nothing... if(returnVal == NULL) //and if we find nothing...
{ {
returnVal = findSingleLink(aNode->Right()); //check the right subtree returnVal = findSingleLink(aNode->Right()); //check the right subtree
} }
if(returnVal == nullptr) //if we could not find any chains if(returnVal == NULL) //if we could not find any chains
{ {
returnVal = detectLoneLoops; //see if we found any nodes at all that havent been processed returnVal = detectLoneLoops; //see if we found any nodes at all that havent been processed
} }
return returnVal; //return what we find (will be nullptr if no new chains are return returnVal; //return what we find (will be NULL if no new chains are
//found) //found)
} }
@ -226,7 +226,7 @@ bool SystemProcessor::setLinkVisited(POEMSNode * firstNode, POEMSNode * secondNo
//cout << "Checking link between nodes " << firstNode->idNumber << " and " << secondNode->idNumber << "... "; //cout << "Checking link between nodes " << firstNode->idNumber << " and " << secondNode->idNumber << "... ";
ListElement<POEMSNode> * tmp = firstNode->links.GetHeadElement(); //get the head element of the list of pointers for node 1 ListElement<POEMSNode> * tmp = firstNode->links.GetHeadElement(); //get the head element of the list of pointers for node 1
ListElement<bool> * tmp2 = firstNode->taken.GetHeadElement(); //get the head element of the list of bool isVisited flags for node 1 ListElement<bool> * tmp2 = firstNode->taken.GetHeadElement(); //get the head element of the list of bool isVisited flags for node 1
while(tmp->value != nullptr || tmp2->value != nullptr) //go through until we reach the end of the lists while(tmp->value != NULL || tmp2->value != NULL) //go through until we reach the end of the lists
{ {
if(tmp->value == secondNode) //if we find the link to the other node if(tmp->value == secondNode) //if we find the link to the other node
{ {
@ -248,7 +248,7 @@ bool SystemProcessor::setLinkVisited(POEMSNode * firstNode, POEMSNode * secondNo
tmp = secondNode->links.GetHeadElement(); //now, if the link was unvisited, we need to go set the other node's list such that tmp = secondNode->links.GetHeadElement(); //now, if the link was unvisited, we need to go set the other node's list such that
//it also knows this link is being visited //it also knows this link is being visited
tmp2 = secondNode->taken.GetHeadElement(); tmp2 = secondNode->taken.GetHeadElement();
while(tmp->value != nullptr || tmp2->value != nullptr) //go through the list while(tmp->value != NULL || tmp2->value != NULL) //go through the list
{ {
if(tmp->value == firstNode) //if we find the link if(tmp->value == firstNode) //if we find the link
{ {

View File

@ -23,7 +23,7 @@
using namespace std; using namespace std;
TreeNode *GetTreeNode(int item,TreeNode *lptr = nullptr,TreeNode *rptr =nullptr); TreeNode *GetTreeNode(int item,TreeNode *lptr = NULL,TreeNode *rptr =NULL);
void FreeTreeNode(TreeNode *p); void FreeTreeNode(TreeNode *p);
@ -46,7 +46,7 @@ void PrintTree (TreeNode *t, int level);
void Postorder (TreeNode *t, void visit(TreeNode* &t)) void Postorder (TreeNode *t, void visit(TreeNode* &t))
{ {
// the recursive scan terminates on a empty subtree // the recursive scan terminates on a empty subtree
if (t != nullptr) if (t != NULL)
{ {
Postorder(t->Left(), visit); // descend left Postorder(t->Left(), visit); // descend left
Postorder(t->Right(), visit); // descend right Postorder(t->Right(), visit); // descend right
@ -59,7 +59,7 @@ void Postorder (TreeNode *t, void visit(TreeNode* &t))
void Preorder (TreeNode *t, void visit(TreeNode* &t)) void Preorder (TreeNode *t, void visit(TreeNode* &t))
{ {
// the recursive scan terminates on a empty subtree // the recursive scan terminates on a empty subtree
if (t != nullptr) if (t != NULL)
{ {
visit(t); // visit the node visit(t); // visit the node
Preorder(t->Left(), visit); // descend left Preorder(t->Left(), visit); // descend left
@ -69,7 +69,7 @@ void Preorder (TreeNode *t, void visit(TreeNode* &t))
//create TreeNode object with pointer fields lptr and rptr //create TreeNode object with pointer fields lptr and rptr
// The pointers have default value nullptr // The pointers have default value NULL
TreeNode *GetTreeNode(int item,TreeNode *lptr,TreeNode *rptr) TreeNode *GetTreeNode(int item,TreeNode *lptr,TreeNode *rptr)
{ {
TreeNode *p; TreeNode *p;
@ -79,7 +79,7 @@ TreeNode *GetTreeNode(int item,TreeNode *lptr,TreeNode *rptr)
p = new TreeNode(item, lptr, rptr); p = new TreeNode(item, lptr, rptr);
// if insufficient memory, terminatewith an error message // if insufficient memory, terminatewith an error message
if (p == nullptr) if (p == NULL)
{ {
cerr << "Memory allocation failure!\n"; cerr << "Memory allocation failure!\n";
exit(1); exit(1);
@ -103,14 +103,14 @@ void FreeTreeNode(TreeNode *p)
void CountLeaf (TreeNode *t, int& count) void CountLeaf (TreeNode *t, int& count)
{ {
//use postorder descent //use postorder descent
if(t !=nullptr) if(t !=NULL)
{ {
CountLeaf(t->Left(), count); // descend left CountLeaf(t->Left(), count); // descend left
CountLeaf(t->Right(), count); // descend right CountLeaf(t->Right(), count); // descend right
// check if node t is a leaf node (no descendants) // check if node t is a leaf node (no descendants)
// if so, increment the variable count // if so, increment the variable count
if (t->Left() == nullptr && t->Right() == nullptr) if (t->Left() == NULL && t->Right() == NULL)
count++; count++;
} }
} }
@ -124,7 +124,7 @@ int Depth (TreeNode *t)
{ {
int depthLeft, depthRight, depthval; int depthLeft, depthRight, depthval;
if (t == nullptr) if (t == NULL)
depthval = -1; depthval = -1;
else else
{ {
@ -145,8 +145,8 @@ void IndentBlanks(int num)
void PrintTree (TreeNode *t, int level) void PrintTree (TreeNode *t, int level)
{ {
//print tree with root t, as long as t!=nullptr //print tree with root t, as long as t!=NULL
if (t != nullptr) if (t != NULL)
{ {
int indentUnit = 5; int indentUnit = 5;
// print right branch of tree t // print right branch of tree t

View File

@ -82,7 +82,7 @@ public:
DeleteAuxData = callback; DeleteAuxData = callback;
} }
void Insert(const int& item, const int& data, void * AuxData = nullptr); void Insert(const int& item, const int& data, void * AuxData = NULL);
void Delete(const int& item); void Delete(const int& item);
void AVLInsert(TreeNode* &tree, TreeNode* newNode, int &reviseBalanceFactor); void AVLInsert(TreeNode* &tree, TreeNode* newNode, int &reviseBalanceFactor);
void ClearList(void); void ClearList(void);
@ -99,7 +99,7 @@ Tree::Tree(void)
root = 0; root = 0;
current = 0; current = 0;
size = 0; size = 0;
DeleteAuxData = nullptr; DeleteAuxData = NULL;
} }
@ -131,18 +131,18 @@ Tree& Tree::operator = (const Tree& rhs)
} }
// search for data item in the tree. if found, return its node // search for data item in the tree. if found, return its node
// address and a pointer to its parent; otherwise, return nullptr // address and a pointer to its parent; otherwise, return NULL
TreeNode *Tree::FindNode(const int& item, TreeNode *Tree::FindNode(const int& item,
TreeNode* & parent) const TreeNode* & parent) const
{ {
// cycle t through the tree starting with root // cycle t through the tree starting with root
TreeNode *t = root; TreeNode *t = root;
// the parent of the root is nullptr // the parent of the root is NULL
parent = nullptr; parent = NULL;
// terminate on empty subtree // terminate on empty subtree
while(t != nullptr) while(t != NULL)
{ {
// stop on a match // stop on a match
if (item == t->data) if (item == t->data)
@ -158,7 +158,7 @@ TreeNode *Tree::FindNode(const int& item,
} }
} }
// return pointer to node; nullptr if not found // return pointer to node; NULL if not found
return t; return t;
} }
@ -172,14 +172,14 @@ void * Tree::Find(int& item)
current = FindNode (item, parent); current = FindNode (item, parent);
// if item found, assign data to item and return True // if item found, assign data to item and return True
if (current != nullptr) if (current != NULL)
{ {
item = current->data; item = current->data;
return current->GetAuxData(); return current->GetAuxData();
} }
else else
// item not found in the tree. return False // item not found in the tree. return False
return nullptr; return NULL;
} }
@ -194,7 +194,7 @@ void Tree::Insert(const int& item, const int& data, void * AuxData)
int reviseBalanceFactor = 0; int reviseBalanceFactor = 0;
// get a new AVL tree node with empty pointer fields // get a new AVL tree node with empty pointer fields
newNode = GetTreeNode(item,nullptr,nullptr); newNode = GetTreeNode(item,NULL,NULL);
newNode->data = data; newNode->data = data;
newNode->SetAuxData(AuxData); newNode->SetAuxData(AuxData);
// call recursive routine to actually insert the element // call recursive routine to actually insert the element
@ -213,7 +213,7 @@ void Tree::AVLInsert(TreeNode *&tree, TreeNode *newNode, int &reviseBalanceFacto
int rebalanceCurrNode; int rebalanceCurrNode;
// scan reaches an empty tree; time to insert the new node // scan reaches an empty tree; time to insert the new node
if (tree == nullptr) if (tree == NULL)
{ {
// update the parent to point at newNode // update the parent to point at newNode
tree = newNode; tree = newNode;
@ -456,16 +456,16 @@ void Tree::Delete(const int& item)
// search for a node containing data value item. obtain its // search for a node containing data value item. obtain its
// node address and that of its parent // node address and that of its parent
if ((DNodePtr = FindNode (item, PNodePtr)) == nullptr) if ((DNodePtr = FindNode (item, PNodePtr)) == NULL)
return; return;
// If D has nullptr pointer, the // If D has NULL pointer, the
// replacement node is the one on the other branch // replacement node is the one on the other branch
if (DNodePtr->right == nullptr) if (DNodePtr->right == NULL)
RNodePtr = DNodePtr->left; RNodePtr = DNodePtr->left;
else if (DNodePtr->left == nullptr) else if (DNodePtr->left == NULL)
RNodePtr = DNodePtr->right; RNodePtr = DNodePtr->right;
// Both pointers of DNodePtr are non-nullptr // Both pointers of DNodePtr are non-NULL
else else
{ {
// Find and unlink replacement node for D // Find and unlink replacement node for D
@ -483,7 +483,7 @@ void Tree::Delete(const int& item)
// descend down right subtree of the left child of D // descend down right subtree of the left child of D
// keeping a record of current node and its parent. // keeping a record of current node and its parent.
// when we stop, we have found the replacement // when we stop, we have found the replacement
while (RNodePtr->right != nullptr) while (RNodePtr->right != NULL)
{ {
PofRNodePtr = RNodePtr; PofRNodePtr = RNodePtr;
RNodePtr = RNodePtr; RNodePtr = RNodePtr;
@ -508,7 +508,7 @@ void Tree::Delete(const int& item)
// complete the link to the parent node // complete the link to the parent node
// deleting the root node. assign new root // deleting the root node. assign new root
if (PNodePtr == nullptr) if (PNodePtr == NULL)
root = RNodePtr; root = RNodePtr;
// attach R to the correct branch of P // attach R to the correct branch of P
else if (DNodePtr->data < PNodePtr->data) else if (DNodePtr->data < PNodePtr->data)
@ -529,7 +529,7 @@ void Tree::Delete(const int& item)
// assign node value to item; otherwise, insert item in tree // assign node value to item; otherwise, insert item in tree
void Tree::Update(const int& item) void Tree::Update(const int& item)
{ {
if (current !=nullptr && current->data == item) if (current !=NULL && current->data == item)
current->data = item; current->data = item;
else else
Insert(item, item); Insert(item, item);
@ -545,25 +545,25 @@ TreeNode *Tree::CopyTree(TreeNode *t)
TreeNode *newlptr, *newrptr, *newnode; TreeNode *newlptr, *newrptr, *newnode;
// stop the recursive scan when we arrive at an empty tree // stop the recursive scan when we arrive at an empty tree
if (t == nullptr) if (t == NULL)
return nullptr; return NULL;
// CopyTree builds a new tree by scanning the nodes of t. // CopyTree builds a new tree by scanning the nodes of t.
// At each node in t, CopyTree checks for a left child. if // At each node in t, CopyTree checks for a left child. if
// present it makes a copy of left child or returns nullptr. // present it makes a copy of left child or returns NULL.
// the algorithm similarly checks for a right child. // the algorithm similarly checks for a right child.
// CopyTree builds a copy of node using GetTreeNode and // CopyTree builds a copy of node using GetTreeNode and
// appends copy of left and right children to node. // appends copy of left and right children to node.
if (t->Left() !=nullptr) if (t->Left() !=NULL)
newlptr = CopyTree(t->Left()); newlptr = CopyTree(t->Left());
else else
newlptr = nullptr; newlptr = NULL;
if (t->Right() !=nullptr) if (t->Right() !=NULL)
newrptr = CopyTree(t->Right()); newrptr = CopyTree(t->Right());
else else
newrptr = nullptr; newrptr = NULL;
// Build new tree from the bottom up by building the two // Build new tree from the bottom up by building the two
@ -579,12 +579,12 @@ TreeNode *Tree::CopyTree(TreeNode *t)
// the tree and delete each node at the visit operation // the tree and delete each node at the visit operation
void Tree::DeleteTree(TreeNode *t) void Tree::DeleteTree(TreeNode *t)
{ {
if (t != nullptr) { if (t != NULL) {
DeleteTree(t->Left()); DeleteTree(t->Left());
DeleteTree(t->Right()); DeleteTree(t->Right());
void *aux = t->GetAuxData(); void *aux = t->GetAuxData();
if (aux != nullptr) { if (aux != NULL) {
if (DeleteAuxData != nullptr) { if (DeleteAuxData != NULL) {
(*DeleteAuxData)(aux); (*DeleteAuxData)(aux);
} else { } else {
delete (TreeNode *) aux; delete (TreeNode *) aux;
@ -595,11 +595,11 @@ void Tree::DeleteTree(TreeNode *t)
} }
// call the function DeleteTree to deallocate the nodes. then // call the function DeleteTree to deallocate the nodes. then
// set the root pointer back to nullptr // set the root pointer back to NULL
void Tree::ClearTree(TreeNode * &t) void Tree::ClearTree(TreeNode * &t)
{ {
DeleteTree(t); DeleteTree(t);
t = nullptr; // root now nullptr t = NULL; // root now NULL
} }
// delete all nodes in list // delete all nodes in list

View File

@ -18,7 +18,7 @@
#include "poemstreenode.h" #include "poemstreenode.h"
// constructor; initialize the data and pointer fields // constructor; initialize the data and pointer fields
// The pointer value nullptr assigns a empty subtree // The pointer value NULL assigns a empty subtree
TreeNode::TreeNode (const int & item, TreeNode *lptr,TreeNode *rptr, TreeNode::TreeNode (const int & item, TreeNode *lptr,TreeNode *rptr,
int balfac):data(item), left(lptr), right(rptr), balanceFactor(balfac) int balfac):data(item), left(lptr), right(rptr), balanceFactor(balfac)
{ {

View File

@ -18,7 +18,7 @@
#ifndef TREENODE_H #ifndef TREENODE_H
#define TREENODE_H #define TREENODE_H
//#define nullptr 0 //#define NULL 0
//Tree depends on TreeNode //Tree depends on TreeNode

View File

@ -45,7 +45,7 @@ Solver * Solver::GetSolver(SolverType solverToMake) //returning a pointer to a n
switch((int)solverToMake) switch((int)solverToMake)
{ {
case ONSOLVER: return new OnSolver(); case ONSOLVER: return new OnSolver();
default: return nullptr; default: return NULL;
} }
} }

View File

@ -23,7 +23,7 @@
System::System(){ System::System(){
mappings = nullptr; mappings = NULL;
} }
System::~System(){ System::~System(){
@ -238,7 +238,7 @@ void System::Create_DegenerateSystem(int& nfree, int*freelist, double *&masstota
//-------------------------------------------------------------------------// //-------------------------------------------------------------------------//
// Declaring Temporary Entities // Declaring Temporary Entities
//-------------------------------------------------------------------------// //-------------------------------------------------------------------------//
Body* body = nullptr; Body* body = NULL;
Body* prev; Body* prev;
Body* Inertial; Body* Inertial;
Point* origin; Point* origin;
@ -246,7 +246,7 @@ void System::Create_DegenerateSystem(int& nfree, int*freelist, double *&masstota
Point* point_CM; Point* point_CM;
Point* point_p; Point* point_p;
Point* point_k; Point* point_k;
Point* point_ch = nullptr; Point* point_ch = NULL;
Vect3 r1,r2,r3,v1,v2,v3; Vect3 r1,r2,r3,v1,v2,v3;
Mat3x3 IM, N, PKCK,PKCN ; Mat3x3 IM, N, PKCK,PKCN ;
ColMatrix qo, uo, q, qdot,w; ColMatrix qo, uo, q, qdot,w;
@ -391,7 +391,7 @@ void System::Create_System_LAMMPS(int numbodies, double *mass,double **inertia,
// Declaring Temporary Entities // Declaring Temporary Entities
//-------------------------------------------------------------------------// //-------------------------------------------------------------------------//
Body* body = nullptr; Body* body = NULL;
Body* prev; Body* prev;
Body* Inertial; Body* Inertial;
Point* origin; Point* origin;
@ -399,7 +399,7 @@ void System::Create_System_LAMMPS(int numbodies, double *mass,double **inertia,
Point* point_CM; Point* point_CM;
Point* point_p; Point* point_p;
Point* point_k; Point* point_k;
Point* point_ch = nullptr; Point* point_ch = NULL;
Vect3 r1,r2,r3,v1,v2,v3; Vect3 r1,r2,r3,v1,v2,v3;
Mat3x3 IM, N, PKCK,PKCN ; Mat3x3 IM, N, PKCK,PKCN ;
ColMatrix qo, uo, q, qdot,w; ColMatrix qo, uo, q, qdot,w;

View File

@ -52,7 +52,7 @@ void Workspace::allocateNewSystem() {
Workspace::Workspace(){ Workspace::Workspace(){
currentIndex = -1; currentIndex = -1;
maxAlloc = 0; maxAlloc = 0;
system = nullptr; system = NULL;
} }
Workspace::~Workspace(){ Workspace::~Workspace(){
@ -133,7 +133,7 @@ if(njoint){
int ttk = 0; int ttk = 0;
while(NodeValue != nullptr) { while(NodeValue != NULL) {
array = new int[NodeValue->value->listOfNodes.GetNumElements()]; array = new int[NodeValue->value->listOfNodes.GetNumElements()];
arrayFromChain = NodeValue->value->listOfNodes.CreateArray(); arrayFromChain = NodeValue->value->listOfNodes.CreateArray();
numElementsInSystem = NodeValue->value->listOfNodes.GetNumElements(); numElementsInSystem = NodeValue->value->listOfNodes.GetNumElements();
@ -200,7 +200,7 @@ System* Workspace::GetSystem(int index){
} }
} }
else{ else{
return nullptr; return NULL;
} }
} }