Program Listing for File instrumentation_library.h

Return to documentation for file (/home/docs/checkouts/readthedocs.org/user_builds/opentelemetry-cpp/checkouts/v1.0.0/sdk/include/opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h)

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE

namespace sdk
{
namespace instrumentationlibrary
{

class InstrumentationLibrary
{
public:
  InstrumentationLibrary(const InstrumentationLibrary &) = default;

  static nostd::unique_ptr<InstrumentationLibrary> Create(nostd::string_view name,
                                                          nostd::string_view version = "")
  {
    return nostd::unique_ptr<InstrumentationLibrary>(
        new InstrumentationLibrary{std::string{name}, std::string{version}});
  }

  bool operator==(const InstrumentationLibrary &other) const
  {
    return equal(other.name_, other.version_);
  }

  bool equal(const nostd::string_view name, const nostd::string_view version) const
  {
    return this->name_ == name && this->version_ == version;
  }

  const std::string &GetName() const { return name_; }
  const std::string &GetVersion() const { return version_; }

private:
  InstrumentationLibrary(nostd::string_view name, nostd::string_view version)
      : name_(name), version_(version)
  {}

private:
  std::string name_;
  std::string version_;
};

}  // namespace instrumentationlibrary
}  // namespace sdk

OPENTELEMETRY_END_NAMESPACE