family_factory.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2018 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef CARTOGRAPHER_METRICS_FAMILY_FACTORY_H_
00018 #define CARTOGRAPHER_METRICS_FAMILY_FACTORY_H_
00019 
00020 #include <memory>
00021 #include <string>
00022 
00023 #include "cartographer/metrics/counter.h"
00024 #include "cartographer/metrics/gauge.h"
00025 #include "cartographer/metrics/histogram.h"
00026 
00027 namespace cartographer {
00028 namespace metrics {
00029 
00030 template <typename MetricType>
00031 class NullFamily;
00032 
00033 template <typename MetricType>
00034 class Family {
00035  public:  // Family instance that does nothing. Safe for use in static
00036           // initializers.
00037   static Family<MetricType>* Null() {
00038     static NullFamily<MetricType> null_family;
00039     return &null_family;
00040   }
00041 
00042   virtual ~Family() = default;
00043 
00044   virtual MetricType* Add(const std::map<std::string, std::string>& labels) = 0;
00045 };
00046 
00047 template <typename MetricType>
00048 class NullFamily : public Family<MetricType> {
00049  public:
00050   MetricType* Add(const std::map<std::string, std::string>& labels) override {
00051     return MetricType::Null();
00052   }
00053 };
00054 
00055 class FamilyFactory {
00056  public:
00057   virtual ~FamilyFactory() = default;
00058 
00059   virtual Family<Counter>* NewCounterFamily(const std::string& name,
00060                                             const std::string& description) = 0;
00061   virtual Family<Gauge>* NewGaugeFamily(const std::string& name,
00062                                         const std::string& description) = 0;
00063   virtual Family<Histogram>* NewHistogramFamily(
00064       const std::string& name, const std::string& description,
00065       const Histogram::BucketBoundaries& boundaries) = 0;
00066 };
00067 
00068 }  // namespace metrics
00069 }  // namespace cartographer
00070 
00071 #endif  // CARTOGRAPHER_METRICS_FAMILY_FACTORY_H_


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:35