diff options
Diffstat (limited to 'include/grpc++')
-rw-r--r-- | include/grpc++/client_context.h | 11 | ||||
-rw-r--r-- | include/grpc++/impl/call.h | 9 | ||||
-rw-r--r-- | include/grpc++/server_context.h | 5 | ||||
-rw-r--r-- | include/grpc++/support/auth_context.h | 7 | ||||
-rw-r--r-- | include/grpc++/support/string_ref.h | 41 |
5 files changed, 40 insertions, 33 deletions
diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h index ee28f360cb..62e5260a18 100644 --- a/include/grpc++/client_context.h +++ b/include/grpc++/client_context.h @@ -45,6 +45,7 @@ #include <grpc++/support/auth_context.h> #include <grpc++/support/config.h> #include <grpc++/support/status.h> +#include <grpc++/support/string_ref.h> #include <grpc++/support/time.h> struct census_context; @@ -138,12 +139,14 @@ class ClientContext { void AddMetadata(const grpc::string& meta_key, const grpc::string& meta_value); - const std::multimap<grpc::string, grpc::string>& GetServerInitialMetadata() { + const std::multimap<grpc::string_ref, grpc::string_ref>& + GetServerInitialMetadata() { GPR_ASSERT(initial_metadata_received_); return recv_initial_metadata_; } - const std::multimap<grpc::string, grpc::string>& GetServerTrailingMetadata() { + const std::multimap<grpc::string_ref, grpc::string_ref>& + GetServerTrailingMetadata() { // TODO(yangg) check finished return trailing_metadata_; } @@ -234,8 +237,8 @@ class ClientContext { mutable std::shared_ptr<const AuthContext> auth_context_; struct census_context* census_context_; std::multimap<grpc::string, grpc::string> send_initial_metadata_; - std::multimap<grpc::string, grpc::string> recv_initial_metadata_; - std::multimap<grpc::string, grpc::string> trailing_metadata_; + std::multimap<grpc::string_ref, grpc::string_ref> recv_initial_metadata_; + std::multimap<grpc::string_ref, grpc::string_ref> trailing_metadata_; grpc_call* propagate_from_call_; PropagationOptions propagation_options_; diff --git a/include/grpc++/impl/call.h b/include/grpc++/impl/call.h index e5da6c9e2a..fca5603047 100644 --- a/include/grpc++/impl/call.h +++ b/include/grpc++/impl/call.h @@ -54,8 +54,9 @@ namespace grpc { class ByteBuffer; class Call; -void FillMetadataMap(grpc_metadata_array* arr, - std::multimap<grpc::string, grpc::string>* metadata); +void FillMetadataMap( + grpc_metadata_array* arr, + std::multimap<grpc::string_ref, grpc::string_ref>* metadata); grpc_metadata* FillMetadataArray( const std::multimap<grpc::string, grpc::string>& metadata); @@ -418,7 +419,7 @@ class CallOpRecvInitialMetadata { } private: - std::multimap<grpc::string, grpc::string>* recv_initial_metadata_; + std::multimap<grpc::string_ref, grpc::string_ref>* recv_initial_metadata_; grpc_metadata_array recv_initial_metadata_arr_; }; @@ -461,7 +462,7 @@ class CallOpClientRecvStatus { } private: - std::multimap<grpc::string, grpc::string>* recv_trailing_metadata_; + std::multimap<grpc::string_ref, grpc::string_ref>* recv_trailing_metadata_; Status* recv_status_; grpc_metadata_array recv_trailing_metadata_arr_; grpc_status_code status_code_; diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index ce3cb47a23..4b17a28047 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -41,6 +41,7 @@ #include <grpc/support/time.h> #include <grpc++/support/auth_context.h> #include <grpc++/support/config.h> +#include <grpc++/support/string_ref.h> #include <grpc++/support/time.h> struct gpr_timespec; @@ -103,7 +104,7 @@ class ServerContext { bool IsCancelled() const; - const std::multimap<grpc::string, grpc::string>& client_metadata() { + const std::multimap<grpc::string_ref, grpc::string_ref>& client_metadata() { return client_metadata_; } @@ -185,7 +186,7 @@ class ServerContext { CompletionQueue* cq_; bool sent_initial_metadata_; mutable std::shared_ptr<const AuthContext> auth_context_; - std::multimap<grpc::string, grpc::string> client_metadata_; + std::multimap<grpc::string_ref, grpc::string_ref> client_metadata_; std::multimap<grpc::string, grpc::string> initial_metadata_; std::multimap<grpc::string, grpc::string> trailing_metadata_; diff --git a/include/grpc++/support/auth_context.h b/include/grpc++/support/auth_context.h index e6b793972a..5d5f8e837d 100644 --- a/include/grpc++/support/auth_context.h +++ b/include/grpc++/support/auth_context.h @@ -38,6 +38,7 @@ #include <vector> #include <grpc++/support/config.h> +#include <grpc++/support/string_ref.h> struct grpc_auth_context; struct grpc_auth_property; @@ -46,7 +47,7 @@ struct grpc_auth_property_iterator; namespace grpc { class SecureAuthContext; -typedef std::pair<grpc::string, grpc::string> AuthProperty; +typedef std::pair<grpc::string_ref, grpc::string_ref> AuthProperty; class AuthPropertyIterator : public std::iterator<std::input_iterator_tag, const AuthProperty> { @@ -78,11 +79,11 @@ class AuthContext { // A peer identity, in general is one or more properties (in which case they // have the same name). - virtual std::vector<grpc::string> GetPeerIdentity() const = 0; + virtual std::vector<grpc::string_ref> GetPeerIdentity() const = 0; virtual grpc::string GetPeerIdentityPropertyName() const = 0; // Returns all the property values with the given name. - virtual std::vector<grpc::string> FindPropertyValues( + virtual std::vector<grpc::string_ref> FindPropertyValues( const grpc::string& name) const = 0; // Iteration over all the properties. diff --git a/include/grpc++/support/string_ref.h b/include/grpc++/support/string_ref.h index 0ec39a9b0a..2bc1fecefe 100644 --- a/include/grpc++/support/string_ref.h +++ b/include/grpc++/support/string_ref.h @@ -31,10 +31,11 @@ * */ -#ifndef GRPCXX_STRING_REF_H -#define GRPCXX_STRING_REF_H +#ifndef GRPCXX_SUPPORT_STRING_REF_H +#define GRPCXX_SUPPORT_STRING_REF_H #include <iterator> +#include <iosfwd> #include <grpc++/support/config.h> @@ -43,6 +44,8 @@ namespace grpc { // This class is a non owning reference to a string. // It should be a strict subset of the upcoming std::string_ref. See: // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3442.html +// The constexpr is dropped or replaced with const for legacy compiler +// compatibility. class string_ref { public: // types @@ -50,22 +53,22 @@ class string_ref { typedef std::reverse_iterator<const_iterator> const_reverse_iterator; // constants - static constexpr size_t npos = size_t(-1); + const static size_t npos = size_t(-1); // construct/copy. - constexpr string_ref() : data_(nullptr), length_(0) {} - constexpr string_ref(const string_ref& other) + string_ref() : data_(nullptr), length_(0) {} + string_ref(const string_ref& other) : data_(other.data_), length_(other.length_) {} string_ref& operator=(const string_ref& rhs); string_ref(const char* s); - constexpr string_ref(const char* s, size_t l) : data_(s), length_(l) {} + string_ref(const char* s, size_t l) : data_(s), length_(l) {} string_ref(const grpc::string& s) : data_(s.data()), length_(s.length()) {} // iterators - constexpr const_iterator begin() const { return data_; } - constexpr const_iterator end() const { return data_ + length_; } - constexpr const_iterator cbegin() const { return data_; } - constexpr const_iterator cend() const { return data_ + length_; } + const_iterator begin() const { return data_; } + const_iterator end() const { return data_ + length_; } + const_iterator cbegin() const { return data_; } + const_iterator cend() const { return data_ + length_; } const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } @@ -80,10 +83,10 @@ class string_ref { } // capacity - constexpr size_t size() const { return length_; } - constexpr size_t length() const { return length_; } - constexpr size_t max_size() const { return length_; } - constexpr bool empty() const { return length_ == 0; } + size_t size() const { return length_; } + size_t length() const { return length_; } + size_t max_size() const { return length_; } + bool empty() const { return length_ == 0; } // element access const char* data() const { return data_; } @@ -95,9 +98,7 @@ class string_ref { size_t find(string_ref s) const; size_t find(char c) const; - // Defined as constexpr in n3442 but C++11 constexpr semantics do not allow - // the implementation of this function to comply. - /* constrexpr */ string_ref substr(size_t pos, size_t n = npos) const; + string_ref substr(size_t pos, size_t n = npos) const; private: const char* data_; @@ -112,8 +113,8 @@ bool operator>(string_ref x, string_ref y); bool operator<=(string_ref x, string_ref y); bool operator>=(string_ref x, string_ref y); -} // namespace grpc - -#endif // GRPCXX_STRING_REF_H +std::ostream& operator<<(std::ostream& stream, const string_ref& string); +} // namespace grpc +#endif // GRPCXX_SUPPORT_STRING_REF_H |