[Sumover-dev] [svn commit] r4305 - vic/branches/cc/cc/test
sumover-dev at cs.ucl.ac.uk
sumover-dev at cs.ucl.ac.uk
Fri Nov 7 19:40:42 GMT 2008
Author: soohyunc
Date: Fri Nov 7 19:40:41 2008
New Revision: 4305
Added:
vic/branches/cc/cc/test/buffer.cpp (contents, props changed)
vic/branches/cc/cc/test/buffer.h (contents, props changed)
Modified:
vic/branches/cc/cc/test/config.h
Log:
"pktbuf" emulation for the test code
(this is a simple c++ linked list implementation)
Added: vic/branches/cc/cc/test/buffer.cpp
==============================================================================
--- (empty file)
+++ vic/branches/cc/cc/test/buffer.cpp Fri Nov 7 19:40:41 2008
@@ -0,0 +1,75 @@
+/*
+ * buffer.cpp
+ * (implementation for buffer - a simple c++ linked list)
+ */
+
+/* $Id$ */
+
+#include "buffer.h"
+
+// insert
+void buffer::insert (int val, data *ptr) {
+ if (!ptr) {
+ insert_front (val);
+ } else {
+ new data (val, ptr);
+ size_up();
+ }
+}
+
+// insert front
+void buffer::insert_front (int val) {
+ data *ptr = new data(val);
+
+ if (!head_) {
+ head_ = tail_ = ptr;
+ } else {
+ ptr->next(head_);
+ head_ = ptr;
+ }
+
+ size_up();
+}
+
+// insert end
+void buffer::insert_end (int val) {
+ if (tail_) {
+ tail_ = head_ = new data (val);
+ } else {
+ tail_ = new data (val, tail_);
+ }
+
+ size_up();
+}
+
+// find
+void buffer::find (int val) {
+ data* ptr = head_;
+
+ while (ptr) {
+ if (ptr->get_val() == val)
+ break;
+ ptr = ptr->next();
+ }
+ return ptr;
+}
+
+// remove front
+void buffer::remove_front() {
+ if (head_) {
+ data *ptr = head_;
+ head_ = head_->next();
+
+ size_down();
+ delete ptr;
+ }
+}
+
+// purge
+void buffer::purge() {
+ while (head_)
+ remove_front();
+
+ size_ = 0;
+ head_ = tail_ = 0;
+}
Added: vic/branches/cc/cc/test/buffer.h
==============================================================================
--- (empty file)
+++ vic/branches/cc/cc/test/buffer.h Fri Nov 7 19:40:41 2008
@@ -0,0 +1,72 @@
+/*
+ * buffer.h
+ * (pktbuf emulation for unit test)
+ */
+
+/* $Id$ */
+
+#include "config.h"
+
+// buffer is a linked list
+class data;
+
+class buffer {
+public:
+ // default constructor
+ buffer() : head_(0), tail_(0), size_(0) {};
+
+ // return list size
+ inline int size() { return size_; }
+
+ // increase list size
+ inline void size_up() { ++size_; }
+
+ // decrease list size
+ inline void size_down() { --size_; }
+
+ // insert
+ void insert (int val, data *ptr);
+
+ // insert front
+ void insert_front (int val);
+
+ // insert end
+ void insert_end (int val);
+
+ // find
+ data* find (int val);
+
+ // remove
+ int remove (int val);
+
+ // remove front
+ void remove_front();
+
+ // purge list
+ void purge();
+
+private:
+ data* head_;
+ data* tail_;
+ int size_;
+};
+
+// buffer contents
+class data {
+public:
+ friend class buffer;
+
+ // default constructor
+ data() : val_(0), next_(0) {};
+ data (int val, data *loc = 0);
+
+ // value
+ int get_val() { return val_; }
+
+ // next
+ data* next() { return next_; }
+
+private:
+ int val_; // hold a number
+ data *next_; // hold the address of the next item on the list
+};
Modified: vic/branches/cc/cc/test/config.h
==============================================================================
--- vic/branches/cc/cc/test/config.h (original)
+++ vic/branches/cc/cc/test/config.h Fri Nov 7 19:40:41 2008
@@ -1,4 +1,9 @@
+/*
+ * config.h to be included in the test codes
+ */
+
/* $Id$ */
+
#ifdef vic_cc_test_config_h
#define vic_cc_test_config_h
More information about the Sumover-dev
mailing list