<commit_before>/// \file ROOT/TDrawingOptsBase.hxx
/// \ingroup Gpad ROOT7
/// \author <NAME> <<EMAIL>>
/// \date 2017-09-26
/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
/// is welcome!

/*************************************************************************
 * Copyright (C) 1995-2017, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT7_TDrawingAttrs
#define ROOT7_TDrawingAttrs

#include <ROOT/TColor.hxx>

#include <RStringView.h>

#include <map>
#include <string>
#include <vector>

namespace ROOT {
namespace Experimental {
class TCanvas;
class TPadBase;
class TDrawingOptsBaseNoDefault;

namespace Internal {

template <class PRIMITIVE>
class TDrawingAttrTable;
}

/** \class TDrawingAttrName
 Allows to add sub-parts, assembling a complete name. All sub-parts are separated by '.'.
 */
class TDrawingAttrName {
   std::string fName;

public:
   TDrawingAttrName() = default;
   explicit TDrawingAttrName(std::string_view name): fName(name) {}
   TDrawingAttrName operator+(std::string_view sub) const
   {
      std::string ret(fName);
      ret += ".";
      ret += sub;
      return TDrawingAttrName(ret);
   }
   operator const std::string &() const { return fName; }
};

/** \class ROOT::Experimental::TDrawingAttrRef
 The `TCanvas` keep track of `TColor`s, integer and floating point attributes used by the drawing options,
 making them accessible from other drawing options. The index into the table of the active attributes is
 wrapped into `TDrawingAttrRef` to make them type-safe (i.e. distinct for `TColor`, `long long` and `double`).
 */

template <class PRIMITIVE>
class TDrawingAttrRef {
private:
   size_t fIdx = (size_t)-1; ///< The index in the relevant attribute table of `TCanvas`.

   /// Construct a reference given the index.
   explicit TDrawingAttrRef(size_t idx): fIdx(idx) {}

   friend class Internal::TDrawingAttrTable<PRIMITIVE>;

public:
   /// Construct an invalid reference.
   TDrawingAttrRef() = default;

   /// Construct a reference from its options object, name, and set of string options.
   /// Initialized the PRIMITIVE to the default value, as available in TDrawingOptsBase::GetDefaultCanvas().
   /// The value of this attribute will be the index in the vector of strings; the default value is parsed by
   /// finding the configured string in the vector of strings. `optStrings` will only be used if
   /// `PRIMITIVE` is `long long`.
   TDrawingAttrRef(TDrawingOptsBaseNoDefault &opts, const TDrawingAttrName& name, const PRIMITIVE &deflt,
      const std::vector<std::string_view> &optStrings = {});

   /// Get the underlying index.
   operator size_t() const { return fIdx; }

   /// Whether the reference is valid.
   explicit operator bool() const { return fIdx != (size_t)-1; }
};

extern template class TDrawingAttrRef<TColor>;
extern template class TDrawingAttrRef<long long>;
extern template class TDrawingAttrRef<double>;

namespace Internal {

template <class PRIMITIVE>
class TDrawingAttrAndUseCount {
   /// The value.
   PRIMITIVE fVal;
   /// The value's use count.
   size_t fUseCount = 1;

   /// Clear the value; use count must be 0.
   void Clear();

public:
   /// Default constructor: a default-constructed value that is unused.
   TDrawingAttrAndUseCount(): fVal(), fUseCount(0) {}<commit_msg>Use std::string instead of TDrawingAttrName.<commit_after>/// \file ROOT/TDrawingOptsBase.hxx
/// \ingroup Gpad ROOT7
/// \author <NAME> <<EMAIL>>
/// \date 2017-09-26
/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
/// is welcome!

/*************************************************************************
 * Copyright (C) 1995-2017, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT7_TDrawingAttrs
#define ROOT7_TDrawingAttrs

#include <ROOT/TColor.hxx>

#include <RStringView.h>

#include <map>
#include <string>
#include <vector>

namespace ROOT {
namespace Experimental {
class TCanvas;
class TPadBase;
class TDrawingOptsBaseNoDefault;

namespace Internal {

template <class PRIMITIVE>
class TDrawingAttrTable;
}

/** \class ROOT::Experimental::TDrawingAttrRef
 The `TCanvas` keep track of `TColor`s, integer and floating point attributes used by the drawing options,
 making them accessible from other drawing options. The index into the table of the active attributes is
 wrapped into `TDrawingAttrRef` to make them type-safe (i.e. distinct for `TColor`, `long long` and `double`).
 */

template <class PRIMITIVE>
class TDrawingAttrRef {
private:
   size_t fIdx = (size_t)-1; ///< The index in the relevant attribute table of `TCanvas`.

   /// Construct a reference given the index.
   explicit TDrawingAttrRef(size_t idx): fIdx(idx) {}

   friend class Internal::TDrawingAttrTable<PRIMITIVE>;

public:
   /// Construct an invalid reference.
   TDrawingAttrRef() = default;

   /// Construct a reference from its options object, name, default value and set of string options.
   ///
   /// Initializes the PRIMITIVE to the default value, as available in TDrawingOptsBase::GetDefaultCanvas(),
   /// or to `deflt` if no entry exists under the attribute name. The attribute name is `opts.GetName() + "." + attrName`.
   /// `optStrings` is only be used if `PRIMITIVE` is `long long`; the style setting is expected to be one of
   /// the strings, with the attribute's value the index of the string.
   TDrawingAttrRef(TDrawingOptsBaseNoDefault &opts, const std::string &attrName, const PRIMITIVE &deflt,
                   const std::vector<std::string_view> &optStrings = {});

   /// Get the underlying index.
   operator size_t() const { return fIdx; }

   /// Whether the reference is valid.
   explicit operator bool() const { return fIdx != (size_t)-1; }
};

extern template class TDrawingAttrRef<TColor>;
extern template class TDrawingAttrRef<long long>;
extern template class TDrawingAttrRef<double>;

namespace Internal {

template <class PRIMITIVE>
class TDrawingAttrAndUseCount {
   /// The value.
   PRIMITIVE fVal;
   /// The value's use count.
   size_t fUseCount = 1;

   /// Clear the value; use count must be 0.
   void Clear();

public:
   /// Default constructor: a default-constructed value that is unused.
   TDrawingAttrAndUseCount(): fVal(), fUseCount(0) {}
{'fraction_non_alphanumeric': 0.13878650411114263, 'fraction_numerical': 0.007088176920895945, 'mean_word_length': 3.2119402985074625, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2388791', 'n_tokens_mistral': 1971, 'n_tokens_neox': 1935, 'n_words': 699}