mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 02:53:10 +01:00
added DynamicAny::convert<>()
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
//
|
||||
// DynamicAny.h
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/include/Poco/DynamicAny.h#4 $
|
||||
// $Id: //poco/Main/Foundation/include/Poco/DynamicAny.h#6 $
|
||||
//
|
||||
// Library: Poco
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: DynamicAny
|
||||
//
|
||||
@@ -36,11 +36,11 @@
|
||||
//
|
||||
|
||||
|
||||
#ifndef Poco_DynamicAny_INCLUDED
|
||||
#define Poco_DynamicAny_INCLUDED
|
||||
#ifndef Foundation_DynamicAny_INCLUDED
|
||||
#define Foundation_DynamicAny_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Poco.h"
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/DynamicAnyHolder.h"
|
||||
#include <typeinfo>
|
||||
|
||||
@@ -146,6 +146,21 @@ public:
|
||||
_pHolder->convert(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& extract() const
|
||||
/// Returns a const reference to the actual value.
|
||||
///
|
||||
/// Must be instantiated with the exact type of
|
||||
/// the stored value, otherwise a BadCastException
|
||||
/// is thrown.
|
||||
{
|
||||
DynamicAnyHolderImpl<T>* pHolder = dynamic_cast<DynamicAnyHolderImpl<T>*>(_pHolder);
|
||||
if (pHolder)
|
||||
return pHolder->value();
|
||||
else
|
||||
throw BadCastException();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
DynamicAny& operator = (const T& other)
|
||||
@@ -167,4 +182,4 @@ private:
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Poco_DynamicAny_INCLUDED
|
||||
#endif // Foundation_DynamicAny_INCLUDED
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//
|
||||
// DynamicAnyHolder.h
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/include/Poco/DynamicAnyHolder.h#4 $
|
||||
// $Id: //poco/Main/Foundation/include/Poco/DynamicAnyHolder.h#6 $
|
||||
//
|
||||
// Library: Poco
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: DynamicAnyHolder
|
||||
//
|
||||
@@ -36,11 +36,11 @@
|
||||
//
|
||||
|
||||
|
||||
#ifndef Poco_DynamicAnyHolder_INCLUDED
|
||||
#define Poco_DynamicAnyHolder_INCLUDED
|
||||
#ifndef Foundation_DynamicAnyHolder_INCLUDED
|
||||
#define Foundation_DynamicAnyHolder_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Poco.h"
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/NumberParser.h"
|
||||
#include "Poco/String.h"
|
||||
@@ -210,6 +210,10 @@ class DynamicAnyHolderImpl: public DynamicAnyHolder
|
||||
/// NotImplementedException (if the specialization for a type does not exist)
|
||||
/// RangeException (if an attempt is made to assign a numeric value outside of the target min/max limits
|
||||
/// SyntaxException (if an attempt is made to convert a string containing non-numeric characters to number)
|
||||
///
|
||||
/// All specializations must additionally implement a public member function:
|
||||
/// const T& value() const
|
||||
/// returning a const reference to the actual stored value.
|
||||
{
|
||||
public:
|
||||
DynamicAnyHolderImpl()
|
||||
@@ -383,6 +387,11 @@ public:
|
||||
{
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const Int8& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
private:
|
||||
Int8 _val;
|
||||
@@ -476,6 +485,11 @@ public:
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const Int16& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
private:
|
||||
Int16 _val;
|
||||
};
|
||||
@@ -568,6 +582,11 @@ public:
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const Int32& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
private:
|
||||
Int32 _val;
|
||||
};
|
||||
@@ -660,6 +679,11 @@ public:
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const Int64& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
private:
|
||||
Int64 _val;
|
||||
};
|
||||
@@ -752,6 +776,11 @@ public:
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const UInt8& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
private:
|
||||
UInt8 _val;
|
||||
};
|
||||
@@ -844,6 +873,11 @@ public:
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const UInt16& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
private:
|
||||
UInt16 _val;
|
||||
};
|
||||
@@ -936,6 +970,11 @@ public:
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const UInt32& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
private:
|
||||
UInt32 _val;
|
||||
};
|
||||
@@ -1028,6 +1067,11 @@ public:
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const UInt64& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
private:
|
||||
UInt64 _val;
|
||||
};
|
||||
@@ -1120,6 +1164,11 @@ public:
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const bool& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _val;
|
||||
};
|
||||
@@ -1213,6 +1262,11 @@ public:
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const float& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
private:
|
||||
float _val;
|
||||
};
|
||||
@@ -1312,6 +1366,11 @@ public:
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const double& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
private:
|
||||
double _val;
|
||||
};
|
||||
@@ -1404,6 +1463,11 @@ public:
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const char& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
private:
|
||||
char _val;
|
||||
};
|
||||
@@ -1514,6 +1578,11 @@ public:
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const std::string& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _val;
|
||||
};
|
||||
@@ -1609,6 +1678,11 @@ public:
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const long& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
private:
|
||||
long _val;
|
||||
};
|
||||
@@ -1701,6 +1775,11 @@ public:
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const unsigned long& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned long _val;
|
||||
};
|
||||
@@ -1712,4 +1791,4 @@ private:
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Poco_DynamicAnyHolder_INCLUDED
|
||||
#endif // Foundation_DynamicAnyHolder_INCLUDED
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//
|
||||
// SharedMemory.h
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/include/Poco/SharedMemory.h#4 $
|
||||
// $Id: //poco/Main/Foundation/include/Poco/SharedMemory.h#5 $
|
||||
//
|
||||
// Library: Poco
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemory
|
||||
//
|
||||
@@ -36,11 +36,11 @@
|
||||
//
|
||||
|
||||
|
||||
#ifndef Poco_SharedMemory_INCLUDED
|
||||
#define Poco_SharedMemory_INCLUDED
|
||||
#ifndef Foundation_SharedMemory_INCLUDED
|
||||
#define Foundation_SharedMemory_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Poco.h"
|
||||
#include "Poco/Foundation.h"
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
|
||||
@@ -128,4 +128,4 @@ inline void SharedMemory::swap(SharedMemory& other)
|
||||
} // namespace Poco::Poco
|
||||
|
||||
|
||||
#endif // Poco_SharedMemory_INCLUDED
|
||||
#endif // Foundation_SharedMemory_INCLUDED
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//
|
||||
// SharedMemoryImpl.h
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/include/Poco/SharedMemory_DUMMY.h#3 $
|
||||
// $Id: //poco/Main/Foundation/include/Poco/SharedMemory_DUMMY.h#4 $
|
||||
//
|
||||
// Library: Poco
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemoryImpl
|
||||
//
|
||||
@@ -36,11 +36,11 @@
|
||||
//
|
||||
|
||||
|
||||
#ifndef Poco_SharedMemoryImpl_INCLUDED
|
||||
#define Poco_SharedMemoryImpl_INCLUDED
|
||||
#ifndef Foundation_SharedMemoryImpl_INCLUDED
|
||||
#define Foundation_SharedMemoryImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Poco.h"
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/SharedMemory.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
|
||||
@@ -107,4 +107,4 @@ inline char* SharedMemoryImpl::end() const
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Poco_SharedMemoryImpl_INCLUDED
|
||||
#endif // Foundation_SharedMemoryImpl_INCLUDED
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//
|
||||
// SharedMemoryImpl.h
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/include/Poco/SharedMemory_POSIX.h#4 $
|
||||
// $Id: //poco/Main/Foundation/include/Poco/SharedMemory_POSIX.h#5 $
|
||||
//
|
||||
// Library: Poco
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemoryImpl
|
||||
//
|
||||
@@ -36,11 +36,11 @@
|
||||
//
|
||||
|
||||
|
||||
#ifndef Poco_SharedMemoryImpl_INCLUDED
|
||||
#define Poco_SharedMemoryImpl_INCLUDED
|
||||
#ifndef Foundation_SharedMemoryImpl_INCLUDED
|
||||
#define Foundation_SharedMemoryImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Poco.h"
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/SharedMemory.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
|
||||
@@ -122,4 +122,4 @@ inline char* SharedMemoryImpl::end() const
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Poco_SharedMemoryImpl_INCLUDED
|
||||
#endif // Foundation_SharedMemoryImpl_INCLUDED
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//
|
||||
// SharedMemoryImpl.h
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/include/Poco/SharedMemory_WIN32.h#3 $
|
||||
// $Id: //poco/Main/Foundation/include/Poco/SharedMemory_WIN32.h#4 $
|
||||
//
|
||||
// Library: Poco
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemoryImpl
|
||||
//
|
||||
@@ -36,8 +36,8 @@
|
||||
//
|
||||
|
||||
|
||||
#ifndef Poco_SharedMemoryImpl_INCLUDED
|
||||
#define Poco_SharedMemoryImpl_INCLUDED
|
||||
#ifndef Foundation_SharedMemoryImpl_INCLUDED
|
||||
#define Foundation_SharedMemoryImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Poco.h"
|
||||
@@ -122,4 +122,4 @@ inline char* SharedMemoryImpl::end() const
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Poco_SharedMemoryImpl_INCLUDED
|
||||
#endif // Foundation_SharedMemoryImpl_INCLUDED
|
||||
|
||||
Reference in New Issue
Block a user