KiCad PCB EDA Suite
OPTIONAL_XML_ATTRIBUTE< T > Class Template Reference

Class OPTIONAL_XML_ATTRIBUTE models an optional XML attribute. More...

#include <eagle_parser.h>

Public Member Functions

 OPTIONAL_XML_ATTRIBUTE ()
 Constructor OPTIONAL_XML_ATTRIBUTE construct a default OPTIONAL_XML_ATTRIBUTE, whose data is not available. More...
 
 OPTIONAL_XML_ATTRIBUTE (const wxString &aData)
 Constructor OPTIONAL_XML_ATTRIBUTE. More...
 
template<typename V = T>
 OPTIONAL_XML_ATTRIBUTE (T aData)
 Constructor OPTIONAL_XML_ATTRIBUTE. More...
 
 operator bool () const
 Operator bool. More...
 
OPTIONAL_XML_ATTRIBUTE< T > & operator= (const wxString &aData)
 Assignment operator to a string (optionally) containing the data. More...
 
OPTIONAL_XML_ATTRIBUTE< T > & operator= (T aData)
 Assignment operator to an object of the base type containing the data. More...
 
bool operator== (const T &aOther) const
 Equal operator to an object of the base type. More...
 
void Set (const wxString &aString)
 Function Set tries to convert a string to the base type. More...
 
T & Get ()
 Function Get returns a reference to the value of the attribute assuming it is available. More...
 
const T & CGet () const
 Function CGet returns a constant reference to the value of the attribute assuming it is available. More...
 
T & operator * ()
 Operator * returns a reference to the value of the attribute assuming it is available. More...
 
const T & operator * () const
 Operator * returns a constant reference to the value of the attribute assuming it is available. More...
 
T * operator-> ()
 Operator -> returns a pointer to the value of the attribute assuming it is available. More...
 
const T * operator-> () const
 Operator -> returns 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 >

Class OPTIONAL_XML_ATTRIBUTE models 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 190 of file eagle_parser.h.

Constructor & Destructor Documentation

◆ OPTIONAL_XML_ATTRIBUTE() [1/3]

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

Constructor OPTIONAL_XML_ATTRIBUTE construct a default OPTIONAL_XML_ATTRIBUTE, whose data is not available.

Definition at line 204 of file eagle_parser.h.

204  :
205  m_isAvailable( false ),
206  m_data( T() )
207  {}
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:194
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:197

◆ OPTIONAL_XML_ATTRIBUTE() [2/3]

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

Constructor OPTIONAL_XML_ATTRIBUTE.

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 215 of file eagle_parser.h.

216  {
217  m_data = T();
218  m_isAvailable = !aData.IsEmpty();
219 
220  if( m_isAvailable )
221  Set( aData );
222  }
void Set(const wxString &aString)
Function Set tries to convert a string to the base type.
Definition: eagle_parser.h:289
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:194
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:197

◆ OPTIONAL_XML_ATTRIBUTE() [3/3]

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

Constructor OPTIONAL_XML_ATTRIBUTE.

Parameters
aDatais the value of the XML attribute. If this constructor is called, the attribute is available.

Definition at line 230 of file eagle_parser.h.

230  :
231  m_isAvailable( true ),
232  m_data( aData )
233  {}
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:194
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:197

Member Function Documentation

◆ CGet()

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

Function CGet returns a constant reference to the value of the attribute assuming it is available.

Returns
const T& - the value of the attribute.

Definition at line 311 of file eagle_parser.h.

312  {
313  assert( m_isAvailable );
314  return m_data;
315  }
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:194
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:197

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

Function Get returns a reference to the value of the attribute assuming it is available.

Returns
T& - the value of the attribute.

Definition at line 300 of file eagle_parser.h.

301  {
302  assert( m_isAvailable );
303  return m_data;
304  }
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:194
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:197

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

Operator * returns a reference to the value of the attribute assuming it is available.

Returns
T& - the value of the attribute.

Definition at line 322 of file eagle_parser.h.

323  {
324  return Get();
325  }
T & Get()
Function Get returns a reference to the value of the attribute assuming it is available.
Definition: eagle_parser.h:300

◆ operator *() [2/2]

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

Operator * returns a constant reference to the value of the attribute assuming it is available.

Returns
const T& - the value of the attribute.

Definition at line 332 of file eagle_parser.h.

333  {
334  return CGet();
335  }
const T & CGet() const
Function CGet returns a constant reference to the value of the attribute assuming it is available.
Definition: eagle_parser.h:311

◆ operator bool()

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

Operator bool.

Returns
bool - the availability of the attribute.

Definition at line 239 of file eagle_parser.h.

240  {
241  return m_isAvailable;
242  }
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:194

◆ operator->() [1/2]

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

Operator -> returns a pointer to the value of the attribute assuming it is available.

Returns
T* - the value of the attribute.

Definition at line 342 of file eagle_parser.h.

343  {
344  return &Get();
345  }
T & Get()
Function Get returns a reference to the value of the attribute assuming it is available.
Definition: eagle_parser.h:300

◆ operator->() [2/2]

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

Operator -> returns a constant pointer to the value of the attribute assuming it is available.

Returns
const T* - the value of the attribute.

Definition at line 352 of file eagle_parser.h.

353  {
354  return &CGet();
355  }
const T & CGet() const
Function CGet returns a constant reference to the value of the attribute assuming it is available.
Definition: eagle_parser.h:311

◆ operator=() [1/2]

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

Assignment operator 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 250 of file eagle_parser.h.

251  {
252  m_isAvailable = !aData.IsEmpty();
253 
254  if( m_isAvailable )
255  Set( aData );
256 
257  return *this;
258  }
void Set(const wxString &aString)
Function Set tries to convert a string to the base type.
Definition: eagle_parser.h:289
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:194

◆ operator=() [2/2]

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

Assignment operator 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 266 of file eagle_parser.h.

267  {
268  m_data = aData;
269  m_isAvailable = true;
270 
271  return *this;
272  }
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:194
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:197

◆ operator==()

template<typename T>
bool OPTIONAL_XML_ATTRIBUTE< T >::operator== ( const T &  aOther) const
inline

Equal operator to an object of the base type.

Parameters
aOtheris the object of the base type that should be compared with this one.

Definition at line 279 of file eagle_parser.h.

280  {
281  return m_isAvailable && ( aOther == m_data );
282  }
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:194
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:197

◆ Set()

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

Function Set tries to convert a string to the base type.

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

Definition at line 289 of file eagle_parser.h.

290  {
291  m_data = Convert<T>( aString );
292  m_isAvailable = !aString.IsEmpty();
293  }
bool m_isAvailable
A boolean indicating if the data is present or not.
Definition: eagle_parser.h:194
T m_data
The actual data if m_isAvailable is true; otherwise, garbage.
Definition: eagle_parser.h:197

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: