Skip to content

Commit

Permalink
Always use std::string in C++11.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuo committed Oct 24, 2018
1 parent 91c9da0 commit 1fdee54
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 57 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ option(MUDUO_BUILD_EXAMPLES "Build Muduo examples" ON)
set(CXX_FLAGS
-g
# -DVALGRIND
# -DMUDUO_STD_STRING
-DCHECK_PTHREAD_RETURN_VALUE
-D_FILE_OFFSET_BITS=64
-Wall
Expand All @@ -28,7 +27,7 @@ set(CXX_FLAGS
-Wwrite-strings
-march=native
# -MMD
-std=c++0x
-std=c++11
-rdynamic
)
if(CMAKE_BUILD_BITS EQUAL 32)
Expand Down
1 change: 1 addition & 0 deletions examples/cdns/Resolver.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef MUDUO_EXAMPLES_CDNS_RESOLVER_H
#define MUDUO_EXAMPLES_CDNS_RESOLVER_H

#include <muduo/base/noncopyable.h>
#include <muduo/base/StringPiece.h>
#include <muduo/base/Timestamp.h>
#include <muduo/net/InetAddress.h>
Expand Down
1 change: 1 addition & 0 deletions examples/curl/Curl.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef MUDUO_EXAMPLES_CURL_CURL_H
#define MUDUO_EXAMPLES_CURL_CURL_H

#include <muduo/base/noncopyable.h>
#include <muduo/base/StringPiece.h>

#include <muduo/net/Callbacks.h>
Expand Down
1 change: 1 addition & 0 deletions examples/procmon/plot.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <muduo/base/noncopyable.h>
#include <muduo/base/Types.h>
#include <vector>
#include <stdlib.h> // ssize_t
Expand Down
1 change: 1 addition & 0 deletions examples/protobuf/codec/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef MUDUO_EXAMPLES_PROTOBUF_CODEC_DISPATCHER_H
#define MUDUO_EXAMPLES_PROTOBUF_CODEC_DISPATCHER_H

#include <muduo/base/noncopyable.h>
#include <muduo/net/Callbacks.h>

#include <google/protobuf/message.h>
Expand Down
1 change: 1 addition & 0 deletions examples/protobuf/codec/dispatcher_lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef MUDUO_EXAMPLES_PROTOBUF_CODEC_DISPATCHER_LITE_H
#define MUDUO_EXAMPLES_PROTOBUF_CODEC_DISPATCHER_LITE_H

#include <muduo/base/noncopyable.h>
#include <muduo/net/Callbacks.h>

#include <google/protobuf/message.h>
Expand Down
12 changes: 0 additions & 12 deletions muduo/base/FileUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,3 @@ template int FileUtil::ReadSmallFile::readToString(
string* content,
int64_t*, int64_t*, int64_t*);

#ifndef MUDUO_STD_STRING
template int FileUtil::readFile(StringArg filename,
int maxSize,
std::string* content,
int64_t*, int64_t*, int64_t*);

template int FileUtil::ReadSmallFile::readToString(
int maxSize,
std::string* content,
int64_t*, int64_t*, int64_t*);
#endif

1 change: 1 addition & 0 deletions muduo/base/FileUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#ifndef MUDUO_BASE_FILEUTIL_H
#define MUDUO_BASE_FILEUTIL_H

#include <muduo/base/noncopyable.h>
#include <muduo/base/StringPiece.h>
#include <sys/types.h> // for off_t

Expand Down
12 changes: 1 addition & 11 deletions muduo/base/LogStream.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#ifndef MUDUO_BASE_LOGSTREAM_H
#define MUDUO_BASE_LOGSTREAM_H

#include <muduo/base/noncopyable.h>
#include <muduo/base/StringPiece.h>
#include <muduo/base/Types.h>
#include <assert.h>
#include <string.h> // memcpy
#ifndef MUDUO_STD_STRING
#include <string>
#endif

namespace muduo
{
Expand Down Expand Up @@ -138,14 +136,6 @@ class LogStream : noncopyable
return *this;
}

#ifndef MUDUO_STD_STRING
self& operator<<(const std::string& v)
{
buffer_.append(v.c_str(), v.size());
return *this;
}
#endif

self& operator<<(const StringPiece& v)
{
buffer_.append(v.data(), v.size());
Expand Down
19 changes: 0 additions & 19 deletions muduo/base/StringPiece.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
#include <iosfwd> // for ostream forward-declaration

#include <muduo/base/Types.h>
#ifndef MUDUO_STD_STRING
#include <string>
#endif

namespace muduo
{
Expand All @@ -63,12 +60,6 @@ class StringArg // copyable
: str_(str.c_str())
{ }

#ifndef MUDUO_STD_STRING
StringArg(const std::string& str)
: str_(str.c_str())
{ }
#endif

const char* c_str() const { return str_; }

private:
Expand All @@ -93,10 +84,6 @@ class StringPiece {
length_(static_cast<int>(strlen(ptr_))) { }
StringPiece(const string& str)
: ptr_(str.data()), length_(static_cast<int>(str.size())) { }
#ifndef MUDUO_STD_STRING
StringPiece(const std::string& str)
: ptr_(str.data()), length_(static_cast<int>(str.size())) { }
#endif
StringPiece(const char* offset, int len)
: ptr_(offset), length_(len) { }

Expand Down Expand Up @@ -170,12 +157,6 @@ class StringPiece {
target->assign(ptr_, length_);
}

#ifndef MUDUO_STD_STRING
void CopyToStdString(std::string* target) const {
target->assign(ptr_, length_);
}
#endif

// Does "this" start with "x"
bool starts_with(const StringPiece& x) const {
return ((length_ >= x.length_) && (memcmp(ptr_, x.ptr_, x.length_) == 0));
Expand Down
1 change: 1 addition & 0 deletions muduo/base/TimeZone.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <muduo/base/TimeZone.h>
#include <muduo/base/noncopyable.h>
#include <muduo/base/Date.h>

#include <algorithm>
Expand Down
16 changes: 3 additions & 13 deletions muduo/base/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,25 @@

#include <stdint.h>
#include <string.h> // memset
#ifdef MUDUO_STD_STRING
#include <string>
#else // !MUDUO_STD_STRING
#include <ext/vstring.h>
#include <ext/vstring_fwd.h>
#endif

#ifndef NDEBUG
#include <assert.h>
#endif

#include <muduo/base/noncopyable.h>

///
/// The most common stuffs.
///
namespace muduo
{

using std::string;

inline void memZero(void* p, size_t n)
{
memset(p, 0, n);
}

#ifdef MUDUO_STD_STRING
using std::string;
#else // !MUDUO_STD_STRING
typedef __gnu_cxx::__sso_string string;
#endif

// Taken from google-protobuf stubs/common.h
//
// Protocol Buffers - Google's data interchange format
Expand Down
1 change: 1 addition & 0 deletions muduo/net/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#ifndef MUDUO_NET_CHANNEL_H
#define MUDUO_NET_CHANNEL_H

#include <muduo/base/noncopyable.h>
#include <muduo/base/Timestamp.h>

#include <functional>
Expand Down
1 change: 1 addition & 0 deletions muduo/net/Connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#ifndef MUDUO_NET_CONNECTOR_H
#define MUDUO_NET_CONNECTOR_H

#include <muduo/base/noncopyable.h>
#include <muduo/net/InetAddress.h>

#include <functional>
Expand Down
1 change: 1 addition & 0 deletions muduo/net/TcpConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#ifndef MUDUO_NET_TCPCONNECTION_H
#define MUDUO_NET_TCPCONNECTION_H

#include <muduo/base/noncopyable.h>
#include <muduo/base/StringPiece.h>
#include <muduo/base/Types.h>
#include <muduo/net/Callbacks.h>
Expand Down
1 change: 1 addition & 0 deletions muduo/net/protobuf/ProtobufCodecLite.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef MUDUO_NET_PROTOBUF_PROTOBUFCODECLITE_H
#define MUDUO_NET_PROTOBUF_PROTOBUFCODECLITE_H

#include <muduo/base/noncopyable.h>
#include <muduo/base/StringPiece.h>
#include <muduo/base/Timestamp.h>
#include <muduo/net/Callbacks.h>
Expand Down

0 comments on commit 1fdee54

Please sign in to comment.