summaryrefslogtreecommitdiff
path: root/comm/MsgBuffer.cc
diff options
context:
space:
mode:
authorchatty1993-11-29 10:37:30 +0000
committerchatty1993-11-29 10:37:30 +0000
commitcf5ac26fc18c06cf9b185efdf5b68a4a13217416 (patch)
treecbc68b725e66b09137331071aa6314301a664109 /comm/MsgBuffer.cc
parentd737da9ceccc110ac86d48f7fe17cff70f265cbf (diff)
downloadivy-league-cf5ac26fc18c06cf9b185efdf5b68a4a13217416.zip
ivy-league-cf5ac26fc18c06cf9b185efdf5b68a4a13217416.tar.gz
ivy-league-cf5ac26fc18c06cf9b185efdf5b68a4a13217416.tar.bz2
ivy-league-cf5ac26fc18c06cf9b185efdf5b68a4a13217416.tar.xz
Changed the profile of Get
Fixed documentation
Diffstat (limited to 'comm/MsgBuffer.cc')
-rw-r--r--comm/MsgBuffer.cc67
1 files changed, 39 insertions, 28 deletions
diff --git a/comm/MsgBuffer.cc b/comm/MsgBuffer.cc
index 0aefd6c..72d7668 100644
--- a/comm/MsgBuffer.cc
+++ b/comm/MsgBuffer.cc
@@ -14,6 +14,7 @@
#include "MsgBuffer.h"
#include "Message.h"
+#include "ccu/String.h"
#include <stdlib.h>
#include <string.h>
@@ -36,16 +37,17 @@ The initial size, the increments and the maximum sizes can be defined.
If the buffer exceeds its maximal size, it will be deleted when it becomes empty
in order to give it a smaller size.
-Data can be appended and extracted from the buffer by \fun{operator <<} and \fun{operator >>}.
+Data can be appended and extracted from the buffer by \fun{operator $<<$}
+and \fun{operator $>>$}.
When extracting data, the buffer may not contain enough bytes.
We say that a ``get error'' has occurred and the buffer remembers it until it is modified
-by the functions \fun{Append} or \fun{More}, or by \fun{operator <<}.
+by the functions \fun{Append} or \fun{More}, or by \fun{operator $<<$}.
The class \typ{^{pUchMsgBuffer}} implements smart pointers to buffers.
Smart pointers behave like pointers but they manage a reference count on the
pointed to objects for an automatic reclaim of dynamically allocated objects.
-\fig{buffer}{Some operations on a buffer.}
+\fig{FIGURES/buffer}{Some operations on a buffer.}
?*/
static int padding [] = { 0, 1, 2, 3};
@@ -199,7 +201,7 @@ UchMsgBuffer :: Flush (int n)
/*?
Flush the buffer until \var{p}.
-This can be used when the UchMsgBuffer.has been accessed through \fun{Buffer ()}
+This can be used when the buffer has been accessed through \fun{Buffer ()}
and you want to flush until a given position in the buffer.
?*/
void
@@ -357,35 +359,18 @@ UchMsgBuffer :: Get (byte* b, int n, bool peek)
return TRUE;
}
-/*?nextdoc?*/
-bool
-UchMsgBuffer :: Get (byte* b, bool peek)
-{
-//printf ("UchMsgBuffer %x : Get byte\n", this);
- if (GetErr)
- return FALSE;
- if (Stop - Start < 1) {
- GetErr = TRUE;
-//printf ("Get failed : %d bytes\n", Stop - Start);
- return FALSE;
- }
- *b = *Start;
- if (! peek)
- Flush (1);
- return TRUE;
-}
#ifdef DOC
/*?nextdoc?*/
bool
-UchMsgBuffer :: Get (char* c, bool peek)
+UchMsgBuffer :: Get (char& c, bool peek)
{
}
/*?nextdoc?*/
bool
-UchMsgBuffer :: Get (sword* s, bool peek)
+UchMsgBuffer :: Get (sword& s, bool peek)
{ }
/*?
@@ -394,7 +379,7 @@ Return TRUE if the data was actually extracted, else return FALSE and mark the b
If \var{peek} is TRUE, the buffer is not flushed after extracting the data.
?*/
bool
-UchMsgBuffer :: Get (lword* l, bool peek)
+UchMsgBuffer :: Get (lword& l, bool peek)
{
}
@@ -444,12 +429,37 @@ UchMsgBuffer :: Get (char* str, int n, const char* delim, bool peek)
*q++ = *p++;
}
*q = '\0';
+
+ /* if we reached the end of a string, flush the null character as well */
if (! peek)
- Flush (i);
+ Flush (*p ? i : i + 1);
return i;
}
/*?
+Extract a string from a buffer and copy it to a \typ{CcuString}.
+This assumes that the string in the buffer is null-terminated.
+?*/
+int
+UchMsgBuffer :: Get (CcuString& s, bool peek)
+{
+ if (GetErr)
+ return 0;
+
+ int n = Stop - Start;
+ byte* p = Start;
+ while (n-- && *p)
+ ++p;
+
+ int l = p - Start;
+
+ s.Assign ((const char*) Start, l);
+ if (! peek)
+ Flush (*p ? l : l + 1);
+ return l;
+}
+
+/*?
Get a message from the buffer.
The message must be prefixed by its length, as done by \fun{Append(UchMessage*)}.
The virtual function \fun{ReadFrom} of the message is called to convert the buffer into a message.
@@ -458,7 +468,7 @@ If \fun{ReadFrom} reads past the end of the message,
FALSE is returned and the get error flag is set.
?*/
bool
-UchMsgBuffer :: Get (UchMessage* msg)
+UchMsgBuffer :: Get (UchMessage& msg)
{
if (GetErr || (Stop - Start < lwsize))
return FALSE;
@@ -474,7 +484,7 @@ UchMsgBuffer :: Get (UchMessage* msg)
// read from buffer
Start += lwsize;
- msg->ReadFrom (*this, len);
+ msg.ReadFrom (*this, len);
// align to length
lword rl = l - (Stop - Start);
@@ -490,6 +500,7 @@ UchMsgBuffer :: Get (UchMessage* msg)
}
}
+
//------ peek operations
/*?nextdoc?*/
@@ -697,7 +708,7 @@ UchMsgBuffer :: Ok ()
/*?
Reset the error flag.
The error flag is automatically reset by the functions \fun{Append} and \fun{More},
-and by \fun{operator <<}.
+and by \fun{operator $<<$}.
?*/
void
UchMsgBuffer :: ResetError ()