Files
yoga/yoga/instrumentation.h
David Aurelio 58f0cca7c7 Add MarkerSection
Summary:
@public

Adds a class for triggering markers.

This calls `startMarker()` on construction, and `endMarker()` on destruction, thus being usable like a "scope guard": the object is instantiated, and automatically destroyed when going out of scope.

Reviewed By: SidharthGuglani

Differential Revision: D13817589

fbshipit-source-id: fd88884af970c1c0933d9ca6843f3f8f5d28b9e6
2019-01-29 11:42:36 -08:00

45 lines
1.2 KiB
C++

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*/
#include "YGConfig.h"
#include "YGMarker.h"
#include "YGNode.h"
namespace facebook {
namespace yoga {
namespace marker {
template <YGMarker MarkerType>
class MarkerSection {
public:
MarkerSection(YGNodeRef node) : MarkerSection{node, node->getConfig()} {}
~MarkerSection() {
if (endMarker_) {
endMarker_(MarkerType, node_, {&data}, userData_);
}
}
typename detail::MarkerData<MarkerType>::type data = {};
private:
decltype(YGMarkerCallbacks{}.endMarker) endMarker_;
YGNodeRef node_;
void* userData_;
MarkerSection(YGNodeRef node, YGConfigRef config)
: MarkerSection{node, config ? &config->markerCallbacks : nullptr} {}
MarkerSection(YGNodeRef node, YGMarkerCallbacks* callbacks)
: endMarker_{callbacks ? callbacks->endMarker : nullptr},
node_{node},
userData_{callbacks && callbacks->startMarker
? callbacks->startMarker(MarkerType, node, {&data})
: nullptr} {}
};
} // namespace marker
} // namespace yoga
} // namespace facebook