Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: mojo/public/cpp/bindings/string_traits.h

Issue 1968623002: Mojo C++ bindings: expose public <struct>DataView and StringDataView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@25_totally_new
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_H_
7 7
8 #include "base/logging.h"
9 #include "mojo/public/cpp/bindings/lib/array_internal.h"
10
8 namespace mojo { 11 namespace mojo {
9 12
13 // Access to a string inside a mojo message.
14 class StringDataView {
15 public:
16 explicit StringDataView(internal::String_Data* data) : data_(data) {}
17
18 // Whether the data represents a null string.
19 // Note: Must not access the following methods if this method returns true.
20 bool is_null() const { return !data_; }
21
22 const char* storage() const {
23 DCHECK(!is_null());
24 return data_->storage();
25 }
26
27 size_t size() const {
28 DCHECK(!is_null());
29 return data_->size();
30 }
31
32 private:
33 internal::String_Data* data_;
34 };
35
10 // This must be specialized for any UserType to be serialized/deserialized as 36 // This must be specialized for any UserType to be serialized/deserialized as
11 // a mojom string. 37 // a mojom string.
12 // 38 //
13 // TODO(yzshen): This is work in progress. Add better documentation once the 39 // TODO(yzshen): This is work in progress. Add better documentation once the
14 // interface becomes more stable. 40 // interface becomes more stable.
15 template <typename UserType> 41 template <typename UserType>
16 struct StringTraits; 42 struct StringTraits;
17 43
18 } // namespace mojo 44 } // namespace mojo
19 45
20 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_H_ 46 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/string_traits_wtf.cc ('k') | mojo/public/cpp/bindings/string_traits_standard.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698