71 template <
typename ValueType>
73 : fContent(new Ref<ValueType>(value))
79 : fContent(other.fContent != nullptr ? other.fContent->Clone() : nullptr)
88 operator bool() {
return !
Empty(); }
94 std::swap(fContent, rhs.fContent);
98 template <
typename ValueType>
117 return fContent !=
nullptr ? fContent->TypeInfo() :
typeid(void);
123 return fContent !=
nullptr ? fContent->Address() :
nullptr;
128 std::string
ToString()
const {
return fContent->ToString(); }
130 void FromString(
const std::string& val) { fContent->FromString(val); }
137 Placeholder() =
default;
139 virtual ~Placeholder() =
default;
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 const std::type_info& TypeInfo()
const override
173 return typeid(ValueType);
178 Placeholder* Clone()
const override {
return new Ref(fRef); }
182 void* Address()
const override {
return (
void*) (&fRef); }
186 std::string
ToString()
const override
188 std::stringstream ss;
195 void FromString(
const std::string& val)
override
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)
227 fRef = val.substr(1, val.size() - 2);
236inline void G4AnyType::Ref<G4ThreeVector>::FromString(
const std::string& val)
250 const char*
what()
const throw()
override
252 return "G4BadAnyCast: failed conversion using any_cast";
258template <
typename ValueType>
261 return operand && operand->
TypeInfo() ==
typeid(ValueType)
262 ? &
static_cast<G4AnyType::Ref<ValueType>*
>(operand->fContent)->fRef
266template <
typename ValueType>
269 return any_cast<ValueType>(
const_cast<G4AnyType*
>(operand));
272template <
typename ValueType>
275 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
const char * what() const override
static G4ThreeVector ConvertTo3Vector(const char *st)
static G4bool ConvertToBool(const char *st)
std::string ToString(const T &value)