1 // Copyright 2023 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 // This file contains a minimal fake implementation of Inspect to enable code to 16 // compile when Inspect is not supported. 17 18 #pragma once 19 20 #include <string> 21 22 namespace inspect { 23 24 template <typename T> 25 class Property { 26 public: 27 explicit operator bool() const { return false; } Set(const T &)28 void Set(const T& /*value*/) {} Add(T)29 void Add(T /*value*/) {} Subtract(T)30 void Subtract(T /*value*/) {} 31 }; 32 33 class StringProperty final : public Property<std::string> {}; 34 class BoolProperty final : public Property<bool> {}; 35 class IntProperty final : public Property<int64_t> {}; 36 class UintProperty final : public Property<uint64_t> {}; 37 class DoubleProperty final : public Property<double> {}; 38 39 class Node final { 40 public: 41 Node() = default; 42 43 explicit operator bool() const { return false; } 44 CreateChild(std::string_view)45 Node CreateChild(std::string_view /*name*/) { return Node(); } 46 UniqueName(const std::string &)47 std::string UniqueName(const std::string& /*prefix*/) { return ""; } 48 CreateString(std::string_view,const std::string &)49 StringProperty CreateString(std::string_view /*name*/, 50 const std::string& /*value*/) { 51 return {}; 52 } 53 54 template <typename T> CreateString(std::string_view,const std::string &,T *)55 void CreateString(std::string_view /*name*/, 56 const std::string& /*value*/, 57 T* /*list*/) {} 58 RecordString(std::string_view,const std::string &)59 void RecordString(std::string_view /*name*/, const std::string& /*value*/) {} 60 CreateBool(std::string_view,bool)61 BoolProperty CreateBool(std::string_view /*name*/, bool /*value*/) { 62 return {}; 63 } 64 RecordBool(std::string_view,bool)65 void RecordBool(std::string_view /*name*/, bool /*value*/) {} 66 CreateInt(std::string_view,int64_t)67 IntProperty CreateInt(std::string_view /*name*/, int64_t /*value*/) { 68 return {}; 69 } 70 RecordInt(std::string_view,int64_t)71 void RecordInt(std::string_view /*name*/, int64_t /*value*/) {} 72 CreateUint(std::string_view,uint64_t)73 UintProperty CreateUint(std::string_view /*name*/, uint64_t /*value*/) { 74 return {}; 75 } 76 RecordUint(std::string_view,uint64_t)77 void RecordUint(std::string_view /*name*/, uint64_t /*value*/) {} 78 CreateDouble(std::string_view,double)79 DoubleProperty CreateDouble(std::string_view /*name*/, double /*value*/) { 80 return {}; 81 } 82 RecordDouble(std::string_view,double)83 void RecordDouble(std::string_view /*name*/, double /*value*/) {} 84 }; 85 86 class Inspector final { 87 public: GetRoot()88 Node& GetRoot() { return node_; } 89 90 private: 91 Node node_; 92 }; 93 94 } // namespace inspect 95