LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
decl.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
26 #ifndef LBANN_UTILS_PROTOBUF_DECL_HPP_INCLUDED
27 #define LBANN_UTILS_PROTOBUF_DECL_HPP_INCLUDED
28 
34 
35 #include <google/protobuf/any.pb.h>
36 #include <google/protobuf/message.h>
37 #include <google/protobuf/reflection.h>
38 #include <google/protobuf/repeated_field.h>
39 
40 #include <memory>
41 #include <set>
42 #include <string>
43 #include <type_traits>
44 #include <unordered_set>
45 #include <vector>
46 
47 namespace lbann {
48 namespace protobuf {
49 
51 
57 
62 
64 
65 
72 bool has_oneof(google::protobuf::Message const& msg,
73  std::string const& oneof_name);
74 
80 google::protobuf::Message const&
81 get_oneof_message(google::protobuf::Message const& msg,
82  std::string const& oneof_name);
83 
88 std::string which_oneof(google::protobuf::Message const& msg,
89  std::string const& oneof_name);
90 
92 std::string message_type(google::protobuf::Message const& msg);
93 
95 std::string message_type(google::protobuf::Any const& any);
96 
98 
99 
102 template <typename T>
103 auto as_vector(google::protobuf::Message const& msg,
104  std::string const& field_name) -> std::vector<T>;
105 
110 template <typename T>
111 auto as_vector(google::protobuf::RepeatedField<T> const&) -> std::vector<T>;
112 
117 template <typename T>
118 auto as_vector(google::protobuf::RepeatedPtrField<T> const&) -> std::vector<T>;
119 
127 template <typename OutT, typename InT>
128 auto to_vector(google::protobuf::RepeatedField<InT> const& rf)
129  -> std::vector<OutT>;
130 
132 template <typename T>
133 auto as_set(google::protobuf::Message const& msg, std::string const& field_name)
134  -> std::set<T>;
135 
140 template <typename T>
141 auto as_set(google::protobuf::RepeatedField<T> const&) -> std::set<T>;
142 
147 auto as_set(google::protobuf::RepeatedPtrField<std::string> const&)
148  -> std::set<std::string>;
149 
154 template <typename OutT, typename InT>
155 auto to_set(google::protobuf::RepeatedField<InT> const&) -> std::set<OutT>;
156 
158 template <typename T>
159 auto as_unordered_set(google::protobuf::Message const& msg,
160  std::string const& field_name) -> std::unordered_set<T>;
161 
166 template <typename T>
167 auto as_unordered_set(google::protobuf::RepeatedField<T> const&)
168  -> std::unordered_set<T>;
169 
174 auto as_unordered_set(google::protobuf::RepeatedPtrField<std::string> const&)
175  -> std::unordered_set<std::string>;
176 
181 template <typename OutT, typename InT>
182 auto to_unordered_set(google::protobuf::RepeatedField<InT> const&)
183  -> std::unordered_set<OutT>;
184 
186 
187 
190 void fill(std::istream& is, google::protobuf::Message& msg);
191 
193 void fill(std::string const& pbuf_str, google::protobuf::Message& msg);
194 
196 void load(std::string const& pbuf_filename, google::protobuf::Message& msg);
197 
199 void serialize(std::ostream& os, google::protobuf::Message const& msg);
200 
202 std::string serialize(google::protobuf::Message const& msg);
203 
205 void serialize(std::string const& pbuf_filename,
206  google::protobuf::Message const& msg);
207 
209 
210 
213 template <typename T, typename ContainerT>
214 void assign_to_repeated(google::protobuf::RepeatedField<T>& field,
215  ContainerT const& values);
219 template <typename ContainerT>
220 std::string to_space_sep_string(ContainerT const& values);
221 
223 
224 namespace text {
226 
229 void fill(std::istream& is, google::protobuf::Message& msg);
230 
232 void fill(std::string const& str, google::protobuf::Message& msg);
233 
235 void load(std::string const& ptext_filename, google::protobuf::Message& msg);
236 
238 void write(std::ostream& os, google::protobuf::Message const& msg);
239 
241 std::string write(google::protobuf::Message const& msg);
242 
244 void write(std::string const& ptext_filename,
245  google::protobuf::Message const& msg);
247 } // namespace text
248 } // namespace protobuf
249 } // namespace lbann
250 
251 #endif // LBANN_UTILS_PROTOBUF_DECL_HPP_INCLUDED
void fill(std::istream &is, google::protobuf::Message &msg)
Fill the protobuf message from a binary stream.
google::protobuf::uint8 uint8
Definition: decl.hpp:58
void write(std::ostream &os, google::protobuf::Message const &msg)
Write the protobuf message in prototext in a stream.
void serialize(std::ostream &os, google::protobuf::Message const &msg)
Serialize the protobuf message to a stream.
google::protobuf::int32 int32
Definition: decl.hpp:55
auto as_unordered_set(google::protobuf::Message const &msg, std::string const &field_name) -> std::unordered_set< T >
Extract the values from the named field as an unordered_set.
Definition: impl.hpp:213
void load(std::string const &pbuf_filename, google::protobuf::Message &msg)
Fill the protobuf message from a binary file.
auto to_vector(google::protobuf::RepeatedField< InT > const &rf) -> std::vector< OutT >
Convert the repeated field to an STL vector of given type.
Definition: impl.hpp:174
void load(std::string const &ptext_filename, google::protobuf::Message &msg)
Fill the protobuf message from prototext in a file.
google::protobuf::uint16 uint16
Definition: decl.hpp:59
std::string to_space_sep_string(ContainerT const &values)
Concatenate a container of strings into a single string. Elements are space separated.
Definition: impl.hpp:140
auto to_set(google::protobuf::RepeatedField< InT > const &) -> std::set< OutT >
Convert the repeated field to an STL set of given type.
Definition: impl.hpp:206
void assign_to_repeated(google::protobuf::RepeatedField< T > &field, ContainerT const &values)
Assign a range of values to a repeated protobuf field.
Definition: impl.hpp:125
google::protobuf::int64 int64
Definition: decl.hpp:56
void fill(std::istream &is, google::protobuf::Message &msg)
Fill the protobuf message from prototext in a stream.
google::protobuf::uint32 uint32
Definition: decl.hpp:60
auto as_set(google::protobuf::Message const &msg, std::string const &field_name) -> std::set< T >
Extract the values from the named field as a set.
Definition: impl.hpp:181
google::protobuf::uint64 uint64
Definition: decl.hpp:61
google::protobuf::int16 int16
Definition: decl.hpp:54
bool has_oneof(google::protobuf::Message const &msg, std::string const &oneof_name)
Test whether the message has a oneof field with the given name.
google::protobuf::int8 int8
Definition: decl.hpp:53
auto to_unordered_set(google::protobuf::RepeatedField< InT > const &) -> std::unordered_set< OutT >
Convert the repeated field to an STL unordered_set of given type.
Definition: impl.hpp:239
google::protobuf::Message const & get_oneof_message(google::protobuf::Message const &msg, std::string const &oneof_name)
Get a message in a oneof from the given message.
std::string which_oneof(google::protobuf::Message const &msg, std::string const &oneof_name)
Get the name of the set field in the named oneof.
std::string message_type(google::protobuf::Message const &msg)
Get the name of the message type as a string.
auto as_vector(google::protobuf::Message const &msg, std::string const &field_name) -> std::vector< T >
Extract the values from the named field as a vector.
Definition: impl.hpp:152