summaryrefslogtreecommitdiff
path: root/cpp/demo/Ice/throughput/StringView.h
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2015-03-18 12:58:16 -0230
committerMatthew Newhook <matthew@zeroc.com>2015-03-18 12:58:16 -0230
commit9b7668c7c92cf9cb311fe444cdddb489cd2a219d (patch)
tree5016567c58c81f5654e9d01935e199c6bf4761d2 /cpp/demo/Ice/throughput/StringView.h
parentVS add-in & build updates: (diff)
downloadice-9b7668c7c92cf9cb311fe444cdddb489cd2a219d.tar.bz2
ice-9b7668c7c92cf9cb311fe444cdddb489cd2a219d.tar.xz
ice-9b7668c7c92cf9cb311fe444cdddb489cd2a219d.zip
Removed demos.
Moved demoscript to distribution.
Diffstat (limited to 'cpp/demo/Ice/throughput/StringView.h')
-rw-r--r--cpp/demo/Ice/throughput/StringView.h197
1 files changed, 0 insertions, 197 deletions
diff --git a/cpp/demo/Ice/throughput/StringView.h b/cpp/demo/Ice/throughput/StringView.h
deleted file mode 100644
index b6ab4b1c0d0..00000000000
--- a/cpp/demo/Ice/throughput/StringView.h
+++ /dev/null
@@ -1,197 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-#ifndef STRING_VIEW_H
-#define STRING_VIEW_H
-
-#include <Ice/Ice.h>
-
-namespace Util
-{
-
-//
-// A simplified version of boost::string_ref and the new
-// std::experimental::fundamentals_v1::string_view
-//
-
-class string_view
-{
-public:
-
- string_view() :
- _data(0),
- _size(0)
- {}
-
- string_view(const string_view& sv) :
- _data(sv._data),
- _size(sv._size)
- {}
-
- string_view(const std::string& s) :
- _data(s.data()),
- _size(s.length())
- {}
-
- string_view(const char* str) :
- _data(str),
- _size(strlen(str))
- {
- }
-
- string_view(const char* str, size_t len) :
- _data(str),
- _size(len)
- {}
-
- string_view& operator=(const string_view& sv)
- {
- _data = sv._data;
- _size = sv._size;
- return *this;
- }
-
- size_t size() const
- {
- return _size;
- }
-
- size_t length() const
- {
- return _size;
- }
-
- bool empty() const
- {
- return _size != 0;
- }
-
- const char* data() const
- {
- return _data;
- }
-
- void clear()
- {
- _data = 0;
- _size = 0;
- }
-
- std::string to_string() const
- {
- return std::string(_data, _size);
- }
-
- int compare(string_view str) const
- {
- if(_size == str._size)
- {
- if(_data == str._data)
- {
- return 0;
- }
- else
- {
- return strncmp(_data, str._data, _size);
- }
- }
- else if(_size < str._size)
- {
- return -1;
- }
- else
- {
- return 1;
- }
- }
-
-private:
- const char* _data;
- size_t _size;
-};
-
-inline bool
-operator==(string_view lhs, string_view rhs)
-{
- return lhs.compare(rhs) == 0;
-}
-
-inline bool
-operator!=(string_view lhs, string_view rhs)
-{
- return lhs.compare(rhs) != 0;
-}
-
-}
-
-
-namespace Ice
-{
-
-//
-// Describes how to marshal/unmarshal a Util::string_view
-// It would be the same for a string_ref or std...::string_view
-//
-
-template<>
-struct StreamableTraits<Util::string_view>
-{
- static const StreamHelperCategory helper = StreamHelperCategoryBuiltin;
- static const int minWireSize = 1;
- static const bool fixedLength = false;
-};
-
-template<>
-struct StreamHelper<Util::string_view, StreamHelperCategoryBuiltin>
-{
- template<class S> static inline void
- write(S* stream, const Util::string_view& v)
- {
-
-#ifdef STRING_VIEW_IGNORE_STRING_CONVERTER
- stream->write(v.data(), v.size(), false);
-#else
- stream->write(v.data(), v.size(), true);
-#endif
- }
-
- template<class S> static inline void
- read(S* stream, Util::string_view& v)
- {
- const char* vdata = 0;
- size_t vsize = 0;
-
-#ifdef STRING_VIEW_IGNORE_STRING_CONVERTER
- stream->read(vdata, vsize);
-#else
- std::string holder;
- stream->read(vdata, vsize, holder);
-
- // If holder is not empty, a string conversion occured, and we can't return a
- // string_view since it does not hold the memory
- if(!holder.empty())
- {
- throw Ice::MarshalException(__FILE__, __LINE__, "string conversion not supported");
- }
-#endif
-
- if(vsize > 0)
- {
- v = Util::string_view(vdata, vsize);
- }
- else
- {
- v.clear();
- }
- }
-};
-
-}
-
-#endif