aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-03-14 17:49:30 +0000
committerlloyd <[email protected]>2008-03-14 17:49:30 +0000
commit1d5b656dc719f7411c96a2f416ad261bdfbca59b (patch)
tree09586fbe9d266c7273d8fc88f801240004b15bf8
parent83de95aacd2b1e82f885b62676622f2723276671 (diff)
Use a special typedef, Pipe::message_id, rather than a bare u32bit,
to represent the message number in a Pipe
-rw-r--r--include/pipe.h26
-rw-r--r--src/pipe.cpp6
-rw-r--r--src/pipe_rw.cpp16
3 files changed, 25 insertions, 23 deletions
diff --git a/include/pipe.h b/include/pipe.h
index 9bc98a72b..9bf05b76a 100644
--- a/include/pipe.h
+++ b/include/pipe.h
@@ -18,7 +18,9 @@ namespace Botan {
class Pipe : public DataSource
{
public:
- static const u32bit LAST_MESSAGE, DEFAULT_MESSAGE;
+ typedef u32bit message_id;
+
+ static const message_id LAST_MESSAGE, DEFAULT_MESSAGE;
void write(const byte[], u32bit);
void write(const MemoryRegion<byte>&);
@@ -31,21 +33,21 @@ class Pipe : public DataSource
void process_msg(const std::string&);
void process_msg(DataSource&);
- u32bit remaining(u32bit = DEFAULT_MESSAGE) const;
+ u32bit remaining(message_id = DEFAULT_MESSAGE) const;
u32bit read(byte[], u32bit);
- u32bit read(byte[], u32bit, u32bit);
- u32bit read(byte&, u32bit = DEFAULT_MESSAGE);
+ u32bit read(byte[], u32bit, message_id);
+ u32bit read(byte&, message_id = DEFAULT_MESSAGE);
- SecureVector<byte> read_all(u32bit = DEFAULT_MESSAGE);
- std::string read_all_as_string(u32bit = DEFAULT_MESSAGE);
+ SecureVector<byte> read_all(message_id = DEFAULT_MESSAGE);
+ std::string read_all_as_string(message_id = DEFAULT_MESSAGE);
u32bit peek(byte[], u32bit, u32bit) const;
- u32bit peek(byte[], u32bit, u32bit, u32bit) const;
- u32bit peek(byte&, u32bit, u32bit = DEFAULT_MESSAGE) const;
+ u32bit peek(byte[], u32bit, u32bit, message_id) const;
+ u32bit peek(byte&, u32bit, message_id = DEFAULT_MESSAGE) const;
- u32bit default_msg() const { return default_read; }
- void set_default_msg(u32bit);
+ message_id default_msg() const { return default_read; }
+ void set_default_msg(message_id);
u32bit message_count() const;
bool end_of_data() const;
@@ -68,11 +70,11 @@ class Pipe : public DataSource
void find_endpoints(Filter*);
void clear_endpoints(Filter*);
- u32bit get_message_no(const std::string&, u32bit) const;
+ message_id get_message_no(const std::string&, message_id) const;
Filter* pipe;
class Output_Buffers* outputs;
- u32bit default_read;
+ message_id default_read;
bool inside_msg;
};
diff --git a/src/pipe.cpp b/src/pipe.cpp
index f821a9ffe..a19cff258 100644
--- a/src/pipe.cpp
+++ b/src/pipe.cpp
@@ -100,7 +100,7 @@ bool Pipe::end_of_data() const
/*************************************************
* Set the default read message *
*************************************************/
-void Pipe::set_default_msg(u32bit msg)
+void Pipe::set_default_msg(message_id msg)
{
if(msg >= message_count())
throw Invalid_Argument("Pipe::set_default_msg: msg number is too high");
@@ -284,7 +284,7 @@ u32bit Pipe::message_count() const
/*************************************************
* Static Member Variables *
*************************************************/
-const u32bit Pipe::LAST_MESSAGE = 0xFFFFFFFE;
-const u32bit Pipe::DEFAULT_MESSAGE = 0xFFFFFFFF;
+const Pipe::message_id Pipe::LAST_MESSAGE = static_cast<Pipe::message_id>(-2);
+const Pipe::message_id Pipe::DEFAULT_MESSAGE = static_cast<Pipe::message_id>(-1);
}
diff --git a/src/pipe_rw.cpp b/src/pipe_rw.cpp
index 1fa195210..617129b9f 100644
--- a/src/pipe_rw.cpp
+++ b/src/pipe_rw.cpp
@@ -12,7 +12,7 @@ namespace Botan {
/*************************************************
* Look up the canonical ID for a queue *
*************************************************/
-u32bit Pipe::get_message_no(const std::string& func_name, u32bit msg) const
+Pipe::message_id Pipe::get_message_no(const std::string& func_name, message_id msg) const
{
if(msg == DEFAULT_MESSAGE)
msg = default_msg();
@@ -75,7 +75,7 @@ void Pipe::write(DataSource& source)
/*************************************************
* Read some data from the pipe *
*************************************************/
-u32bit Pipe::read(byte output[], u32bit length, u32bit msg)
+u32bit Pipe::read(byte output[], u32bit length, message_id msg)
{
return outputs->read(output, length, get_message_no("read", msg));
}
@@ -91,7 +91,7 @@ u32bit Pipe::read(byte output[], u32bit length)
/*************************************************
* Read a single byte from the pipe *
*************************************************/
-u32bit Pipe::read(byte& out, u32bit msg)
+u32bit Pipe::read(byte& out, message_id msg)
{
return read(&out, 1, msg);
}
@@ -99,7 +99,7 @@ u32bit Pipe::read(byte& out, u32bit msg)
/*************************************************
* Return all data in the pipe *
*************************************************/
-SecureVector<byte> Pipe::read_all(u32bit msg)
+SecureVector<byte> Pipe::read_all(message_id msg)
{
msg = ((msg != DEFAULT_MESSAGE) ? msg : default_msg());
SecureVector<byte> buffer(remaining(msg));
@@ -110,7 +110,7 @@ SecureVector<byte> Pipe::read_all(u32bit msg)
/*************************************************
* Return all data in the pipe as a string *
*************************************************/
-std::string Pipe::read_all_as_string(u32bit msg)
+std::string Pipe::read_all_as_string(message_id msg)
{
msg = ((msg != DEFAULT_MESSAGE) ? msg : default_msg());
SecureVector<byte> buffer(DEFAULT_BUFFERSIZE);
@@ -131,7 +131,7 @@ std::string Pipe::read_all_as_string(u32bit msg)
/*************************************************
* Find out how many bytes are ready to read *
*************************************************/
-u32bit Pipe::remaining(u32bit msg) const
+u32bit Pipe::remaining(message_id msg) const
{
return outputs->remaining(get_message_no("remaining", msg));
}
@@ -140,7 +140,7 @@ u32bit Pipe::remaining(u32bit msg) const
* Peek at some data in the pipe *
*************************************************/
u32bit Pipe::peek(byte output[], u32bit length,
- u32bit offset, u32bit msg) const
+ u32bit offset, message_id msg) const
{
return outputs->peek(output, length, offset, get_message_no("peek", msg));
}
@@ -156,7 +156,7 @@ u32bit Pipe::peek(byte output[], u32bit length, u32bit offset) const
/*************************************************
* Peek at a byte in the pipe *
*************************************************/
-u32bit Pipe::peek(byte& out, u32bit offset, u32bit msg) const
+u32bit Pipe::peek(byte& out, u32bit offset, message_id msg) const
{
return peek(&out, 1, offset, msg);
}