xref: /aosp_15_r20/external/federated-compute/fcp/base/string_stream.h (revision 14675a029014e728ec732f129a32e299b2da0601)
1 #ifndef FCP_BASE_STRING_STREAM_H_
2 #define FCP_BASE_STRING_STREAM_H_
3 
4 #include <string>
5 
6 #ifndef FCP_BAREMETAL
7 static_assert(false,
8               "StringStream should be used only when building FCP in bare "
9               "metal configuration.");
10 #endif
11 
12 namespace fcp {
13 namespace internal {
14 
15 // This is a class used for building diagnostic messages with
16 // FCP_LOG and FCP_STATUS macros.
17 // The class is designed to be a simplified replacement for std::ostringstream.
18 class StringStream final {
19  public:
20   StringStream() = default;
StringStream(const std::string & str)21   explicit StringStream(const std::string& str) : str_(str) {}
22 
23   StringStream& operator<<(bool x);
24   StringStream& operator<<(int32_t x);
25   StringStream& operator<<(uint32_t x);
26   StringStream& operator<<(int64_t x);
27   StringStream& operator<<(uint64_t x);
28   StringStream& operator<<(double x);
29   StringStream& operator<<(const char* x);
30   StringStream& operator<<(const std::string& x);
31 
str()32   std::string str() const { return str_; }
33 
34  private:
35   std::string str_;
36 };
37 
38 }  // namespace internal
39 }  // namespace fcp
40 
41 #endif  // FCP_BASE_STRING_STREAM_H_
42