7 #include <initializer_list>
31 #define _CAPTURE_PROPERTY_CAST_DEFINITION(type_name, pascal_name, lower_name) \
32 std::optional<type_name> CaptureProperty::As##pascal_name() const { \
33 if (GetType() != Type::k##pascal_name) { \
34 return std::nullopt; \
36 return reinterpret_cast<const Capture##pascal_name##Property*>(this) \
42 #define _CAPTURE_PROPERTY_DEFINITION(type_name, pascal_name, lower_name) \
43 Capture##pascal_name##Property::Capture##pascal_name##Property( \
44 const std::string& label, type_name value, Options options) \
45 : CaptureProperty(label, options), value(std::move(value)) {} \
47 std::shared_ptr<Capture##pascal_name##Property> \
48 Capture##pascal_name##Property::Make(const std::string& label, \
49 type_name value, Options options) { \
50 auto result = std::shared_ptr<Capture##pascal_name##Property>( \
51 new Capture##pascal_name##Property(label, std::move(value), options)); \
55 CaptureProperty::Type Capture##pascal_name##Property::GetType() const { \
56 return Type::k##pascal_name; \
59 void Capture##pascal_name##Property::Invoke( \
60 const CaptureProcTable& proc_table) { \
61 proc_table.lower_name(*this); \
70 CaptureElement::CaptureElement(
const std::string& label)
71 : CaptureCursorListElement(label) {}
73 std::shared_ptr<CaptureElement> CaptureElement::Make(
const std::string& label) {
77 void CaptureElement::Rewind() {
82 bool CaptureElement::MatchesCloselyEnough(
const CaptureElement& other)
const {
83 return label == other.
label;
90 Capture::Capture() =
default;
92 #ifdef IMPELLER_ENABLE_CAPTURE
93 Capture::Capture(
const std::string& label)
95 element_->label =
label;
106 #ifdef IMPELLER_ENABLE_CAPTURE
117 #ifdef IMPELLER_ENABLE_CAPTURE
118 #define _CAPTURE_PROPERTY_RECORDER_DEFINITION(type_name, pascal_name, \
120 type_name Capture::Add##pascal_name(std::string_view label, type_name value, \
121 CaptureProperty::Options options) { \
125 FML_DCHECK(element_ != nullptr); \
127 std::string label_clone = std::string(label); \
128 auto new_value = Capture##pascal_name##Property::Make( \
129 label_clone, std::move(value), options); \
131 auto next = std::reinterpret_pointer_cast<Capture##pascal_name##Property>( \
132 element_->properties.GetNext(std::move(new_value), options.readonly)); \
134 return next->value; \
144 #ifdef IMPELLER_ENABLE_CAPTURE
147 : active_(true), allowlist_(allowlist) {}
160 std::initializer_list<std::string> allowlist) {
165 #ifdef IMPELLER_ENABLE_CAPTURE
173 #ifdef IMPELLER_ENABLE_CAPTURE
174 for (
auto& [name, capture] : documents_) {
175 capture.GetElement()->Rewind();
183 #ifdef IMPELLER_ENABLE_CAPTURE
188 if (allowlist_.has_value()) {
189 if (allowlist_->find(label) == allowlist_->end()) {
194 auto found = documents_.find(label);
195 if (found != documents_.end()) {
197 found->second.Rewind();
198 return found->second;
201 auto new_document =
Capture(label);
202 documents_.emplace(label, new_document);
210 #ifdef IMPELLER_ENABLE_CAPTURE
214 return documents_.find(label) != documents_.end();