Merge pull request #4844 from jrw972/gh-actions-flag-cleanup
[OpenDDS.git] / performance-tests / bench / builder / Common.h
blob9abcd12d477278ebae7a7fdc0c8a5e1c7161c377
1 #pragma once
3 #include "Bench_Builder_Export.h"
4 #include "BuilderC.h"
6 #include <chrono>
7 #include <ostream>
8 #include <string>
10 #define APPLY_QOS_MASK(QOS_OUT, QOS_IN, MASK, PATH, FIELD) do { \
11 if (MASK.PATH.has_ ## FIELD) { \
12 QOS_OUT.PATH.FIELD = QOS_IN.PATH.FIELD; \
13 } } while (0);
15 namespace Builder {
17 Bench_Builder_Export extern const TimeStamp ZERO;
19 Bench_Builder_Export TimeStamp get_sys_time();
21 Bench_Builder_Export TimeStamp get_hr_time();
23 Bench_Builder_Export TimeStamp from_seconds(int32_t sec);
25 Bench_Builder_Export double to_seconds_double(const TimeStamp& ts);
27 Bench_Builder_Export std::chrono::milliseconds get_duration(const TimeStamp& ts);
29 Bench_Builder_Export TimeStamp operator+(const TimeStamp& lhs, const TimeStamp& rhs);
31 Bench_Builder_Export TimeStamp operator-(const TimeStamp& lhs, const TimeStamp& rhs);
33 Bench_Builder_Export bool operator<(const TimeStamp& lhs, const TimeStamp& rhs);
35 Bench_Builder_Export bool operator<=(const TimeStamp& lhs, const TimeStamp& rhs);
37 Bench_Builder_Export bool operator==(const TimeStamp& lhs, const TimeStamp& rhs);
39 Bench_Builder_Export bool operator!=(const TimeStamp& lhs, const TimeStamp& rhs);
41 Bench_Builder_Export std::ostream& operator<<(std::ostream& out, const TimeStamp& ts);
43 /**
44 * This class is intended to provide constant-time access into a
45 * potentially-growing sequence of properties. We want the names and content of
46 * the properties to be dynamic (set by the users of the builder API), but for
47 * performance reasons it would be good to stay away from something with log-n
48 * access times (maps, etc)
50 class Bench_Builder_Export PropertyIndex {
51 public:
52 PropertyIndex();
53 PropertyIndex(PropertySeq& seq, uint32_t index);
55 const Property* operator->() const;
56 Property* operator->();
58 inline explicit operator bool() const noexcept { return seq_ != 0; }
59 inline bool operator!() const noexcept { return seq_ == 0; }
61 PropertySeq* get_seq() noexcept { return seq_; };
62 const PropertySeq* get_seq() const noexcept { return seq_; };
64 protected:
65 PropertySeq* seq_;
66 uint32_t index_;
69 class Bench_Builder_Export ConstPropertyIndex {
70 public:
71 ConstPropertyIndex();
72 ConstPropertyIndex(const PropertySeq& seq, uint32_t index);
74 const Property* operator->() const;
76 inline explicit operator bool() const noexcept { return seq_ != 0; }
77 inline bool operator!() const noexcept { return seq_ == 0; }
79 const PropertySeq* get_seq() const noexcept { return seq_; };
81 protected:
82 const PropertySeq* seq_;
83 uint32_t index_;
86 Bench_Builder_Export PropertyIndex get_or_create_property(
87 PropertySeq& seq, const std::string& name, PropertyValueKind kind);
89 Bench_Builder_Export ConstPropertyIndex get_property(
90 const PropertySeq& seq, const std::string& name, PropertyValueKind kind);
92 class Bench_Builder_Export NullStream : public std::streambuf {
93 public:
94 int overflow(int c);
97 class Bench_Builder_Export Log {
98 public:
99 static std::ostream& log();
100 static std::ostream* stream;