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