68 template <
typename ValueType>
G4AnyType(ValueType &value):
69 fContent(new Ref<ValueType>(value)) {}
73 fContent(other.fContent ? other.fContent->Clone() : 0) {}
86 std::swap(fContent, rhs.fContent);
105 return fContent ? fContent->TypeInfo() :
typeid(void);
109 return fContent ? fContent->Address() : 0;
113 return fContent->ToString();
117 fContent->FromString(val);
128 virtual ~Placeholder() {}
130 virtual const std::type_info& TypeInfo()
const = 0;
132 virtual Placeholder* Clone()
const = 0;
134 virtual void* Address()
const = 0;
136 virtual std::string ToString()
const = 0;
138 virtual void FromString(
const std::string& val) = 0;
141 template <
typename ValueType>
class Ref:
public Placeholder {
144 Ref(ValueType& value): fRef(value) {}
146 virtual const std::type_info& TypeInfo()
const {
147 return typeid(ValueType);
150 virtual Placeholder* Clone()
const {
151 return new Ref(fRef);
154 virtual void* Address()
const {
155 return (
void*) (&fRef);
158 virtual std::string ToString()
const {
164 virtual void FromString(
const std::string& val) {
165 std::stringstream s(val);
174 Placeholder* fContent;
181template<>
void G4AnyType::Ref<bool>::FromString(
const std::string& val);
182template<>
void G4AnyType::Ref<G4String>::FromString(
const std::string& val);
183template<>
void G4AnyType::Ref<CLHEP::Hep3Vector>::FromString(
const std::string& val);
195 virtual const char*
what()
const throw() {
196 return "G4BadAnyCast: failed conversion using any_cast";
202 return operand && operand->
TypeInfo() ==
typeid(ValueType)
203 ? &
static_cast<G4AnyType::Ref<ValueType>*
>(operand->fContent)->fRef : 0;
207 return any_cast<ValueType>(
const_cast<G4AnyType*
>(operand));
211 const ValueType* result = any_cast<ValueType>(&operand);
ValueType * any_cast(G4AnyType *operand)
void FromString(const std::string &val)
G4AnyType & Swap(G4AnyType &rhs)
G4AnyType(ValueType &value)
const std::type_info & TypeInfo() const
friend ValueType * any_cast(G4AnyType *)
G4AnyType & operator=(const ValueType &rhs)
G4AnyType(const G4AnyType &other)
std::string ToString() const
virtual const char * what() const