KiCad PCB EDA Suite
OPTIONAL_XML_ATTRIBUTE< T > Class Template Reference

Model an optional XML attribute. More...

#include <eagle_parser.h>

Public Member Functions

 OPTIONAL_XML_ATTRIBUTE ()
 Construct a default OPTIONAL_XML_ATTRIBUTE, whose data is not available. More...
 
 OPTIONAL_XML_ATTRIBUTE (const wxString &aData)
 
template<typename V = T>
 OPTIONAL_XML_ATTRIBUTE (T aData)
 
 operator bool () const
 
OPTIONAL_XML_ATTRIBUTE< T > & operator= (const wxString &aData)
 Assign to a string (optionally) containing the data. More...
 
OPTIONAL_XML_ATTRIBUTE< T > & operator= (T aData)
 Assign to an object of the base type containing the data. More...
 
bool operator== (const T &aOther) const
 
void Set (const wxString &aString)
 Attempt to convert a string to the base type. More...
 
T & Get ()
 Return a reference to the value of the attribute assuming it is available. More...
 
const T & CGet () const
 Return a constant reference to the value of the attribute assuming it is available. More...
 
T & operator * ()
 Return a reference to the value of the attribute assuming it is available. More...
 
const T & operator * () const
 Return a constant reference to the value of the attribute assuming it is available. More...
 
T * operator-> ()
 Return a pointer to the value of the attribute assuming it is available. More...
 
const T * operator-> () const
 Return a constant pointer to the value of the attribute assuming it is available. More...
 

Private Attributes

bool m_isAvailable
 A boolean indicating if the data is present or not. More...
 
m_data
 The actual data if m_isAvailable is true; otherwise, garbage. More...
 

Detailed Description

template<typename T>
class OPTIONAL_XML_ATTRIBUTE< T >

Model an optional XML attribute.

This was implemented as an alternative to OPT. This class should be replaced with a simple typedef per type using std::optional when C++17 is published.

Definition at line 188 of file eagle_parser.h.

Constructor & Destructor Documentation

◆ OPTIONAL_XML_ATTRIBUTE() [1/3]

template<typename T>
OPTIONAL_XML_ATTRIBUTE< T >::OPTIONAL_XML_ATTRIBUTE ( )
inline

Construct a default OPTIONAL_XML_ATTRIBUTE, whose data is not available.

Definition at line 201 of file eagle_parser.h.

201  :
202  m_isAvailable( false ),
203  m_data( T() )
204  {}
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:192
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:195

◆ OPTIONAL_XML_ATTRIBUTE() [2/3]

template<typename T>
OPTIONAL_XML_ATTRIBUTE< T >::OPTIONAL_XML_ATTRIBUTE ( const wxString &  aData)
inline
Parameters
aDatais a wxString containing the value that should be converted to type T. If aData is empty, the attribute is understood as unavailable; otherwise, the conversion to T is tried.

Definition at line 211 of file eagle_parser.h.

212  {
213  m_data = T();
214  m_isAvailable = !aData.IsEmpty();
215 
216  if( m_isAvailable )
217  Set( aData );
218  }
void Set(const wxString &aString)
Attempt to convert a string to the base type.
Definition: eagle_parser.h:281
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:192
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:195

◆ OPTIONAL_XML_ATTRIBUTE() [3/3]

template<typename T>
template<typename V = T>
OPTIONAL_XML_ATTRIBUTE< T >::OPTIONAL_XML_ATTRIBUTE ( aData)
inline
Parameters
aDatais the value of the XML attribute. If this constructor is called, the attribute is available.

Definition at line 225 of file eagle_parser.h.

225  :
226  m_isAvailable( true ),
227  m_data( aData )
228  {}
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:192
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:195

Member Function Documentation

◆ CGet()

template<typename T>
const T& OPTIONAL_XML_ATTRIBUTE< T >::CGet ( ) const
inline

Return a constant reference to the value of the attribute assuming it is available.

Returns
const T& - the value of the attribute.

Definition at line 303 of file eagle_parser.h.

304  {
305  assert( m_isAvailable );
306  return m_data;
307  }
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:192
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:195

Referenced by ETEXT::ConvertSize(), SCH_EAGLE_PLUGIN::loadTextAttributes(), OPTIONAL_XML_ATTRIBUTE< bool >::operator *(), and OPTIONAL_XML_ATTRIBUTE< bool >::operator->().

◆ Get()

template<typename T>
T& OPTIONAL_XML_ATTRIBUTE< T >::Get ( )
inline

Return a reference to the value of the attribute assuming it is available.

Returns
T& - the value of the attribute.

Definition at line 292 of file eagle_parser.h.

