Import backup from 2004-06-09
This commit is contained in:
1 parent
fdf6b71a91
commit
b54b8191c4
11 files changed
+469
-117
No files matched your search
@@ -3,7 +3,7 @@
|
||||
// implements a LinkedList container for HOS
|
||||
// Author: Josh Holtrop
|
||||
// Date: 05/22/04
|
||||
// Modified: 06/03/04
|
||||
// Modified: 06/09/04
|
||||
|
||||
#ifndef __HOS_LINKEDLIST__
|
||||
#define __HOS_LINKEDLIST__ __HOS_LINKEDLIST__
|
||||
@@ -61,6 +61,10 @@ public:
|
||||
theNode = theNode->next;
|
||||
return theNode->prev->data;
|
||||
}
|
||||
bool operator==(const iterator & second) const
|
||||
{ return theNode == second.theNode; }
|
||||
bool operator!=(const iterator & second) const
|
||||
{ return theNode != second.theNode; }
|
||||
};
|
||||
|
||||
class reverse_iterator
|
||||
@@ -90,6 +94,10 @@ public:
|
||||
theNode = theNode->prev;
|
||||
return theNode->next->data;
|
||||
}
|
||||
bool operator==(const reverse_iterator & second) const
|
||||
{ return theNode == second.theNode; }
|
||||
bool operator!=(const reverse_iterator & second) const
|
||||
{ return theNode != second.theNode; }
|
||||
};
|
||||
|
||||
/* Basic constructor */
|
||||
@@ -99,10 +107,10 @@ public:
|
||||
int size() { return count; }
|
||||
|
||||
/* Return some iterators for traversing the list */
|
||||
iterator begin() { return iterator(firstNode); }
|
||||
iterator begin() { return iterator(firstNode->next); }
|
||||
iterator end() { return iterator(lastNode->next); }
|
||||
reverse_iterator rbegin() { return reverse_iterator(lastNode); }
|
||||
reverse_iterator rend() { return reverse_iterator(firstNode->prev); }
|
||||
reverse_iterator rend() { return reverse_iterator(firstNode); }
|
||||
|
||||
/* Insert an element, its position will be index */
|
||||
LinkedList & insert(int index, Element e);
|
||||
|
||||
+91
-24
@@ -62,30 +62,6 @@ char * string::data() const { return myChars; }
|
||||
|
||||
int string::size() const { return myLength; }
|
||||
|
||||
bool string::operator==(const string & second) const
|
||||
{
|
||||
if (myLength != second.myLength)
|
||||
return false;
|
||||
for (unsigned int i = 0; i < myLength; i++)
|
||||
{
|
||||
if (myChars[i] != second.myChars[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool string::operator==(const char *cstring) const
|
||||
{
|
||||
if (myLength != strlen(cstring))
|
||||
return false;
|
||||
for (unsigned int i = 0; i < myLength; i++)
|
||||
{
|
||||
if (myChars[i] != cstring[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
string & string::operator+=(const string & str)
|
||||
{
|
||||
char *newStr = new char[myLength + str.myLength + 1];
|
||||
@@ -210,3 +186,94 @@ char & string::operator[](unsigned int index)
|
||||
return *myChars; //if index is invalid, return a pointer to the trailing 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool string::operator==(const string & second) const
|
||||
{
|
||||
if (myLength != second.myLength)
|
||||
return false;
|
||||
for (unsigned int i = 0; i < myLength; i++)
|
||||
{
|
||||
if (myChars[i] != second.myChars[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool string::operator==(const char *cstring) const
|
||||
{
|
||||
if (myLength != strlen(cstring))
|
||||
return false;
|
||||
for (unsigned int i = 0; i < myLength; i++)
|
||||
{
|
||||
if (myChars[i] != cstring[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool string::operator!=(const string & second) const
|
||||
{ return !operator==(second); }
|
||||
|
||||
bool string::operator!=(const char *cstring) const
|
||||
{ return !operator==(cstring); }
|
||||
|
||||
bool string::operator<(const string & second) const
|
||||
{
|
||||
char *c1 = myChars, *c2 = second.myChars;
|
||||
while (*c1 == *c2 && *c1)
|
||||
{
|
||||
c1++;
|
||||
c2++;
|
||||
}
|
||||
return *c1 < *c2;
|
||||
}
|
||||
|
||||
bool string::operator>(const string & second) const
|
||||
{
|
||||
char *c1 = myChars, *c2 = second.myChars;
|
||||
while (*c1 == *c2 && *c1)
|
||||
{
|
||||
c1++;
|
||||
c2++;
|
||||
}
|
||||
return *c1 > *c2;
|
||||
}
|
||||
|
||||
bool string::operator<(const char *cstring) const
|
||||
{
|
||||
char *c1 = myChars;
|
||||
while (*c1 == *cstring && *c1)
|
||||
{
|
||||
c1++;
|
||||
cstring++;
|
||||
}
|
||||
return *c1 < *cstring;
|
||||
}
|
||||
|
||||
bool string::operator>(const char *cstring) const
|
||||
{
|
||||
char *c1 = myChars;
|
||||
while (*c1 == *cstring && *c1)
|
||||
{
|
||||
c1++;
|
||||
cstring++;
|
||||
}
|
||||
return *c1 > *cstring;
|
||||
}
|
||||
|
||||
bool string::operator<=(const string & second) const
|
||||
{ return !operator>(second); }
|
||||
|
||||
bool string::operator>=(const string & second) const
|
||||
{ return !operator<(second); }
|
||||
|
||||
bool string::operator<=(const char *cstring) const
|
||||
{ return operator<(cstring) || operator==(cstring); }
|
||||
|
||||
bool string::operator>=(const char *cstring) const
|
||||
{ return operator>(cstring) || operator==(cstring); }
|
||||
|
||||
|
||||
|
||||
|
||||
+27
-2
@@ -3,7 +3,7 @@
|
||||
// implements c++ string object for HOS
|
||||
// Author: Josh Holtrop
|
||||
// Date: 06/01/04
|
||||
// Modified: 06/07/04
|
||||
// Modified: 06/09/04
|
||||
|
||||
|
||||
#ifndef __HOS_STRING__
|
||||
@@ -38,9 +38,19 @@ public:
|
||||
string & operator=(const string & orig);
|
||||
string & operator=(const char *cstring);
|
||||
|
||||
/* Boolean equals operators */
|
||||
/* Boolean comparison operators */
|
||||
bool operator==(const string & second) const;
|
||||
bool operator==(const char *cstring) const;
|
||||
bool operator!=(const string & second) const;
|
||||
bool operator!=(const char *cstring) const;
|
||||
bool operator<(const string & second) const;
|
||||
bool operator>(const string & second) const;
|
||||
bool operator<(const char *cstring) const;
|
||||
bool operator>(const char *cstring) const;
|
||||
bool operator<=(const string & second) const;
|
||||
bool operator>=(const string & second) const;
|
||||
bool operator<=(const char *cstring) const;
|
||||
bool operator>=(const char *cstring) const;
|
||||
|
||||
/* Construct strings made up of combinations of other
|
||||
* strings, c-style strings, and characters */
|
||||
@@ -76,6 +86,21 @@ public:
|
||||
static inline bool operator==(char *cstring, const string & str)
|
||||
{ return str == cstring; }
|
||||
|
||||
static inline bool operator!=(char *cstring, const string & str)
|
||||
{ return str != cstring; }
|
||||
|
||||
static inline bool operator<(const char *cstring, const string & str)
|
||||
{ return str > cstring; }
|
||||
|
||||
static inline bool operator>(const char *cstring, const string & str)
|
||||
{ return str < cstring; }
|
||||
|
||||
static inline bool operator<=(const char *cstring, const string & str)
|
||||
{ return str >= cstring; }
|
||||
|
||||
static inline bool operator>=(const char *cstring, const string & str)
|
||||
{ return str <= cstring; }
|
||||
|
||||
|
||||
|
||||
static inline string & operator+=(const char *cstring, string & str)
|
||||
|
||||
Reference in new issue
Block a user