72 template <
typename ValueType>
74 : fContent(new Ref<ValueType>(value))
80 : fContent(other.fContent ? other.fContent->Clone() : 0)
89 operator bool() {
return !
Empty(); }
95 std::swap(fContent, rhs.fContent);
99 template <
typename ValueType>
118 return fContent ? fContent->TypeInfo() :
typeid(void);
123 void*
Address()
const {
return fContent ? fContent->Address() : 0; }
127 std::string
ToString()
const {
return fContent->ToString(); }
129 void FromString(
const std::string& val) { fContent->FromString(val); }
139 virtual ~Placeholder() {}
143 virtual const std::type_info& TypeInfo()
const = 0;
145 virtual Placeholder* Clone()
const = 0;
147 virtual void* Address()
const = 0;
151 virtual std::string ToString()
const = 0;
155 virtual void FromString(
const std::string& val) = 0;
158 template <
typename ValueType>
159 class Ref :
public Placeholder
165 Ref(ValueType& value)
171 virtual const std::type_info& TypeInfo()
const
173 return typeid(ValueType);
178 virtual Placeholder* Clone()
const {
return new Ref(fRef); }
182 virtual void* Address()
const {
return (
void*) (&fRef); }
186 virtual std::string ToString()
const
188 std::stringstream ss;
195 virtual void FromString(
const std::string& val)
197 std::stringstream ss(val);
206 template <
typename ValueType>
209 Placeholder* fContent =
nullptr;
217inline void G4AnyType::Ref<bool>::FromString(
const std::string& val)
223inline void G4AnyType::Ref<G4String>::FromString(
const std::string& val)
226 fRef = val.substr(1, val.size() - 2);
232inline void G4AnyType::Ref<G4ThreeVector>::FromString(
const std::string& val)
247 virtual const char*
what()
const throw()
249 return "G4BadAnyCast: failed conversion using any_cast";
255template <
typename ValueType>
258 return operand && operand->
TypeInfo() ==
typeid(ValueType)
259 ? &
static_cast<G4AnyType::Ref<ValueType>*
>(operand->fContent)->fRef
263template <
typename ValueType>
266 return any_cast<ValueType>(
const_cast<G4AnyType*
>(operand));
269template <
typename ValueType>
272 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)
G4AnyType & operator=(const G4AnyType &rhs)
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
static G4ThreeVector ConvertTo3Vector(const char *st)
static G4bool ConvertToBool(const char *st)