libutil++  1.9.3
 All Classes Functions Variables
Null.cpp
1 /*
2 ** libutil++
3 ** $Id: Null.cpp 1702 2016-08-13 23:26:06Z sella $
4 ** Copyright (c) 2011-2016 Digital Genesis, LLC. All Rights Reserved.
5 ** Released under the LGPL Version 2.1 License.
6 ** http://www.digitalgenesis.com
7 */
8 
9 static const char rcsid[] __attribute__((used)) = "$Id: Null.cpp 1702 2016-08-13 23:26:06Z sella $";
10 
11 #include "Null.h"
12 #include "../util/CommonMacro.h"
13 
14 using namespace sella::variant;
15 
16 Null::Null() throw () : Nullable() { }
17 
18 Null::Null(const Null &other) throw () : Nullable() { }
19 
20 Null& Null::operator=(const Null &other) throw () {
21  return *this;
22 }
23 
24 Null::~Null() throw () { }
25 
26 void Null::msgpack(sella::util::MessagePack &mpack, uint32_t &offset) const throw (TypeCastException) {
27  uint32_t c;
28 
29  c = mpack.append(offset);
30 
31  offset += c;
32 
33  if (UNLIKELY(c == 0)) {
34  THROW(TypeCastException, "Failed to append null at offset %d (buffer length: %d)", offset, mpack.length());
35  }
36 }
37 
38 void Null::msgpackBufferSize(size_t &size) const throw () {
39  size += 1;
40 }
41 
42 std::string Null::str(int type) const throw () {
43  std::string output;
44 
45  switch (type) {
46  case JSON:
47  case CJSON:
48  output = "null";
49  break;
50 
51  case XML:
52  output = "<root null=\"true\" />";
53  break;
54 
55  case CSV:
56  output = "\\N";
57  break;
58  }
59 
60  return output;
61 }
62 
63 bool Null::isType(const char *value, size_t size) throw () {
64  return (size == 4 && strncmp(value, "null", size) == 0);
65 }
66 
67 /*
68 ** vim: noet ts=3 sw=3
69 */