- Finished the ArrayFIFO test and debugged the implementation.
- Moved all the local #include directives to the top of the files, to catch any missing global #include directives.
This commit is contained in:
+17
-25
@@ -5,47 +5,39 @@
|
||||
* Author: Miha Vitorovic
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "version.h"
|
||||
|
||||
using std::stringstream;
|
||||
using epics::pvData::String;
|
||||
|
||||
namespace epics {
|
||||
namespace pvAccess {
|
||||
|
||||
using epics::pvData::String;
|
||||
|
||||
const String Version::getLongVersionString() const {
|
||||
String ret;
|
||||
ret += getProductName();
|
||||
ret += " [";
|
||||
ret += getImplementationLanguage();
|
||||
ret += "] v";
|
||||
ret += getMajorVersion();
|
||||
ret += ".";
|
||||
ret += getMinorVersion();
|
||||
ret += ".";
|
||||
stringstream ret;
|
||||
ret<<getProductName()<<" ["<<getImplementationLanguage();
|
||||
ret<<"] v"<<getMajorVersion()<<"."<<getMinorVersion()<<".";
|
||||
if(getDevelopmentVersion()>0) {
|
||||
ret += "D";
|
||||
ret += getDevelopmentVersion();
|
||||
ret<<"D"<<getDevelopmentVersion();
|
||||
} else
|
||||
ret += getMaintenanceVersion();
|
||||
ret<<getMaintenanceVersion();
|
||||
|
||||
return ret;
|
||||
return ret.str();
|
||||
}
|
||||
|
||||
const String Version::getVersionString() const {
|
||||
String ret;
|
||||
ret += getProductName();
|
||||
ret += " v";
|
||||
ret += getMajorVersion();
|
||||
ret += ".";
|
||||
ret += getMinorVersion();
|
||||
ret += ".";
|
||||
stringstream ret;
|
||||
ret<<getProductName()<<" v"<<getMajorVersion()<<".";
|
||||
ret<<getMinorVersion()<<".";
|
||||
if(getDevelopmentVersion()>0) {
|
||||
ret += "D";
|
||||
ret += getDevelopmentVersion();
|
||||
ret<<"D"<<getDevelopmentVersion();
|
||||
} else
|
||||
ret += getMaintenanceVersion();
|
||||
ret<<getMaintenanceVersion();
|
||||
|
||||
return ret;
|
||||
return ret.str();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,42 +5,132 @@
|
||||
* Author: Miha Vitorovic
|
||||
*/
|
||||
|
||||
#define ARRAY_FIFO_DEBUG 1
|
||||
#include "arrayFIFO.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <epicsAssert.h>
|
||||
|
||||
#include "arrayFIFO.h"
|
||||
|
||||
using namespace epics::pvAccess;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
ArrayFIFO<int> fifo;
|
||||
ArrayFIFO<int> fifoInt;
|
||||
|
||||
assert(fifo.size()==0);
|
||||
assert(fifo.isEmpty());
|
||||
assert(fifoInt.size()==0);
|
||||
assert(fifoInt.isEmpty());
|
||||
|
||||
cout<<"Testing clear..."<<endl;
|
||||
fifo.push(3);
|
||||
assert(fifo.size()==1);
|
||||
cout<<"Testing clear."<<endl;
|
||||
fifoInt.push(3);
|
||||
assert(fifoInt.size()==1);
|
||||
|
||||
fifo.clear();
|
||||
assert(fifo.isEmpty());
|
||||
fifoInt.clear();
|
||||
assert(fifoInt.isEmpty());
|
||||
|
||||
cout<<"Testing push/pop..."<<endl;
|
||||
fifo.push(5);
|
||||
fifo.push(6);
|
||||
fifo.push(7);
|
||||
assert(fifo.size()==3);
|
||||
cout<<"Testing push/pop."<<endl;
|
||||
fifoInt.push(5);
|
||||
fifoInt.push(6);
|
||||
fifoInt.push(7);
|
||||
assert(fifoInt.size()==3);
|
||||
|
||||
assert(fifo.pop()==7);
|
||||
assert(fifo.size()==2);
|
||||
assert(fifoInt.pop()==7);
|
||||
assert(fifoInt.size()==2);
|
||||
|
||||
assert(fifo.pop()==6);
|
||||
assert(fifo.size()==1);
|
||||
assert(fifoInt.pop()==6);
|
||||
assert(fifoInt.size()==1);
|
||||
|
||||
assert(fifo.pop()==5);
|
||||
assert(fifo.size()==0);
|
||||
assert(fifoInt.pop()==5);
|
||||
assert(fifoInt.size()==0);
|
||||
|
||||
cout<<"Testing FIFO ops (first/last)."<<endl;
|
||||
fifoInt.addFirst(100);
|
||||
fifoInt.addFirst(200);
|
||||
fifoInt.addFirst(300);
|
||||
fifoInt.addFirst(400);
|
||||
fifoInt.addFirst(500);
|
||||
|
||||
assert(fifoInt.size()==5);
|
||||
assert(fifoInt.pollLast()==100);
|
||||
assert(fifoInt.pollLast()==200);
|
||||
assert(fifoInt.pollLast()==300);
|
||||
assert(fifoInt.pollLast()==400);
|
||||
assert(fifoInt.pollLast()==500);
|
||||
assert(fifoInt.isEmpty());
|
||||
|
||||
cout<<"Testing FIFO ops (last/first)."<<endl;
|
||||
fifoInt.addLast(150);
|
||||
fifoInt.addLast(250);
|
||||
fifoInt.addLast(350);
|
||||
fifoInt.addLast(450);
|
||||
fifoInt.addLast(550);
|
||||
assert(fifoInt.size()==5);
|
||||
|
||||
assert(fifoInt.pollFirst()==150);
|
||||
assert(fifoInt.pollFirst()==250);
|
||||
assert(fifoInt.pollFirst()==350);
|
||||
assert(fifoInt.pollFirst()==450);
|
||||
assert(fifoInt.pollFirst()==550);
|
||||
assert(fifoInt.isEmpty());
|
||||
|
||||
cout<<"Testing remove, peek."<<endl;
|
||||
fifoInt.addFirst(1000);
|
||||
fifoInt.addFirst(2000);
|
||||
fifoInt.addFirst(3000);
|
||||
fifoInt.addFirst(4000);
|
||||
fifoInt.addFirst(5000);
|
||||
fifoInt.addFirst(6000);
|
||||
fifoInt.addFirst(7000);
|
||||
// - - - - - - - - - - - -
|
||||
fifoInt.addFirst(8000);
|
||||
fifoInt.addFirst(9000);
|
||||
fifoInt.addFirst(10000);
|
||||
|
||||
assert(fifoInt.peekFirst()==10000);
|
||||
assert(fifoInt.peekLast()==1000);
|
||||
|
||||
assert(fifoInt.size()==10);
|
||||
assert(fifoInt.remove(9000));
|
||||
assert(fifoInt.size()==9);
|
||||
assert(!fifoInt.remove(3500));
|
||||
assert(fifoInt.size()==9);
|
||||
|
||||
assert(fifoInt.pollLast()==1000);
|
||||
assert(fifoInt.pollLast()==2000);
|
||||
assert(fifoInt.pollLast()==3000);
|
||||
assert(fifoInt.pollLast()==4000);
|
||||
assert(fifoInt.pollLast()==5000);
|
||||
assert(fifoInt.pollLast()==6000);
|
||||
assert(fifoInt.pollLast()==7000);
|
||||
// - - - - - - - - - - - -
|
||||
assert(fifoInt.pollLast()==8000);
|
||||
assert(fifoInt.pollLast()==10000);
|
||||
assert(fifoInt.isEmpty());
|
||||
|
||||
cout<<"Testing increase buffer."<<endl;
|
||||
fifoInt.addLast(100100);
|
||||
fifoInt.addLast(100200);
|
||||
fifoInt.addLast(100300);
|
||||
fifoInt.addLast(100400);
|
||||
fifoInt.addLast(100500);
|
||||
fifoInt.addLast(100600);
|
||||
fifoInt.addLast(100700);
|
||||
fifoInt.addLast(100800);
|
||||
fifoInt.addLast(100900);
|
||||
fifoInt.addLast(101000);
|
||||
fifoInt.addLast(101100);
|
||||
fifoInt.addLast(101200);
|
||||
fifoInt.addLast(101300);
|
||||
fifoInt.addLast(101400);
|
||||
fifoInt.addLast(101500);
|
||||
fifoInt.addLast(101600);
|
||||
fifoInt.addLast(101700);
|
||||
fifoInt.addLast(101800);
|
||||
|
||||
assert(fifoInt.size()==18);
|
||||
fifoInt.debugState();
|
||||
fifoInt.clear();
|
||||
assert(fifoInt.isEmpty());
|
||||
|
||||
cout<<"\nPASSED!\n";
|
||||
return 0;
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
* Author: Miha Vitorovic
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "hexDump.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace epics::pvAccess;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
* Author: Miha Vitorovic
|
||||
*/
|
||||
|
||||
#include "wildcharMatcher.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <epicsAssert.h>
|
||||
|
||||
#include "wildcharMatcher.h"
|
||||
|
||||
using namespace epics::pvAccess;
|
||||
using std::cout;
|
||||
|
||||
@@ -59,4 +59,5 @@ int main(int argc, char *argv[]) {
|
||||
cout<<"Testing for '*[p-z]tring*'.\n";
|
||||
assert(match("*[p-z]tring*", testString));
|
||||
cout<<"\nPASSED!\n";
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
#ifndef ARRAYFIFO_H_
|
||||
#define ARRAYFIFO_H_
|
||||
|
||||
#ifdef ARRAY_FIFO_DEBUG
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
#include <lock.h>
|
||||
#include <epicsException.h>
|
||||
|
||||
@@ -18,7 +22,7 @@ using epics::pvData::BaseException;
|
||||
namespace epics {
|
||||
namespace pvAccess {
|
||||
|
||||
template <class T>
|
||||
template<class T>
|
||||
class ArrayFIFO {
|
||||
public:
|
||||
/**
|
||||
@@ -117,6 +121,17 @@ namespace epics {
|
||||
*/
|
||||
bool remove(const T e);
|
||||
|
||||
#ifdef ARRAY_FIFO_DEBUG
|
||||
void debugState() {
|
||||
size_t mask = _size-1;
|
||||
std::cout<<"h:"<<_head<<",t:"<<_tail<<",c:"<<_size;
|
||||
std::cout<<",s:"<<size()<<std::endl;
|
||||
std::cout<<"Content:"<<std::endl;
|
||||
for (int i = 0; i < _size; i++)
|
||||
std::cout<<"["<<i<<"]: "<<_elements[i]<<std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
T* _elements; // array of pointers
|
||||
size_t _head, _tail, _size;
|
||||
@@ -135,7 +150,8 @@ namespace epics {
|
||||
*/
|
||||
void doubleCapacity();
|
||||
|
||||
void arraycopy(T* src, size_t srcPos, T* dest, size_t destPos, size_t length);
|
||||
void arraycopy(T* src, size_t srcPos, T* dest, size_t destPos,
|
||||
size_t length);
|
||||
|
||||
/**
|
||||
* Removes the element at the specified position in the elements array,
|
||||
@@ -160,8 +176,12 @@ namespace epics {
|
||||
template<class T>
|
||||
void ArrayFIFO<T>::arraycopy(T* src, size_t srcPos, T* dest,
|
||||
size_t destPos, size_t length) {
|
||||
for(size_t i = 0; i<length; i++)
|
||||
dest[destPos++] = src[srcPos++];
|
||||
if(srcPos<destPos) // this takes care of same-buffer copy
|
||||
for(int i = length-1; i>=0; i--)
|
||||
dest[destPos+i] = src[srcPos+i];
|
||||
else
|
||||
for(size_t i = 0; i<length; i++)
|
||||
dest[destPos++] = src[srcPos++];
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -237,10 +257,8 @@ namespace epics {
|
||||
|
||||
if(isEmpty()) THROW_BASE_EXCEPTION("ArrayFIFO empty");
|
||||
|
||||
size_t h = _head;
|
||||
T result = _elements[h]; // Element is null if deque empty
|
||||
_elements[h] = NULL; // Must null out slot
|
||||
_head = (h+1)&(_size-1);
|
||||
T result = _elements[_head]; // Element is null if deque empty
|
||||
_head = (_head+1)&(_size-1);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -250,10 +268,8 @@ namespace epics {
|
||||
|
||||
if(isEmpty()) THROW_BASE_EXCEPTION("ArrayFIFO empty");
|
||||
|
||||
int t = (_tail-1)&(_size-1);
|
||||
T result = _elements[t];
|
||||
_tail = t;
|
||||
return result;
|
||||
_tail = (_tail-1)&(_size-1);
|
||||
return _elements[_tail];
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -312,11 +328,12 @@ namespace epics {
|
||||
|
||||
template<class T>
|
||||
bool ArrayFIFO<T>::del(const size_t i) {
|
||||
int mask = _size-1;
|
||||
int h = _head;
|
||||
int t = _tail;
|
||||
int front = (i-h)&mask;
|
||||
int back = (t-i)&mask;
|
||||
// i is absolute index in the array
|
||||
size_t mask = _size-1;
|
||||
size_t h = _head;
|
||||
size_t t = _tail;
|
||||
size_t front = (i-h)&mask;
|
||||
size_t back = (t-i)&mask;
|
||||
|
||||
// Invariant: head <= i < tail mod circularity
|
||||
if(front>=((t-h)&mask)) THROW_BASE_EXCEPTION(
|
||||
@@ -329,11 +346,11 @@ namespace epics {
|
||||
}
|
||||
else { // Wrap around
|
||||
arraycopy(_elements, 0, _elements, 1, i);
|
||||
_elements[0] = _elements[mask];
|
||||
if(t>0) _elements[0] = _elements[mask];
|
||||
arraycopy(_elements, h, _elements, h+1, mask-h);
|
||||
}
|
||||
_elements[h] = NULL;
|
||||
_head = (h+1)&mask;
|
||||
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
@@ -357,10 +374,10 @@ namespace epics {
|
||||
|
||||
if(isEmpty()) return false; // nothing to do
|
||||
|
||||
int mask = _size-1;
|
||||
int i = _head;
|
||||
size_t mask = _size-1;
|
||||
size_t i = _head;
|
||||
while(i!=_tail) {
|
||||
if(e == _elements[i]) {
|
||||
if(e==_elements[i]) {
|
||||
del(i);
|
||||
return true;
|
||||
}
|
||||
@@ -369,7 +386,6 @@ namespace epics {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
* Author: Miha Vitorovic
|
||||
*/
|
||||
|
||||
#include "hexDump.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "hexDump.h"
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
* Author: Miha Vitorovic
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "wildcharMatcher.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using std::cout;
|
||||
|
||||
namespace epics {
|
||||
|
||||
Reference in New Issue
Block a user