File tree 6 files changed +22
-8
lines changed
6 files changed +22
-8
lines changed Original file line number Diff line number Diff line change 28
28
#include < algorithm>
29
29
#include < string>
30
30
31
+ #define MP_FORMAT_UTILS multipass::FormatUtils::instance ()
32
+
31
33
namespace multipass
32
34
{
33
35
class Formatter ;
@@ -43,8 +45,6 @@ Formatter* formatter_for(const std::string& format);
43
45
template <typename Container>
44
46
Container sorted (const Container& items);
45
47
46
- std::string convert_to_localtime (const google::protobuf::Timestamp& timestamp);
47
-
48
48
void filter_aliases (google::protobuf::RepeatedPtrField<multipass::FindReply_AliasInfo>& aliases);
49
49
50
50
// Computes the column width needed to display all the elements of a range [begin, end). get_width is a function
@@ -60,6 +60,14 @@ static constexpr auto column_width =
60
60
return std::max ({get_width (*max_width) + col_buffer, header_width + col_buffer, minimum_width});
61
61
};
62
62
} // namespace format
63
+
64
+ class FormatUtils : public Singleton <FormatUtils>
65
+ {
66
+ public:
67
+ FormatUtils (const Singleton<FormatUtils>::PrivatePass&) noexcept ;
68
+
69
+ virtual std::string convert_to_localtime (const google::protobuf::Timestamp& timestamp) const ;
70
+ };
63
71
} // namespace multipass
64
72
65
73
template <typename Container>
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ std::string generate_snapshot_details(const mp::InfoReply reply)
85
85
86
86
fmt::format_to (std::back_inserter (buf),
87
87
" ,{},{},{},\" {}\"\n " ,
88
- mp::format:: convert_to_localtime (fundamentals.creation_timestamp ()),
88
+ MP_FORMAT_UTILS. convert_to_localtime (fundamentals.creation_timestamp ()),
89
89
fundamentals.parent (),
90
90
fmt::join (info.snapshot_info ().children (), " ;" ),
91
91
fundamentals.comment ());
Original file line number Diff line number Diff line change @@ -111,7 +111,12 @@ void mp::format::filter_aliases(google::protobuf::RepeatedPtrField<multipass::Fi
111
111
}
112
112
}
113
113
114
- std::string mp::format::convert_to_localtime (const google::protobuf::Timestamp& timestamp) const
114
+ mp::FormatUtils::FormatUtils (const Singleton<FormatUtils>::PrivatePass& pass) noexcept
115
+ : Singleton<FormatUtils>::Singleton{pass}
116
+ {
117
+ }
118
+
119
+ std::string mp::FormatUtils::convert_to_localtime (const google::protobuf::Timestamp& timestamp) const
115
120
{
116
121
std::ostringstream oss;
117
122
std::time_t t = google::protobuf::util::TimeUtil::TimestampToTimeT (timestamp);
Original file line number Diff line number Diff line change @@ -76,8 +76,9 @@ QJsonObject generate_snapshot_details(const mp::DetailedInfoItem& item)
76
76
}
77
77
snapshot_info.insert (" mounts" , mounts);
78
78
79
- snapshot_info.insert (" created" ,
80
- QString::fromStdString (mp::format::convert_to_localtime (fundamentals.creation_timestamp ())));
79
+ snapshot_info.insert (
80
+ " created" ,
81
+ QString::fromStdString (MP_FORMAT_UTILS.convert_to_localtime (fundamentals.creation_timestamp ())));
81
82
snapshot_info.insert (" parent" , QString::fromStdString (fundamentals.parent ()));
82
83
83
84
QJsonArray children;
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ std::string generate_snapshot_details(const mp::DetailedInfoItem& item)
88
88
fmt::format_to (std::back_inserter (buf),
89
89
" {:<16}{}\n " ,
90
90
" Created:" ,
91
- mp::format:: convert_to_localtime (fundamentals.creation_timestamp ()));
91
+ MP_FORMAT_UTILS. convert_to_localtime (fundamentals.creation_timestamp ()));
92
92
fmt::format_to (std::back_inserter (buf),
93
93
" {:<16}{}\n " ,
94
94
" Parent:" ,
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ YAML::Node generate_snapshot_details(const mp::DetailedInfoItem& item)
78
78
}
79
79
snapshot_node[" mounts" ] = mounts;
80
80
81
- snapshot_node[" created" ] = mp::format:: convert_to_localtime (fundamentals.creation_timestamp ());
81
+ snapshot_node[" created" ] = MP_FORMAT_UTILS. convert_to_localtime (fundamentals.creation_timestamp ());
82
82
snapshot_node[" parent" ] = fundamentals.parent ().empty () ? YAML::Node () : YAML::Node (fundamentals.parent ());
83
83
84
84
snapshot_node[" children" ] = YAML::Node (YAML::NodeType::Sequence);
You can’t perform that action at this time.
0 commit comments