Exemplo n.º 1
0
	ElementTypeT& UnknownElement::ConvertTo() {
		CastVisitor_T<ElementTypeT> castVisitor;
		m_pImp->Accept(castVisitor);
		if (castVisitor.m_pElement == 0) {
			// we're not the right type. fix it & try again
			*this = ElementTypeT();
			m_pImp->Accept(castVisitor);
		}

		return *castVisitor.m_pElement;
	}
Exemplo n.º 2
0
ElementTypeT& UnknownElement::CastTo()
{
   CastVisitor<ElementTypeT> castVisitor;
   Accept(castVisitor);

   // If this element is uninitialized, implicitly convert it to the desired type
   if (castVisitor.is_null) {
      *this = ElementTypeT();
      return *this;
   }

   // Otherwise throw an exception
   if (!castVisitor.element)
      throw Exception("Bad cast");
   return *castVisitor.element;
}