71 fContent(new Ref<ValueType>(value)) {}
75 fContent(other.fContent ? other.fContent->Clone() : 0) {}
88 std::swap(fContent, rhs.fContent);
107 return fContent ? fContent->TypeInfo() :
typeid(
void);
111 return fContent ? fContent->Address() : 0;
115 return fContent->ToString();
119 fContent->FromString(val);
130 virtual ~Placeholder() {}
132 virtual const std::type_info&
TypeInfo()
const = 0;
134 virtual Placeholder* Clone()
const = 0;
136 virtual void*
Address()
const = 0;
138 virtual std::string
ToString()
const = 0;
140 virtual void FromString(
const std::string& val) = 0;
143 template <
typename ValueType>
class Ref:
public Placeholder {
146 Ref(ValueType&
value): fRef(value) {}
148 virtual const std::type_info&
TypeInfo()
const {
149 return typeid(ValueType);
152 virtual Placeholder* Clone()
const {
153 return new Ref(fRef);
156 virtual void*
Address()
const {
157 return (
void*) (&fRef);
160 virtual std::string
ToString()
const {
161 std::stringstream ss;
166 virtual void FromString(
const std::string& val) {
167 std::stringstream ss(val);
176 Placeholder* fContent;
183 template <>
inline void G4AnyType::Ref<bool>::FromString(
const std::string& val) {
187 template <>
inline void G4AnyType::Ref<G4String>::FromString(
const std::string& val) {
188 if (val[0] ==
'"' ) fRef = val.substr(1,val.size()-2);
192 template <>
inline void G4AnyType::Ref<G4ThreeVector>::FromString(
const std::string& val) {
207 virtual const char*
what()
const throw() {
208 return "G4BadAnyCast: failed conversion using any_cast";
214 return operand && operand->
TypeInfo() ==
typeid(ValueType)
215 ? &
static_cast<G4AnyType::Ref<ValueType>*
>(operand->fContent)->fRef : 0;
G4double G4ParticleHPJENDLHEData::G4double result
G4AnyType(const G4AnyType &other)
virtual const char * what() const
const std::type_info & TypeInfo() const
static G4ThreeVector ConvertTo3Vector(const char *st)
G4AnyType(ValueType &value)
void FromString(const std::string &val)
static int operand(pchar begin, pchar end, double &result, pchar &endp, const dic_type &dictionary)
std::string ToString() const
const XML_Char int const XML_Char * value
static G4bool ConvertToBool(const char *st)
friend ValueType * any_cast(G4AnyType *)
G4AnyType & Swap(G4AnyType &rhs)
typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData
ValueType * any_cast(G4AnyType *operand)
G4AnyType & operator=(const ValueType &rhs)