LLVM API Documentation

Public Member Functions
llvm::StringSwitch< T, R > Class Template Reference

A switch()-like statement whose cases are string literals. More...

#include <StringSwitch.h>

List of all members.

Public Member Functions

 StringSwitch (StringRef S)
template<unsigned N>
StringSwitchCase (const char(&S)[N], const T &Value)
template<unsigned N>
StringSwitchEndsWith (const char(&S)[N], const T &Value)
template<unsigned N>
StringSwitchStartsWith (const char(&S)[N], const T &Value)
template<unsigned N0, unsigned N1>
StringSwitchCases (const char(&S0)[N0], const char(&S1)[N1], const T &Value)
template<unsigned N0, unsigned N1, unsigned N2>
StringSwitchCases (const char(&S0)[N0], const char(&S1)[N1], const char(&S2)[N2], const T &Value)
template<unsigned N0, unsigned N1, unsigned N2, unsigned N3>
StringSwitchCases (const char(&S0)[N0], const char(&S1)[N1], const char(&S2)[N2], const char(&S3)[N3], const T &Value)
template<unsigned N0, unsigned N1, unsigned N2, unsigned N3, unsigned N4>
StringSwitchCases (const char(&S0)[N0], const char(&S1)[N1], const char(&S2)[N2], const char(&S3)[N3], const char(&S4)[N4], const T &Value)
Default (const T &Value) const
 operator R () const

Detailed Description

template<typename T, typename R = T>
class llvm::StringSwitch< T, R >

A switch()-like statement whose cases are string literals.

The StringSwitch class is a simple form of a switch() statement that determines whether the given string matches one of the given string literals. The template type parameter T is the type of the value that will be returned from the string-switch expression. For example, the following code switches on the name of a color in argv[i]:

 Color color = StringSwitch<Color>(argv[i])
   .Case("red", Red)
   .Case("orange", Orange)
   .Case("yellow", Yellow)
   .Case("green", Green)
   .Case("blue", Blue)
   .Case("indigo", Indigo)
   .Cases("violet", "purple", Violet)
   .Default(UnknownColor);

Definition at line 42 of file StringSwitch.h.


Constructor & Destructor Documentation

template<typename T , typename R = T>
llvm::StringSwitch< T, R >::StringSwitch ( StringRef  S) [inline, explicit]

Definition at line 51 of file StringSwitch.h.


Member Function Documentation

template<typename T , typename R = T>
template<unsigned N>
StringSwitch& llvm::StringSwitch< T, R >::Case ( const char(&)  S[N],
const T Value 
) [inline]
template<typename T , typename R = T>
template<unsigned N0, unsigned N1>
StringSwitch& llvm::StringSwitch< T, R >::Cases ( const char(&)  S0[N0],
const char(&)  S1[N1],
const T Value 
) [inline]
template<typename T , typename R = T>
template<unsigned N0, unsigned N1, unsigned N2>
StringSwitch& llvm::StringSwitch< T, R >::Cases ( const char(&)  S0[N0],
const char(&)  S1[N1],
const char(&)  S2[N2],
const T Value 
) [inline]

Definition at line 91 of file StringSwitch.h.

References llvm::StringSwitch< T, R >::Case().

template<typename T , typename R = T>
template<unsigned N0, unsigned N1, unsigned N2, unsigned N3>
StringSwitch& llvm::StringSwitch< T, R >::Cases ( const char(&)  S0[N0],
const char(&)  S1[N1],
const char(&)  S2[N2],
const char(&)  S3[N3],
const T Value 
) [inline]

Definition at line 97 of file StringSwitch.h.

References llvm::StringSwitch< T, R >::Case().

template<typename T , typename R = T>
template<unsigned N0, unsigned N1, unsigned N2, unsigned N3, unsigned N4>
StringSwitch& llvm::StringSwitch< T, R >::Cases ( const char(&)  S0[N0],
const char(&)  S1[N1],
const char(&)  S2[N2],
const char(&)  S3[N3],
const char(&)  S4[N4],
const T Value 
) [inline]

Definition at line 104 of file StringSwitch.h.

References llvm::StringSwitch< T, R >::Case().

template<typename T , typename R = T>
R llvm::StringSwitch< T, R >::Default ( const T Value) const [inline]
template<typename T , typename R = T>
template<unsigned N>
StringSwitch& llvm::StringSwitch< T, R >::EndsWith ( const char(&)  S[N],
const T Value 
) [inline]

Definition at line 65 of file StringSwitch.h.

References llvm::StringRef::data(), llvm::LibFunc::memcmp, and llvm::StringRef::size().

Referenced by parseFormat(), and parseSubArch().

template<typename T , typename R = T>
llvm::StringSwitch< T, R >::operator R ( ) const [inline]

Definition at line 118 of file StringSwitch.h.

template<typename T , typename R = T>
template<unsigned N>
StringSwitch& llvm::StringSwitch< T, R >::StartsWith ( const char(&)  S[N],
const T Value 
) [inline]

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