root/trunk/whisperlib/net/rpc/lib/types/rpc_string.cc

Revision 7, 3.5 kB (checked in by whispercastorg, 2 years ago)

version 0.2.0

Line 
1 // Copyright (c) 2009, Whispersoft s.r.l.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Whispersoft s.r.l. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Author: Cosmin Tudorache
31
32 #include "common/io/buffer/io_memory_stream.h"
33 #include "net/rpc/lib/codec/rpc_codec.h"
34 #include "net/rpc/lib/types/rpc_string.h"
35
36 namespace rpc {
37
38 rpc::String::String()
39     : rpc::Object(), str_() {
40 }
41 rpc::String::String(const char* szStr)
42     : rpc::Object(), str_(szStr) {
43 }
44 rpc::String::String(const string& strStr)
45     : rpc::Object(), str_(strStr) {
46 }
47 rpc::String::String(const rpc::String& rpcStr)
48     : rpc::Object(), str_(rpcStr.str_) {
49 }
50 rpc::String::~String() {
51 }
52 rpc::String& rpc::String::operator=(const char* szStr) {
53   str_ = szStr;
54   return *this;
55 }
56 rpc::String& rpc::String::operator=(const string& strStr) {
57   str_ = strStr;
58   return *this;
59 }
60 rpc::String& rpc::String::operator=(const rpc::String& rpcStr) {
61   str_ = rpcStr.str_;
62   return *this;
63 }
64
65 bool rpc::String::operator==(const char* szStr) const {
66   return str_ == szStr;
67 }
68 bool rpc::String::operator==(const string& strStr) const {
69   return str_ == strStr;
70 }
71 bool rpc::String::operator==(const rpc::String& rpcStr) const {
72   return str_ == rpcStr.str_;
73 }
74
75 bool rpc::String::operator!=(const char* szStr) const {
76   return !operator==(szStr);
77 }
78 bool rpc::String::operator!=(const string& strStr) const {
79   return !operator==(strStr);
80 }
81 bool rpc::String::operator!=(const rpc::String& rpcStr) const {
82   return !operator==(rpcStr);
83 }
84
85 bool rpc::String::operator<(const rpc::String& rpcStr) const {
86   return ::strcmp(CStr(), rpcStr.CStr()) < 0;
87 }
88
89 uint32 rpc::String::Size() const {
90   return str_.size();
91 }
92
93 const string& rpc::String::StdStr() const {
94   return str_;
95 }
96 string& rpc::String::MutableStdStr() {
97   return str_;
98 }
99
100 const char* rpc::String::CStr() const {
101   return str_.c_str();
102 }
103
104 rpc::Object* rpc::String::Clone() const {
105   return new rpc::String(*this);
106 }
107
108 string rpc::String::ToString() const {
109   return string("\"") + str_ + string("\"");
110 }
111
112 void rpc::String::Encode(io::MemoryStream& result,
113                          rpc::Codec& codec) const {
114   codec.Encode(result, *this);
115 }
116 }
Note: See TracBrowser for help on using the browser.