--- a/src/common/buffer.cc Fri Oct 20 15:09:24 2006 +0200
+++ b/src/common/buffer.cc Sat Oct 21 11:35:02 2006 +0200
@@ -34,9 +34,10 @@
struct Buffer::BufferData *
Buffer::Allocate (uint32_t reqSize, uint32_t reqStart)
{
- if (reqSize == 0) {
+ if (reqSize == 0)
+ {
reqSize = 1;
- }
+ }
assert (reqSize >= 1);
uint32_t size = reqSize - 1 + sizeof (struct Buffer::BufferData);
uint8_t *b = new uint8_t [size];
@@ -61,34 +62,40 @@
{
assert (data->m_count == 0);
/* get rid of it if it is too small for later reuse. */
- if (data->m_size < (Buffer::m_maxTotalAddStart + Buffer::m_maxTotalAddEnd)) {
+ if (data->m_size < (Buffer::m_maxTotalAddStart + Buffer::m_maxTotalAddEnd))
+ {
Buffer::Deallocate (data);
return;
- }
+ }
/* feed into free list */
- if (Buffer::m_freeList.size () > 1000) {
+ if (Buffer::m_freeList.size () > 1000)
+ {
Buffer::Deallocate (data);
- } else {
+ }
+ else
+ {
Buffer::m_freeList.push_back (data);
- }
+ }
}
Buffer::BufferData *
Buffer::Create (void)
{
/* try to find a buffer correctly sized. */
- while (!Buffer::m_freeList.empty ()) {
+ while (!Buffer::m_freeList.empty ())
+ {
struct Buffer::BufferData *data = Buffer::m_freeList.back ();
Buffer::m_freeList.pop_back ();
- if (data->m_size >= (m_maxTotalAddStart + m_maxTotalAddEnd)) {
+ if (data->m_size >= (m_maxTotalAddStart + m_maxTotalAddEnd))
+ {
data->m_initialStart = m_maxTotalAddStart;
data->m_dirtyStart = m_maxTotalAddStart;
data->m_dirtySize = 0;
data->m_count = 1;
return data;
- }
+ }
Buffer::Deallocate (data);
- }
+ }
struct Buffer::BufferData *data = Buffer::Allocate (m_maxTotalAddStart+m_maxTotalAddEnd,
m_maxTotalAddStart);
assert (data->m_count == 1);
@@ -122,57 +129,70 @@
{
assert (m_start <= m_data->m_initialStart);
bool isDirty = m_data->m_count > 1 && m_start > m_data->m_dirtyStart;
- if (m_start >= start && !isDirty) {
+ if (m_start >= start && !isDirty)
+ {
/* enough space in the buffer and not dirty. */
m_start -= start;
m_size += start;
- } else if (m_size + start <= m_data->m_size && !isDirty) {
+ }
+ else if (m_size + start <= m_data->m_size && !isDirty)
+ {
/* enough space but need to move data around to fit new data */
memmove (m_data->m_data + start, GetStart (), m_size);
assert (start > m_start);
m_data->m_initialStart += start;
m_start = 0;
m_size += start;
- } else if (m_start < start) {
+ }
+ else if (m_start < start)
+ {
/* not enough space in buffer */
uint32_t newSize = m_size + start;
struct Buffer::BufferData *newData = Buffer::Allocate (newSize, 0);
memcpy (newData->m_data + start, GetStart (), m_size);
newData->m_initialStart = m_data->m_initialStart + start;
m_data->m_count--;
- if (m_data->m_count == 0) {
+ if (m_data->m_count == 0)
+ {
Buffer::Deallocate (m_data);
- }
+ }
m_data = newData;
m_start = 0;
m_size = newSize;
- } else {
+ }
+ else
+ {
/* enough space in the buffer but it is dirty ! */
assert (isDirty);
struct Buffer::BufferData *newData = Buffer::Create ();
memcpy (newData->m_data + m_start, GetStart (), m_size);
newData->m_initialStart = m_data->m_initialStart;
m_data->m_count--;
- if (m_data->m_count == 0) {
+ if (m_data->m_count == 0)
+ {
Recycle (m_data);
- }
+ }
m_data = newData;
m_start -= start;
m_size += start;
- }
+ }
// update dirty area
m_data->m_dirtyStart = m_start;
m_data->m_dirtySize = m_size;
// update m_maxTotalAddStart
uint32_t addedAtStart;
- if (m_data->m_initialStart > m_start) {
+ if (m_data->m_initialStart > m_start)
+ {
addedAtStart = m_data->m_initialStart - m_start;
- } else {
+ }
+ else
+ {
addedAtStart = 0;
- }
- if (addedAtStart > m_maxTotalAddStart) {
+ }
+ if (addedAtStart > m_maxTotalAddStart)
+ {
m_maxTotalAddStart = addedAtStart;
- }
+ }
TRACE ("start add="<<start<<", start="<<m_start<<", size="<<m_size<<", zero="<<m_zeroAreaSize<<
", real size="<<m_data->m_size<<", ini start="<<m_data->m_initialStart<<
", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
@@ -183,10 +203,13 @@
assert (m_start <= m_data->m_initialStart);
bool isDirty = m_data->m_count > 1 &&
m_start + m_size < m_data->m_dirtyStart + m_data->m_dirtySize;
- if (m_start + m_size + end <= m_data->m_size && !isDirty) {
+ if (m_start + m_size + end <= m_data->m_size && !isDirty)
+ {
/* enough space in buffer and not dirty */
m_size += end;
- } else if (m_size + end <= m_data->m_size && !isDirty) {
+ }
+ else if (m_size + end <= m_data->m_size && !isDirty)
+ {
/* enough space but need to move data around to fit the extra data */
uint32_t newStart = m_data->m_size - (m_size + end);
memmove (m_data->m_data + newStart, GetStart (), m_size);
@@ -194,46 +217,56 @@
m_data->m_initialStart -= m_start - newStart;
m_start = newStart;
m_size += end;
- } else if (m_start + m_size + end > m_data->m_size) {
+ }
+ else if (m_start + m_size + end > m_data->m_size)
+ {
/* not enough space in buffer */
uint32_t newSize = m_size + end;
struct Buffer::BufferData *newData = Buffer::Allocate (newSize, 0);
memcpy (newData->m_data, GetStart (), m_size);
newData->m_initialStart = m_data->m_initialStart;
m_data->m_count--;
- if (m_data->m_count == 0) {
+ if (m_data->m_count == 0)
+ {
Buffer::Deallocate (m_data);
- }
+ }
m_data = newData;
m_size = newSize;
m_start = 0;
- } else {
+ }
+ else
+ {
/* enough space in the buffer but it is dirty ! */
assert (isDirty);
struct Buffer::BufferData *newData = Buffer::Create ();
memcpy (newData->m_data + m_start, GetStart (), m_size);
newData->m_initialStart = m_data->m_initialStart;
m_data->m_count--;
- if (m_data->m_count == 0) {
+ if (m_data->m_count == 0)
+ {
Recycle (m_data);
- }
+ }
m_data = newData;
m_size += end;
- }
+ }
// update dirty area
m_data->m_dirtyStart = m_start;
m_data->m_dirtySize = m_size;
// update m_maxTotalAddEnd
uint32_t endLoc = m_start + m_size;
uint32_t addedAtEnd;
- if (m_data->m_initialStart < endLoc) {
+ if (m_data->m_initialStart < endLoc)
+ {
addedAtEnd = endLoc - m_data->m_initialStart;
- } else {
+ }
+ else
+ {
addedAtEnd = 0;
- }
- if (addedAtEnd > m_maxTotalAddEnd) {
+ }
+ if (addedAtEnd > m_maxTotalAddEnd)
+ {
m_maxTotalAddEnd = addedAtEnd;
- }
+ }
TRACE ("end add="<<end<<", start="<<m_start<<", size="<<m_size<<", zero="<<m_zeroAreaSize<<
", real size="<<m_data->m_size<<", ini start="<<m_data->m_initialStart<<
", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
@@ -242,83 +275,110 @@
void
Buffer::RemoveAtStart (uint32_t start)
{
- if (m_zeroAreaSize == 0) {
- if (m_size <= start) {
+ if (m_zeroAreaSize == 0)
+ {
+ if (m_size <= start)
+ {
m_start += m_size;
m_size = 0;
- } else {
+ }
+ else
+ {
m_start += start;
m_size -= start;
- }
- } else {
+ }
+ }
+ else
+ {
assert (m_data->m_initialStart >= m_start);
uint32_t zeroStart = m_data->m_initialStart - m_start;
uint32_t zeroEnd = zeroStart + m_zeroAreaSize;
uint32_t dataEnd = m_size + m_zeroAreaSize;
- if (start <= zeroStart) {
+ if (start <= zeroStart)
+ {
/* only remove start of buffer */
m_start += start;
m_size -= start;
- } else if (start <= zeroEnd) {
+ }
+ else if (start <= zeroEnd)
+ {
/* remove start of buffer _and_ start of zero area */
m_start += zeroStart;
uint32_t zeroDelta = start - zeroStart;
m_zeroAreaSize -= zeroDelta;
assert (zeroDelta <= start);
m_size -= zeroStart;
- } else if (start <= dataEnd) {
+ }
+ else if (start <= dataEnd)
+ {
/* remove start of buffer, complete zero area, and part
* of end of buffer */
m_start += start - m_zeroAreaSize;
m_size -= start - m_zeroAreaSize;
m_zeroAreaSize = 0;
- } else {
+ }
+ else
+ {
/* remove all buffer */
m_start += m_size;
m_size = 0;
m_zeroAreaSize = 0;
- }
- }
- TRACE ("start remove="<<start<<", start="<<m_start<<", size="<<m_size<<", zero="<<m_zeroAreaSize<<
+ }
+ }
+ TRACE ("start remove="<<start<<", start="<<m_start<<", size="<<m_size<<
+ ", zero="<<m_zeroAreaSize<<
", real size="<<m_data->m_size<<", ini start="<<m_data->m_initialStart<<
", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
}
void
Buffer::RemoveAtEnd (uint32_t end)
{
- if (m_zeroAreaSize == 0) {
- if (m_size <= end) {
+ if (m_zeroAreaSize == 0)
+ {
+ if (m_size <= end)
+ {
m_size = 0;
- } else {
+ }
+ else
+ {
m_size -= end;
- }
- } else {
+ }
+ }
+ else
+ {
assert (m_data->m_initialStart >= m_start);
uint32_t zeroStart = m_data->m_initialStart - m_start;
uint32_t zeroEnd = zeroStart + m_zeroAreaSize;
uint32_t dataEnd = m_size + m_zeroAreaSize;
assert (zeroStart <= m_size);
assert (zeroEnd <= m_size + m_zeroAreaSize);
- if (dataEnd <= end) {
+ if (dataEnd <= end)
+ {
/* remove all buffer */
m_zeroAreaSize = 0;
m_start += m_size;
m_size = 0;
- } else if (dataEnd - zeroStart <= end) {
+ }
+ else if (dataEnd - zeroStart <= end)
+ {
/* remove end of buffer, zero area, part of start of buffer */
assert (end >= m_zeroAreaSize);
m_size -= end - m_zeroAreaSize;
m_zeroAreaSize = 0;
- } else if (dataEnd - zeroEnd <= end) {
+ }
+ else if (dataEnd - zeroEnd <= end)
+ {
/* remove end of buffer, part of zero area */
uint32_t zeroDelta = end - (dataEnd - zeroEnd);
m_zeroAreaSize -= zeroDelta;
m_size -= end - zeroDelta;
- } else {
+ }
+ else
+ {
/* remove part of end of buffer */
m_size -= end;
- }
- }
+ }
+ }
TRACE ("end remove="<<end<<", start="<<m_start<<", size="<<m_size<<", zero="<<m_zeroAreaSize<<
", real size="<<m_data->m_size<<", ini start="<<m_data->m_initialStart<<
", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
@@ -331,9 +391,10 @@
uint32_t zeroEnd = zeroStart + m_zeroAreaSize;
if (m_zeroAreaSize != 0 &&
start + length > zeroStart &&
- start <= zeroEnd) {
+ start <= zeroEnd)
+ {
TransformIntoRealBuffer ();
- }
+ }
Buffer tmp = *this;
tmp.RemoveAtStart (start);
tmp.RemoveAtEnd (GetSize () - (start + length));
@@ -343,7 +404,8 @@
void
Buffer::TransformIntoRealBuffer (void) const
{
- if (m_zeroAreaSize != 0) {
+ if (m_zeroAreaSize != 0)
+ {
assert (m_data->m_initialStart >= m_start);
assert (m_size >= (m_data->m_initialStart - m_start));
Buffer tmp;
@@ -358,7 +420,7 @@
i.Prev (dataEnd);
i.Write (m_data->m_data+m_data->m_initialStart,dataEnd);
*const_cast<Buffer *> (this) = tmp;
- }
+ }
}
@@ -401,27 +463,32 @@
uint8_t *expected = array;
uint8_t const*got;
got = b.PeekData ();
- for (uint32_t j = 0; j < n; j++) {
- if (got[j] != expected[j]) {
+ for (uint32_t j = 0; j < n; j++)
+ {
+ if (got[j] != expected[j])
+ {
success = false;
- }
- }
- if (!success) {
+ }
+ }
+ if (!success)
+ {
Failure () << "Buffer -- ";
Failure () << "expected: n=";
Failure () << n << ", ";
Failure ().setf (std::ios::hex, std::ios::basefield);
- for (uint32_t j = 0; j < n; j++) {
+ for (uint32_t j = 0; j < n; j++)
+ {
Failure () << (uint16_t)expected[j] << " ";
- }
+ }
Failure ().setf (std::ios::dec, std::ios::basefield);
Failure () << "got: ";
Failure ().setf (std::ios::hex, std::ios::basefield);
- for (uint32_t j = 0; j < n; j++) {
+ for (uint32_t j = 0; j < n; j++)
+ {
Failure () << (uint16_t)got[j] << " ";
- }
+ }
Failure () << std::endl;
- }
+ }
return success;
}
@@ -429,13 +496,14 @@
* available which is the case for gcc.
* XXX
*/
-#define ENSURE_WRITTEN_BYTES(buffer, n, ...) \
-{ \
- uint8_t bytes[] = {__VA_ARGS__}; \
- if (!EnsureWrittenBytes (buffer, n , bytes)) { \
- ok = false; \
- } \
-}
+#define ENSURE_WRITTEN_BYTES(buffer, n, ...) \
+ { \
+ uint8_t bytes[] = {__VA_ARGS__}; \
+ if (!EnsureWrittenBytes (buffer, n , bytes)) \
+ { \
+ ok = false; \
+ } \
+ }
bool
BufferTest::RunTests (void)
@@ -485,9 +553,10 @@
i.Prev (2);
i.WriteHtonU16 (0xff00);
i.Prev (2);
- if (i.ReadNtohU16 () != 0xff00) {
+ if (i.ReadNtohU16 () != 0xff00)
+ {
ok = false;
- }
+ }
i.Prev (2);
i.WriteU16 (saved);
ENSURE_WRITTEN_BYTES (buffer, 5, 0xff, 0x69, 0xde, 0xad, 0xff);
@@ -574,9 +643,10 @@
buffer.Begin ().WriteU8 (0x21);
ENSURE_WRITTEN_BYTES (buffer, 6, 0x21, 0, 0, 0, 0xab, 0xcd);
buffer.RemoveAtEnd (8);
- if (buffer.GetSize () != 0) {
+ if (buffer.GetSize () != 0)
+ {
ok = false;
- }
+ }
--- a/src/common/buffer.h Fri Oct 20 15:09:24 2006 +0200
+++ b/src/common/buffer.h Sat Oct 21 11:35:02 2006 +0200
@@ -371,9 +371,10 @@
m_start (m_maxTotalAddStart),
m_size (0)
{
- if (m_start > m_data->m_size) {
+ if (m_start > m_data->m_size)
+ {
m_start = 0;
- }
+ }
assert (m_start <= m_data->m_size);
}
@@ -383,9 +384,10 @@
m_start (m_maxTotalAddStart),
m_size (0)
{
- if (m_start > m_data->m_size) {
+ if (m_start > m_data->m_size)
+ {
m_start = 0;
- }
+ }
assert (m_start <= m_data->m_size);
}
@@ -403,15 +405,17 @@
Buffer &
Buffer::operator = (Buffer const&o)
{
- if (m_data != o.m_data) {
+ if (m_data != o.m_data)
+ {
// not assignment to self.
m_data->m_count--;
- if (m_data->m_count == 0) {
+ if (m_data->m_count == 0)
+ {
Recycle (m_data);
- }
+ }
m_data = o.m_data;
m_data->m_count++;
- }
+ }
m_zeroAreaSize = o.m_zeroAreaSize;
m_start = o.m_start;
m_size = o.m_size;
@@ -422,9 +426,10 @@
Buffer::~Buffer ()
{
m_data->m_count--;
- if (m_data->m_count == 0) {
+ if (m_data->m_count == 0)
+ {
Recycle (m_data);
- }
+ }
}
@@ -520,11 +525,14 @@
(m_current >= m_zeroEnd))
);
uint32_t index;
- if (m_current < m_zeroStart) {
+ if (m_current < m_zeroStart)
+ {
index = m_current;
- } else {
+ }
+ else
+ {
index = m_current - (m_zeroEnd-m_zeroStart);
- }
+ }
return index;
}
--- a/src/common/callback-tracer.h Fri Oct 20 15:09:24 2006 +0200
+++ b/src/common/callback-tracer.h Sat Oct 21 11:35:02 2006 +0200
@@ -45,34 +45,40 @@
m_callback = callback;
}
void operator() (void) {
- if (!m_callback.IsNull ()) {
+ if (!m_callback.IsNull ())
+ {
m_callback ();
- }
+ }
}
void operator() (T1 a1) {
- if (!m_callback.IsNull ()) {
+ if (!m_callback.IsNull ())
+ {
m_callback (a1);
- }
+ }
}
void operator() (T1 a1, T2 a2) {
- if (!m_callback.IsNull ()) {
+ if (!m_callback.IsNull ())
+ {
m_callback (a1,a2);
- }
+ }
}
void operator() (T1 a1, T2 a2, T3 a3) {
- if (!m_callback.IsNull ()) {
+ if (!m_callback.IsNull ())
+ {
m_callback (a1,a2,a3);
- }
+ }
}
void operator() (T1 a1, T2 a2, T3 a3, T4 a4) {
- if (!m_callback.IsNull ()) {
+ if (!m_callback.IsNull ())
+ {
m_callback (a1,a2,a3,a4);
- }
+ }
}
void operator() (T1 a1, T2 a2, T3 a3, T4 a4,T5 a5) {
- if (!m_callback.IsNull ()) {
+ if (!m_callback.IsNull ())
+ {
m_callback (a1,a2,a3,a4,a5);
- }
+ }
}
private:
--- a/src/common/data-writer.cc Fri Oct 20 15:09:24 2006 +0200
+++ b/src/common/data-writer.cc Sat Oct 21 11:35:02 2006 +0200
@@ -81,19 +81,21 @@
void
DataWriterPrivate::Write (uint8_t *buffer, uint32_t size)
{
- while (size > 0) {
+ while (size > 0)
+ {
uint32_t toCopy = min (BUFFER_SIZE - m_current, size);
memcpy (m_data + m_current, buffer, toCopy);
size -= toCopy;
m_current += toCopy;
buffer += toCopy;
- if (m_current == BUFFER_SIZE) {
+ if (m_current == BUFFER_SIZE)
+ {
ssize_t written = 0;
written = ::Write (m_fd, m_data, BUFFER_SIZE);
assert (written == BUFFER_SIZE);
m_current = 0;
- }
- }
+ }
+ }
}
DataWriter::DataWriter ()
--- a/src/common/pcap-writer.cc Fri Oct 20 15:09:24 2006 +0200
+++ b/src/common/pcap-writer.cc Sat Oct 21 11:35:02 2006 +0200
@@ -67,7 +67,8 @@
void
PcapWriter::WritePacket (Packet const packet)
{
- if (m_writer != 0) {
+ if (m_writer != 0)
+ {
uint64_t current = Simulator::Now ().Us ();
uint64_t s = current / 1000000;
uint64_t us = current % 1000000;
@@ -76,7 +77,7 @@
Write32 (packet.GetSize ());
Write32 (packet.GetSize ());
m_writer->Write (packet.PeekData (), packet.GetSize ());
- }
+ }
}
void
--- a/src/common/si-variable-tracer.h Fri Oct 20 15:09:24 2006 +0200
+++ b/src/common/si-variable-tracer.h Sat Oct 21 11:35:02 2006 +0200
@@ -44,9 +44,10 @@
}
protected:
void Notify (int64_t oldVal, int64_t newVal) {
- if (oldVal != newVal && !m_callback.IsNull ()) {
+ if (oldVal != newVal && !m_callback.IsNull ())
+ {
m_callback (oldVal, newVal);
- }
+ }
}
private:
ChangeNotifyCallback m_callback;
--- a/src/common/stream-tracer.h Fri Oct 20 15:09:24 2006 +0200
+++ b/src/common/stream-tracer.h Sat Oct 21 11:35:02 2006 +0200
@@ -38,22 +38,25 @@
: m_os (0) {}
template <typename T>
StreamTracer &operator << (T const&v) {
- if (m_os != 0) {
+ if (m_os != 0)
+ {
(*m_os) << v;
- }
+ }
return *this;
}
template <typename T>
StreamTracer &operator << (T &v) {
- if (m_os != 0) {
+ if (m_os != 0)
+ {
(*m_os) << v;
- }
+ }
return *this;
}
StreamTracer &operator << (std::ostream &(*v) (std::ostream &)) {
- if (m_os != 0) {
+ if (m_os != 0)
+ {
(*m_os) << v;
- }
+ }
return *this;
}
--- a/src/common/tags.cc Fri Oct 20 15:09:24 2006 +0200
+++ b/src/common/tags.cc Sat Oct 21 11:35:02 2006 +0200
@@ -36,18 +36,21 @@
uint32_t
TagRegistry::LookupUid (std::string uuid)
{
- if (!m_sorted) {
+ if (!m_sorted)
+ {
std::sort (m_registry.begin (), m_registry.end ());
m_sorted = true;
- }
+ }
assert (m_sorted);
uint32_t uid = 0;
- for (TagsDataCI i = m_registry.begin (); i != m_registry.end (); i++) {
- if (i->first == uuid) {
+ for (TagsDataCI i = m_registry.begin (); i != m_registry.end (); i++)
+ {
+ if (i->first == uuid)
+ {
return uid;
- }
+ }
uid++;
- }
+ }
// someone asked for a uid for an unregistered uuid.
assert ("You tried to use unregistered tag: make sure you create an "
"instance of type TagRegistration<YouTagType>.");
@@ -59,9 +62,10 @@
{
assert (m_registry.size () > uid);
PrettyPrinter prettyPrinter = m_registry[uid].second;
- if (prettyPrinter != 0) {
+ if (prettyPrinter != 0)
+ {
prettyPrinter (buf, os);
- }
+ }
}
@@ -74,23 +78,27 @@
Tags::AllocData (void)
{
struct Tags::TagData *retval;
- if (gFree != 0) {
+ if (gFree != 0)
+ {
retval = gFree;
gFree = gFree->m_next;
gN_free--;
- } else {
+ }
+ else
+ {
retval = new struct Tags::TagData ();
- }
+ }
return retval;
}
void
Tags::FreeData (struct TagData *data)
{
- if (gN_free > 1000) {
+ if (gN_free > 1000)
+ {
delete data;
return;
- }
+ }
gN_free++;
data->m_next = gFree;
gFree = data;
@@ -115,18 +123,23 @@
Tags::Remove (uint32_t id)
{
bool found = false;
- for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) {
- if (cur->m_id == id) {
+ for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
+ {
+ if (cur->m_id == id)
+ {
found = true;
- }
- }
- if (!found) {
+ }
+ }
+ if (!found)
+ {
return false;
- }
+ }
struct TagData *start = 0;
struct TagData **prevNext = &start;
- for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) {
- if (cur->m_id == id) {
+ for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
+ {
+ if (cur->m_id == id)
+ {
/**
* XXX
* Note: I believe that we could optimize this to
@@ -134,7 +147,7 @@
* and just link the already-copied list to the next tag.
*/
continue;
- }
+ }
struct TagData *copy = AllocData ();
copy->m_id = cur->m_id;
copy->m_count = 1;
@@ -142,7 +155,7 @@
memcpy (copy->m_data, cur->m_data, Tags::SIZE);
*prevNext = copy;
prevNext = ©->m_next;
- }
+ }
*prevNext = 0;
RemoveAll ();
m_next = start;
@@ -152,9 +165,10 @@
void
Tags::PrettyPrint (std::ostream &os)
{
- for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) {
+ for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
+ {
TagRegistry::PrettyPrint (cur->m_id, cur->m_data, os);
- }
+ }
}
@@ -228,18 +242,20 @@
tags.Add (a);
a.a = 0;
tags.Peek (a);
- if (a.a != 10) {
+ if (a.a != 10)
+ {
ok = false;
- }
+ }
//tags.prettyPrint (std::cout);
struct myTagB b;
b.b = 0xff;
tags.Add (b);
b.b = 0;
tags.Peek (b);
- if (b.b != 0xff) {
+ if (b.b != 0xff)
+ {
ok = false;
- }
+ }
//tags.prettyPrint (std::cout);
// make sure copy contains copy.
@@ -249,30 +265,36 @@
struct myTagA oA;
oA.a = 0;
other.Peek (oA);
- if (oA.a != 10) {
+ if (oA.a != 10)
+ {
ok = false;
- }
+ }
struct myTagB oB;
other.Peek (oB);
- if (oB.b != 0xff) {
+ if (oB.b != 0xff)
+ {
ok = false;
- }
+ }
// remove data.
other.Remove (oA);
- if (other.Peek (oA)) {
+ if (other.Peek (oA))
+ {
ok = false;
- }
+ }
//other.prettyPrint (std::cout);
- if (!tags.Peek (oA)) {
+ if (!tags.Peek (oA))
+ {
ok = false;
- }
+ }
other.Remove (oB);
- if (other.Peek (oB)) {
+ if (other.Peek (oB))
+ {
ok = false;
- }
- if (!tags.Peek (oB)) {
+ }
+ if (!tags.Peek (oB))
+ {
ok = false;
- }
+ }
other = tags;
Tags another = other;
@@ -281,12 +303,14 @@
another.Add (c);
c.c[0] = 0;
another.Peek (c);
- if (!another.Peek (c)) {
+ if (!another.Peek (c))
+ {
ok = false;
- }
- if (tags.Peek (c)) {
+ }
+ if (tags.Peek (c))
+ {
ok = false;
- }
+ }
other = other;
//other.prettyPrint (std::cout);
--- a/src/common/tags.h Fri Oct 20 15:09:24 2006 +0200
+++ b/src/common/tags.h Sat Oct 21 11:35:02 2006 +0200
@@ -202,9 +202,10 @@
assert (sizeof (T) <= Tags::SIZE);
uint8_t const*buf = reinterpret_cast<uint8_t const*> (&tag);
// ensure this id was not yet added
- for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) {
+ for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
+ {
assert (cur->m_id != TypeUid<T>::GetUid ());
- }
+ }
struct TagData *newStart = AllocData ();
newStart->m_count = 1;
newStart->m_next = 0;
@@ -228,13 +229,15 @@
{
assert (sizeof (T) <= Tags::SIZE);
uint8_t *buf = reinterpret_cast<uint8_t *> (&tag);
- for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) {
- if (cur->m_id == TypeUid<T>::GetUid ()) {
+ for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
+ {
+ if (cur->m_id == TypeUid<T>::GetUid ())
+ {
/* found tag */
memcpy (buf, cur->m_data, sizeof (T));
return true;
- }
- }
+ }
+ }
/* no tag found */
return false;
}
@@ -246,23 +249,26 @@
Tags::Tags (Tags const &o)
: m_next (o.m_next)
{
- if (m_next != 0) {
+ if (m_next != 0)
+ {
m_next->m_count++;
- }
+ }
}
Tags &
Tags::operator = (Tags const &o)
{
// self assignment
- if (m_next == o.m_next) {
+ if (m_next == o.m_next)
+ {
return *this;
- }
+ }
RemoveAll ();
m_next = o.m_next;
- if (m_next != 0) {
+ if (m_next != 0)
+ {
m_next->m_count++;
- }
+ }
return *this;
}
@@ -275,19 +281,23 @@
Tags::RemoveAll (void)
{
struct TagData *prev = 0;
- for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) {
+ for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next)
+ {
cur->m_count--;
- if (cur->m_count > 0) {
+ if (cur->m_count > 0)
+ {
break;
- }
- if (prev != 0) {
+ }
+ if (prev != 0)
+ {
FreeData (prev);
- }
+ }
prev = cur;
- }
- if (prev != 0) {
+ }
+ if (prev != 0)
+ {
FreeData (prev);
- }
+ }
m_next = 0;
}
--- a/src/common/trace-container.cc Fri Oct 20 15:09:24 2006 +0200
+++ b/src/common/trace-container.cc Sat Oct 21 11:35:02 2006 +0200
@@ -38,23 +38,27 @@
void
TraceContainer::SetUiVariableCallback (char const *name, Callback<void,uint64_t, uint64_t> callback)
{
- for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++) {
- if ((*i).second == name) {
+ for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++)
+ {
+ if ((*i).second == name)
+ {
(*i).first->SetCallback (callback);
return;
- }
- }
+ }
+ }
assert (false);
}
void
TraceContainer::SetSiVariableCallback (char const *name, Callback<void,int64_t, int64_t> callback)
{
- for (SiListI i = m_siList.begin (); i != m_siList.end (); i++) {
- if ((*i).second == name) {
+ for (SiListI i = m_siList.begin (); i != m_siList.end (); i++)
+ {
+ if ((*i).second == name)
+ {
(*i).first->SetCallback (callback);
return;
- }
- }
+ }
+ }
assert (false);
}
void
@@ -65,12 +69,14 @@
void
TraceContainer::SetStream (char const *name, std::ostream *os)
{
- for (StreamTracerListI i = m_traceStreamList.begin (); i != m_traceStreamList.end (); i++) {
- if ((*i).second == name) {
+ for (StreamTracerListI i = m_traceStreamList.begin (); i != m_traceStreamList.end (); i++)
+ {
+ if ((*i).second == name)
+ {
(*i).first->SetStream (os);
return;
- }
- }
+ }
+ }
assert (false);
}
@@ -78,24 +84,28 @@
TraceContainer::RegisterUiVariable (char const *name, UiVariableTracerBase *var)
{
// ensure unicity
- for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++) {
- if (i->second == name) {
+ for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++)
+ {
+ if (i->second == name)
+ {
m_uiList.erase (i);
break;
- }
- }
+ }
+ }
m_uiList.push_back (std::make_pair (var, name));
}
void
TraceContainer::RegisterSiVariable (char const *name, SiVariableTracerBase *var)
{
// ensure unicity
- for (SiListI i = m_siList.begin (); i != m_siList.end (); i++) {
- if (i->second == name) {
+ for (SiListI i = m_siList.begin (); i != m_siList.end (); i++)
+ {
+ if (i->second == name)
+ {
m_siList.erase (i);
break;
- }
- }
+ }
+ }
m_siList.push_back (std::make_pair (var, name));
}
void
@@ -108,12 +118,14 @@
TraceContainer::RegisterStream (char const *name, StreamTracer *stream)
{
// ensure unicity
- for (StreamTracerListI i = m_traceStreamList.begin (); i != m_traceStreamList.end (); i++) {
- if (i->second == name) {
+ for (StreamTracerListI i = m_traceStreamList.begin (); i != m_traceStreamList.end (); i++)
+ {
+ if (i->second == name)
+ {
m_traceStreamList.erase (i);
break;
- }
- }
+ }
+ }
m_traceStreamList.push_back (std::make_pair (stream,name));
}
@@ -121,12 +133,14 @@
void
TraceContainer::RegisterCallback (char const *name, CallbackTracerBase *tracer)
{
- for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) {
- if (i->second == name) {
+ for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
+ {
+ if (i->second == name)
+ {
m_callbackList.erase (i);
break;
- }
- }
+ }
+ }
m_callbackList.push_back (std::make_pair (tracer, name));
}
@@ -139,28 +153,36 @@
void
ns3::TraceContainer::PrintDebug (void)
{
- if (!m_uiList.empty ()) {
+ if (!m_uiList.empty ())
+ {
std::cout << "ui var: " << std::endl;
- for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++) {
+ for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++)
+ {
std::cout << " \"" << (*i).second << "\""<<std::endl;
- }
- }
- if (!m_siList.empty ()) {
+ }
+ }
+ if (!m_siList.empty ())
+ {
std::cout << "si var: " << std::endl;
- for (SiListI i = m_siList.begin (); i != m_siList.end (); i++) {
+ for (SiListI i = m_siList.begin (); i != m_siList.end (); i++)
+ {
std::cout << " \"" << (*i).second << "\""<<std::endl;
- }
- }
- if (!m_fList.empty ()) {
+ }
+ }
+ if (!m_fList.empty ())
+ {
std::cout << "f var: " << std::endl;
- for (FListI i = m_fList.begin (); i != m_fList.end (); i++) {
+ for (FListI i = m_fList.begin (); i != m_fList.end (); i++)
+ {
std::cout << " \"" << (*i).second << "\""<<std::endl;
- }
- }
- if (!m_callbackList.empty ()) {
+ }
+ }
+ if (!m_callbackList.empty ())
+ {
std::cout << "callback list: "<<std::endl;
- for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) {
+ for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
+ {
std::cout << " \"" << i->second << "\""<<std::endl;
- }
- }
+ }
+ }
}
--- a/src/common/trace-container.h Fri Oct 20 15:09:24 2006 +0200
+++ b/src/common/trace-container.h Sat Oct 21 11:35:02 2006 +0200
@@ -206,12 +206,14 @@
void
TraceContainer::SetCallback (char const *name, Callback<void,T1> callback)
{
- for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) {
- if (i->second == name) {
+ for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
+ {
+ if (i->second == name)
+ {
static_cast<CallbackTracer<T1> *> (i->first)->SetCallback (callback);
return;
- }
- }
+ }
+ }
#ifndef NDEBUG
assert (false);
#endif
@@ -220,12 +222,14 @@
void
TraceContainer::SetCallback (char const *name, Callback<void,T1,T2> callback)
{
- for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) {
- if (i->second == name) {
+ for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
+ {
+ if (i->second == name)
+ {
static_cast<CallbackTracer<T1,T2> *> (i->first)->SetCallback (callback);
return;
- }
- }
+ }
+ }
#ifndef NDEBUG
assert (false);
#endif
@@ -234,12 +238,14 @@
void
TraceContainer::SetCallback (char const *name, Callback<void,T1,T2,T3> callback)
{
- for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) {
- if (i->second == name) {
+ for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
+ {
+ if (i->second == name)
+ {
static_cast<CallbackTracer<T1,T2,T3> *> (i->first)->SetCallback (callback);
return;
- }
- }
+ }
+ }
#ifndef NDEBUG
assert (false);
#endif
@@ -248,12 +254,14 @@
void
TraceContainer::SetCallback (char const *name, Callback<void,T1,T2,T3,T4> callback)
{
- for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) {
- if (i->second == name) {
+ for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
+ {
+ if (i->second == name)
+ {
static_cast<CallbackTracer<T1,T2,T3,T4> *> (i->first)->SetCallback (callback);
return;
- }
- }
+ }
+ }
#ifndef NDEBUG
assert (false);
#endif
@@ -262,12 +270,14 @@
void
TraceContainer::SetCallback (char const *name, Callback<void,T1,T2,T3,T4,T5> callback)
{
- for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) {
- if (i->second == name) {
+ for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++)
+ {
+ if (i->second == name)
+ {
static_cast<CallbackTracer<T1,T2,T3,T4,T5> *> (i->first)->SetCallback (callback);
return;
- }
- }
+ }
+ }
#ifndef NDEBUG
assert (false);
#endif
--- a/src/common/ui-variable-tracer.h Fri Oct 20 15:09:24 2006 +0200
+++ b/src/common/ui-variable-tracer.h Sat Oct 21 11:35:02 2006 +0200
@@ -47,9 +47,10 @@
}
protected:
void Notify (uint64_t oldVal, uint64_t newVal) {
- if (oldVal != newVal && !m_callback.IsNull ()) {
+ if (oldVal != newVal && !m_callback.IsNull ())
+ {
m_callback (oldVal, newVal);
- }
+ }
}
private:
ChangeNotifyCallback m_callback;
--- a/src/common/variable-tracer-test.cc Fri Oct 20 15:09:24 2006 +0200
+++ b/src/common/variable-tracer-test.cc Sat Oct 21 11:35:02 2006 +0200
@@ -51,44 +51,61 @@
var = 10;
ovar = var;
- if (var == ovar) {
- }
- if (var != ovar) {
- }
- if (var > ovar) {
- }
- if (var >= ovar) {
- }
- if (var < ovar) {
- }
- if (var <= ovar) {
- }
+ if (var == ovar)
+ {
+ }
+ if (var != ovar)
+ {
+ }
+ if (var > ovar)
+ {
+ }
+ if (var >= ovar)
+ {
+ }
+ if (var < ovar)
+ {
+ }
+
+ if (var <= ovar)
- if (var == 1) {
- }
- if (var != 1) {
- }
- if (var > 1) {
- }
- if (var >= 1) {
- }
- if (var < 1) {
- }
- if (var <= 1) {
- }
+ if (var == 1)
+ {
+ }
+ if (var != 1)
+ {
+ }
+ if (var > 1)
+ {
+ }
+ if (var >= 1)
+ {
+ }
+ if (var < 1)
+ {
+ }
+ if (var <= 1)
+ {
+ }
- if (1 == ovar) {
- }
- if (1 != ovar) {
- }
- if (1 > ovar) {
- }
- if (1 >= ovar) {
- }
- if (1 < ovar) {
- }
- if (1 <= ovar) {
- }
+ if (1 == ovar)
+ {
+ }
+ if (1 != ovar)
+ {
+ }
+ if (1 > ovar)
+ {
+ }
+ if (1 >= ovar)
+ {
+ }
+ if (1 < ovar)
+ {
+ }
+ if (1 <= ovar)
+ {
+ }
var++;
++var;