mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-01 06:52:46 +01:00
Add checkNull and documentation
This commit is contained in:
parent
4dc1d2f62d
commit
a46ef4144e
@ -29,42 +29,62 @@ namespace Poco {
|
||||
namespace Redis {
|
||||
|
||||
class Redis_API Array
|
||||
/// Represents a Redis Array.
|
||||
/// Represents a Redis Array. An Array can contain Integers, Strings,
|
||||
/// Bulk Strings, Errors and other arrays. It can also contain a Null
|
||||
/// value.
|
||||
{
|
||||
public:
|
||||
Array();
|
||||
/// Default constructor. As long as there are no elements added,
|
||||
/// the array will contain a Null value.
|
||||
|
||||
Array(const Array& copy);
|
||||
/// Copy constructor.
|
||||
|
||||
virtual ~Array();
|
||||
/// Destructor.
|
||||
|
||||
void add(Poco::Int64 value);
|
||||
/// Adds an integer element.
|
||||
|
||||
void add(const std::string& value);
|
||||
/// Adds a simple string element (can't contain a newline!).
|
||||
|
||||
void add(const BulkString& value);
|
||||
/// Adds a bulk string element.
|
||||
|
||||
void add();
|
||||
/// Adds a Null bulk string element.
|
||||
|
||||
void add(RedisType::Ptr value);
|
||||
/// Adds a Redis element.
|
||||
|
||||
std::vector<RedisType::Ptr>::const_iterator begin() const;
|
||||
/// Returns an iterator to the start of the array. Note:
|
||||
/// this can throw a NullValueException when this is a Null array.
|
||||
|
||||
void clear();
|
||||
|
||||
std::vector<RedisType::Ptr>::const_iterator end() const;
|
||||
/// Returns an iterator to the end of the array. Note:
|
||||
/// this can throw a NullValueException when this is a Null array.
|
||||
|
||||
bool isNull() const;
|
||||
/// Returns true when this is a Null array.
|
||||
|
||||
std::string toString() const;
|
||||
/// Returns the String representation as specified in the
|
||||
/// Redis Protocol specification.
|
||||
|
||||
size_t size() const;
|
||||
/// Returns the size of the array. Note:
|
||||
/// this can throw a NullValueException when this is a Null array.
|
||||
|
||||
private:
|
||||
|
||||
Nullable<std::vector<RedisType::Ptr> > _elements;
|
||||
|
||||
static std::vector<RedisType::Ptr> _empty;
|
||||
void checkNull();
|
||||
};
|
||||
|
||||
inline std::vector<RedisType::Ptr>::const_iterator Array::begin() const
|
||||
@ -72,6 +92,12 @@ inline std::vector<RedisType::Ptr>::const_iterator Array::begin() const
|
||||
return _elements.value().begin();
|
||||
}
|
||||
|
||||
inline void Array::checkNull()
|
||||
{
|
||||
std::vector<RedisType::Ptr> v;
|
||||
if ( _elements.isNull() ) _elements.assign(v);
|
||||
}
|
||||
|
||||
inline void Array::clear()
|
||||
{
|
||||
if ( !_elements.isNull() )
|
||||
|
@ -20,8 +20,6 @@
|
||||
namespace Poco {
|
||||
namespace Redis {
|
||||
|
||||
std::vector<RedisType::Ptr> Array::_empty;
|
||||
|
||||
|
||||
Array::Array()
|
||||
{
|
||||
@ -39,14 +37,14 @@ Array::~Array()
|
||||
|
||||
void Array::add(Int64 value)
|
||||
{
|
||||
if ( _elements.isNull() ) _elements.assign(_empty);
|
||||
checkNull();
|
||||
|
||||
_elements.value().push_back(new Type<Int64>(value));
|
||||
}
|
||||
|
||||
void Array::add(const std::string& value)
|
||||
{
|
||||
if ( _elements.isNull() ) _elements.assign(_empty);
|
||||
checkNull();
|
||||
|
||||
BulkString rs(value);
|
||||
_elements.value().push_back(new Type<BulkString>(rs));
|
||||
@ -54,14 +52,14 @@ void Array::add(const std::string& value)
|
||||
|
||||
void Array::add(const BulkString& value)
|
||||
{
|
||||
if ( _elements.isNull() ) _elements.assign(_empty);
|
||||
checkNull();
|
||||
|
||||
_elements.value().push_back(new Type<BulkString>(value));
|
||||
}
|
||||
|
||||
void Array::add()
|
||||
{
|
||||
if ( _elements.isNull() ) _elements.assign(_empty);
|
||||
checkNull();
|
||||
|
||||
BulkString value;
|
||||
_elements.value().push_back(new Type<BulkString>(value));
|
||||
|
Loading…
x
Reference in New Issue
Block a user