293  {
294  assert( m_isAvailable );
295  return m_data;
296  }
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:192
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:195

Referenced by SCH_EAGLE_PLUGIN::loadLibrary(), SCH_EAGLE_PLUGIN::loadPin(), OPTIONAL_XML_ATTRIBUTE< bool >::operator *(), and OPTIONAL_XML_ATTRIBUTE< bool >::operator->().

◆ operator *() [1/2]

template<typename T>
T& OPTIONAL_XML_ATTRIBUTE< T >::operator * ( )
inline

Return a reference to the value of the attribute assuming it is available.

Returns
T& - the value of the attribute.

Definition at line 314 of file eagle_parser.h.

315  {
316  return Get();
317  }
T & Get()
Return a reference to the value of the attribute assuming it is available.
Definition: eagle_parser.h:292

◆ operator *() [2/2]

template<typename T>
const T& OPTIONAL_XML_ATTRIBUTE< T >::operator * ( ) const
inline

Return a constant reference to the value of the attribute assuming it is available.

Returns
const T& - the value of the attribute.

Definition at line 324 of file eagle_parser.h.

325  {
326  return CGet();
327  }
const T & CGet() const
Return a constant reference to the value of the attribute assuming it is available.
Definition: eagle_parser.h:303

◆ operator bool()

template<typename T>
OPTIONAL_XML_ATTRIBUTE< T >::operator bool ( ) const
inline
Returns
bool the availability of the attribute.

Definition at line 233 of file eagle_parser.h.

234  {
235  return m_isAvailable;
236  }
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:192

◆ operator->() [1/2]

template<typename T>
T* OPTIONAL_XML_ATTRIBUTE< T >::operator-> ( )
inline

Return a pointer to the value of the attribute assuming it is available.

Returns
T* - the value of the attribute.

Definition at line 334 of file eagle_parser.h.

335  {
336  return &Get();
337  }
T & Get()
Return a reference to the value of the attribute assuming it is available.
Definition: eagle_parser.h:292

◆ operator->() [2/2]

template<typename T>
const T* OPTIONAL_XML_ATTRIBUTE< T >::operator-> ( ) const
inline

Return a constant pointer to the value of the attribute assuming it is available.

Returns
const T* - the value of the attribute.

Definition at line 344 of file eagle_parser.h.

345  {
346  return &CGet();
347  }
const T & CGet() const
Return a constant reference to the value of the attribute assuming it is available.
Definition: eagle_parser.h:303

◆ operator=() [1/2]

template<typename T>
OPTIONAL_XML_ATTRIBUTE<T>& OPTIONAL_XML_ATTRIBUTE< T >::operator= ( const wxString &  aData)
inline

Assign to a string (optionally) containing the data.

Parameters
aDatais a wxString that should be converted to T. If the string is empty, the attribute is set to unavailable.

Definition at line 244 of file eagle_parser.h.

245  {
246  m_isAvailable = !aData.IsEmpty();
247 
248  if( m_isAvailable )
249  Set( aData );
250 
251  return *this;
252  }
void Set(const wxString &aString)
Attempt to convert a string to the base type.
Definition: eagle_parser.h:281
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:192

◆ operator=() [2/2]

template<typename T>
OPTIONAL_XML_ATTRIBUTE<T>& OPTIONAL_XML_ATTRIBUTE< T >::operator= ( aData)
inline

Assign to an object of the base type containing the data.

Parameters
aDatais the actual value of the attribute. Calling this assignment, the attribute is automatically made available.

Definition at line 260 of file eagle_parser.h.

261  {
262  m_data = aData;
263  m_isAvailable = true;
264 
265  return *this;
266  }
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:192
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:195

◆ operator==()

template<typename T>
bool OPTIONAL_XML_ATTRIBUTE< T >::operator== ( const T &  aOther) const
inline
Parameters
aOtheris the object of the base type that should be compared with this one.

Definition at line 271 of file eagle_parser.h.

272  {
273  return m_isAvailable && ( aOther == m_data );
274  }
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:192
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:195

◆ Set()

template<typename T>
void OPTIONAL_XML_ATTRIBUTE< T >::Set ( const wxString &  aString)
inline

Attempt to convert a string to the base type.

Parameters
aStringis the string that will be converted to the base type.

Definition at line 281 of file eagle_parser.h.

282  {
283  m_data = Convert<T>( aString );
284  m_isAvailable = !aString.IsEmpty();
285  }
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:192
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:195

Referenced by OPTIONAL_XML_ATTRIBUTE< bool >::operator=(), and OPTIONAL_XML_ATTRIBUTE< bool >::OPTIONAL_XML_ATTRIBUTE().

Member Data Documentation

◆ m_data

◆ m_isAvailable


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