0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
clanguml::common::or_regex< T > Struct Template Reference

Convenience class for configuration options with regex support. More...

Detailed Description

template<typename T>
struct clanguml::common::or_regex< T >

Convenience class for configuration options with regex support.

This template class provides a convenient way of handling configuraiton options, which can be either some basic type like std::string or regex.

Template Parameters
TType of alternative to regex (e.g. std::string)

Definition at line 271 of file types.h.

#include <types.h>

Public Member Functions

 or_regex ()=default
 
 or_regex (T v)
 Constructor from alternative type.
 
 or_regex (std::regex r, std::string p)
 Constructor from regex.
 
or_regexoperator= (const T &v)
 
or_regexoperator= (const regex &v)
 
bool operator== (const T &v) const
 
template<typename Ret >
std::optional< Ret > get () const
 
std::string to_string () const
 
const std::variant< T, regex > & value () const
 
bool is_regex () const
 

Private Attributes

std::variant< T, regexvalue_
 

Constructor & Destructor Documentation

◆ or_regex() [1/3]

template<typename T >
clanguml::common::or_regex< T >::or_regex ( )
default

◆ or_regex() [2/3]

template<typename T >
clanguml::common::or_regex< T >::or_regex ( v)
inline

Constructor from alternative type.

Definition at line 277 of file types.h.

278 : value_{std::move(v)}
279 {
280 }

◆ or_regex() [3/3]

template<typename T >
clanguml::common::or_regex< T >::or_regex ( std::regex  r,
std::string  p 
)
inline

Constructor from regex.

Parameters
rParsed regular expression
pRaw regular expression pattern used for regenerating config and debugging

Definition at line 289 of file types.h.

290 : value_{regex{std::move(r), std::move(p)}}
291 {
292 }

Member Function Documentation

◆ get()

template<typename T >
template<typename Ret >
std::optional< Ret > clanguml::common::or_regex< T >::get ( ) const
inline

Definition at line 314 of file types.h.

315 {
316 if (!std::holds_alternative<Ret>(value_))
317 return std::nullopt;
318
319 return std::get<Ret>(value_);
320 }

◆ is_regex()

template<typename T >
bool clanguml::common::or_regex< T >::is_regex ( ) const
inline

Definition at line 332 of file types.h.

332{ return std::holds_alternative<regex>(value_); }

◆ operator=() [1/2]

template<typename T >
or_regex & clanguml::common::or_regex< T >::operator= ( const regex v)
inline

Definition at line 300 of file types.h.

301 {
302 value_ = v;
303 return *this;
304 }

◆ operator=() [2/2]

template<typename T >
or_regex & clanguml::common::or_regex< T >::operator= ( const T &  v)
inline

Definition at line 294 of file types.h.

295 {
296 value_ = v;
297 return *this;
298 }

◆ operator==()

template<typename T >
bool clanguml::common::or_regex< T >::operator== ( const T &  v) const
inline

Definition at line 306 of file types.h.

307 {
308 if (std::holds_alternative<regex>(value_))
309 return std::regex_match(v, std::get<regex>(value_).regexp);
310
311 return std::get<T>(value_) == v;
312 }

◆ to_string()

template<typename T >
std::string clanguml::common::or_regex< T >::to_string ( ) const
inline

Definition at line 322 of file types.h.

323 {
324 if (std::holds_alternative<regex>(value_))
325 return std::get<regex>(value_).pattern;
326
327 return clanguml::common::to_string(std::get<T>(value_));
328 }

◆ value()

template<typename T >
const std::variant< T, regex > & clanguml::common::or_regex< T >::value ( ) const
inline

Definition at line 330 of file types.h.

330{ return value_; }

Member Data Documentation

◆ value_

template<typename T >
std::variant<T, regex> clanguml::common::or_regex< T >::value_
private

Definition at line 335 of file types.h.


The documentation for this struct was generated from the following file: