xref: /aosp_15_r20/external/pigweed/pw_bluetooth_sapphire/host/common/bounded_inspect_list_node.cc (revision 61c4878ac05f98d0ceed94b57d316916de578985)
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 #include "pw_bluetooth_sapphire/internal/host/common/bounded_inspect_list_node.h"
16 
17 #include <cpp-string/string_printf.h>
18 
19 namespace bt {
20 
AttachInspect(inspect::Node & parent,std::string name)21 void BoundedInspectListNode::AttachInspect(inspect::Node& parent,
22                                            std::string name) {
23   list_node_ = parent.CreateChild(name);
24 }
25 
CreateItem()26 BoundedInspectListNode::Item& BoundedInspectListNode::CreateItem() {
27   if (items_.size() == capacity_) {
28     items_.pop();
29   }
30 
31   std::string index = bt_lib_cpp_string::StringPrintf("%zu", next_index_);
32   next_index_++;
33 
34   items_.push({.node = list_node_.CreateChild(index)});
35   return items_.back();
36 }
37 
38 }  // namespace bt
39