1 #ifndef UTIL___STATIC_SET__HPP
2 #define UTIL___STATIC_SET__HPP
58 template<
class FirstType,
class SecondType>
86 template<
class KeyValueGetter,
class KeyCompare>
108 template<
class Type1,
class Type2>
111 return key_comp()(getter::get_key(v1), getter::get_key(
v2));
116 template<
class Value>
139 template<
class Value>
175 virtual void Convert(
void* dst,
const void* src)
const = 0;
202 return m_ElementCount;
206 void* ret = m_ArrayPtr;
222 void Convert(
const void* src_array,
271 template<
typename DstType,
typename SrcType>
277 return typeid(SrcType);
281 return typeid(DstType);
285 return sizeof(SrcType);
289 return sizeof(DstType);
293 static_cast<DstType*
>(dst)->~DstType();
299 template<
typename DstType,
typename SrcType>
305 return typeid(SrcType);
309 return typeid(DstType);
313 return sizeof(SrcType);
317 return sizeof(DstType);
321 static_cast<DstType*
>(dst)->~DstType();
323 void Convert(
void* dst,
const void* src)
const
325 new (dst)DstType(*
static_cast<const SrcType*
>(src));
330 template<
typename DstType,
typename SrcType>
339 template<
typename DstType,
typename SrcType>
344 template<
typename DstType1,
typename DstType2,
345 typename SrcType1,
typename SrcType2>
348 pair<SrcType1, SrcType2>* src_ptr)
354 template<
typename DstType1,
typename DstType2,
355 typename SrcType1,
typename SrcType2>
364 template<
typename DstType1,
typename DstType2,
365 typename SrcType1,
typename SrcType2>
375 template<
typename DstType,
typename SrcType>
381 return typeid(SrcType);
385 return typeid(DstType);
389 return sizeof(SrcType);
393 return sizeof(DstType);
397 static_cast<DstType*
>(dst)->~DstType();
399 void Convert(
void* dst_ptr,
const void* src_ptr)
const
401 unique_ptr<IObjectConverter> conv1
402 (
MakeConverter(
static_cast<typename DstType::first_type*
>(0),
403 static_cast<typename SrcType::first_type*
>(0)));
404 unique_ptr<IObjectConverter> conv2
405 (
MakeConverter(
static_cast<typename DstType::second_type*
>(0),
406 static_cast<typename SrcType::second_type*
>(0)));
407 DstType& dst = *
static_cast<DstType*
>(dst_ptr);
408 const SrcType& src = *
static_cast<const SrcType*
>(src_ptr);
409 conv1->Convert((
void*)&dst.first, &src.first);
411 conv2->Convert((
void*)&dst.second, &src.second);
417 template<
typename DstType,
typename SrcType>
444 template<
typename Type>
454 template<
typename Type1,
typename Type2>
461 template<
typename Type1,
typename Type2>
478 template<
typename Type1,
typename Type2>
492 template<
typename Type1,
typename Type2>
504 template<
typename Type>
559 template <
typename KeyValueGetter,
typename KeyCompare>
581 template<
size_t Size>
583 const char*
file,
int line,
590 template<
size_t Size>
593 const char*
file,
int line,
603 template<
typename Type>
605 const char*
file,
int line,
608 x_Set(array_ptr, array_size,
file, line, warn);
612 template<
typename Type>
615 const char*
file,
int line,
619 x_Set(array_ptr, array_size,
file, line, warn);
703 return make_pair(start, iter);
723 using namespace NStaticArray;
725 for (
size_t i = 1;
i <
size; ++
i ) {
735 const char*
file,
int line,
738 using namespace NStaticArray;
739 CheckStaticType<value_type>(
file, line);
752 m_End = array_ptr + sz;
757 template<
typename Type>
759 const char*
file,
int line,
762 using namespace NStaticArray;
763 CheckStaticType<Type>(
file, line);
765 size_t sz = array2_size /
sizeof(
Type);
767 static_cast<Type*
>(0)));
789 using namespace NStaticArray;
821 template <
class KeyType,
class KeyCompare = less<KeyType> >
835 template<
size_t Size>
837 const char*
file,
int line,
844 template<
size_t Size>
847 const char*
file,
int line,
858 const char*
file,
int line,
860 :
TBase(array_ptr, array_size,
file, line, warn)
868 const char*
file,
int line,
870 :
TBase(array_ptr, array_size, comp,
file, line, warn)
885 #define DECLARE_CLASS_STATIC_ARRAY_MAP(Type, Var) \
886 static const Type Var
888 #define DEFINE_STATIC_ARRAY_MAP(Type, Var, Array) \
889 static const Type (Var)((Array), sizeof(Array), __FILE__, __LINE__)
891 #define DEFINE_CLASS_STATIC_ARRAY_MAP(Type, Var, Array) \
892 const Type (Var)((Array), sizeof(Array), __FILE__, __LINE__)
894 #define DEFINE_STATIC_ARRAY_MAP_WITH_COPY(Type, Var, Array) \
895 static const Type (Var)((Array), sizeof(Array), __FILE__, __LINE__, \
896 NCBI_NS_NCBI::NStaticArray::eCopyWarn_hide)
898 #define DEFINE_CLASS_STATIC_ARRAY_MAP_WITH_COPY(Type, Var, Array) \
899 const Type (Var)((Array), sizeof(Array), __FILE__, __LINE__, \
900 NCBI_NS_NCBI::NStaticArray::eCopyWarn_hide)
905 template <
class KeyType,
class KeyCompare>
914 template <
class KeyType,
class KeyCompare>
Helper class for holding and correct destruction of static array copy.
void operator=(const CArrayHolder &)
void Convert(const void *src_array, size_t size, const char *file, int line, ECopyWarn warn)
Convert data from static array of different type using the holder's converter.
void * ReleaseArrayPtr(void)
size_t GetElementCount(void) const
CArrayHolder(const CArrayHolder &)
void * GetArrayPtr(void) const
unique_ptr< IObjectConverter > m_Converter
size_t GetDstTypeSize(void) const THROWS_NONE
const type_info & GetDstTypeInfo(void) const THROWS_NONE
void Destroy(void *dst) const THROWS_NONE
size_t GetSrcTypeSize(void) const THROWS_NONE
const type_info & GetSrcTypeInfo(void) const THROWS_NONE
Helper class for destruction of field 'first' in pair<> if exception is thrown while constructing 'se...
void EndOfConversion(void) THROWS_NONE
void operator=(const CObjectDestroyerGuard &)
IObjectConverter * m_Converter
~CObjectDestroyerGuard(void) THROWS_NONE
CObjectDestroyerGuard(void *ptr, IObjectConverter *converter) THROWS_NONE
CObjectDestroyerGuard(const CObjectDestroyerGuard &)
Implementation of converter for pair<> conversion.
const type_info & GetDstTypeInfo(void) const THROWS_NONE
const type_info & GetSrcTypeInfo(void) const THROWS_NONE
size_t GetDstTypeSize(void) const THROWS_NONE
void Convert(void *dst_ptr, const void *src_ptr) const
size_t GetSrcTypeSize(void) const THROWS_NONE
void Destroy(void *dst) const THROWS_NONE
Implementation of converter for a single-object conversion.
const type_info & GetSrcTypeInfo(void) const THROWS_NONE
size_t GetDstTypeSize(void) const THROWS_NONE
const type_info & GetDstTypeInfo(void) const THROWS_NONE
size_t GetSrcTypeSize(void) const THROWS_NONE
void Convert(void *dst, const void *src) const
void Destroy(void *dst) const THROWS_NONE
class CStaticArraySet<> is an array adaptor that provides an STLish interface to statically-defined a...
CStaticArraySearchBase(const value_type(&arr)[Size], const char *file, int line, NStaticArray::ECopyWarn warn)
Default constructor.
static void x_Validate(const value_type *array, size_t size, const value_compare &comp, const char *file, int line)
Perform sort-order validation. This is a no-op in release mode.
difference_type index_of(const key_type &key) const
Return the index of the indicated element, or eNpos if the element is not found.
const_iterator upper_bound(const key_type &key) const
Return an iterator into the sequence such that the iterator's key is greater than the indicated key.
const_iterator find(const key_type &key) const
Return a const_iterator pointing to the specified element, or to the end if the element is not found.
CStaticArraySearchBase(const Type *array_ptr, size_type array_size, const char *file, int line, NStaticArray::ECopyWarn warn)
Default constructor.
const_iterator end() const
Return the end of the controlled sequence.
pair_base_member< value_compare, const_iterator > m_Begin
getter::mapped_type mapped_type
getter::value_type value_type
pair< const_iterator, const_iterator > equal_range(const key_type &key) const
Return a pair of iterators bracketing the given element in the controlled sequence.
const value_type * const_iterator
const_iterator begin() const
Return the start of the controlled sequence.
bool empty() const
Return true if the container is empty.
void(* TDeallocateFunc)(const_iterator &begin, const_iterator &end)
getter::key_type key_type
CStaticArraySearchBase(const Type *array_ptr, size_type array_size, const key_compare &comp, const char *file, int line, NStaticArray::ECopyWarn warn)
Constructor to initialize comparator object.
static void x_DeallocateFunc(const_iterator &begin_ref, const_iterator &end_ref)
Function used for array destruction and deallocation if it was created from a differently typed stati...
const_iterator lower_bound(const key_type &key) const
Return an iterator into the sequence such that the iterator's key is less than or equal to the indica...
TDeallocateFunc m_DeallocateFunc
void x_Set(const value_type *array_ptr, size_t array_size, const char *file, int line, NStaticArray::ECopyWarn)
Assign array pointer and end pointer without conversion.
void x_Set(const Type *array2_ptr, size_t array2_size, const char *file, int line, NStaticArray::ECopyWarn warn)
Assign array pointer and end pointer from differently typed array.
const key_compare & key_comp() const
~CStaticArraySearchBase(void)
Destructor.
const value_compare & value_comp() const
NStaticArray::PLessByKey< getter, key_compare > value_compare
CStaticArraySearchBase(const value_type(&arr)[Size], const key_compare &comp, const char *file, int line, NStaticArray::ECopyWarn warn)
Constructor to initialize comparator object.
const value_type & const_reference
size_type count(const key_type &key) const
Return the count of the elements in the sequence.
bool x_Bad(const key_type &key, const_iterator iter) const
size_type size() const
Return number of elements in the container.
CStaticArraySet(const value_type(&arr)[Size], const key_compare &comp, const char *file, int line, NStaticArray::ECopyWarn warn=NStaticArray::eCopyWarn_default)
Constructor to initialize comparator object.
CStaticArraySet(const Type *array_ptr, size_t array_size, const key_compare &comp, const char *file, int line, NStaticArray::ECopyWarn warn=NStaticArray::eCopyWarn_default)
Constructor to initialize comparator object.
TBase::const_iterator const_iterator
TBase::size_type size_type
CStaticArraySet(const Type *array_ptr, size_t array_size, const char *file, int line, NStaticArray::ECopyWarn warn=NStaticArray::eCopyWarn_default)
default constructor.
TBase::key_compare key_compare
CStaticArraySearchBase< NStaticArray::PKeyValueSelf< KeyType >, KeyCompare > TBase
TBase::value_type value_type
CStaticArraySet(const value_type(&arr)[Size], const char *file, int line, NStaticArray::ECopyWarn warn=NStaticArray::eCopyWarn_default)
default constructor.
Helper class for single object conversion from static type to work type.
virtual void Convert(void *dst, const void *src) const =0
virtual void Destroy(void *dst) const THROWS_NONE=0
virtual size_t GetSrcTypeSize(void) const THROWS_NONE=0
virtual const type_info & GetSrcTypeInfo(void) const THROWS_NONE=0
virtual size_t GetDstTypeSize(void) const THROWS_NONE=0
DECLARE_CLASS_STATIC_FAST_MUTEX(sx_InitMutex)
virtual const type_info & GetDstTypeInfo(void) const THROWS_NONE=0
static mapped_type & get_mapped(value_type &value)
static const mapped_type & get_mapped(const value_type &value)
static const key_type & get_key(const value_type &value)
value_type::second_type mapped_type
static const key_type & get_key(const key_type &key)
value_type::first_type key_type
static const mapped_type & get_mapped(const value_type &value)
static const key_type & get_key(const value_type &value)
static mapped_type & get_mapped(value_type &value)
Include a standard set of the NCBI C++ Toolkit most basic headers.
static vector< string > arr
const first_type & first() const
#define NCBI_DEPRECATED_CTOR(decl)
Macro used to mark a constructor as deprecated.
const second_type & second() const
#define THROWS_NONE
Do not use 'throw' dynamic exception specification for C++11 compilers.
#define NCBI_PARAM_DECL_EXPORT(expname, type, section, name)
Same as NCBI_PARAM_DECL but with export specifier (e.g.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition of all error codes used in util (xutil.lib).
double value_type
The numeric datatype used by the parser.
const struct ncbi::grid::netcache::search::fields::SIZE size
const struct ncbi::grid::netcache::search::fields::KEY key
const GenericPointer< typename T::ValueType > T2 value
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Multi-threading – mutexes; rw-locks; semaphore.
IObjectConverter * MakeConverter(DstType *, SrcType *)
IObjectConverter * MakePairConverter(DstType *, SrcType *)
void CheckStaticType(const Type *, const char *, int)
Template for checking if the static array type is MT-safe, i.e.
STATIC_ARRAY_COPY_WARNING
typedef NCBI_PARAM_TYPE(NCBI, STATIC_ARRAY_COPY_WARNING) TParamStaticArrayCopyWarning
STATIC_ARRAY_UNSAFE_TYPE_WARNING
void ReportUnsafeStaticType(const char *type_name, const char *file, int line)
Log error message about non-MT-safe static type (string, pair<>) if it's configured by TParamStaticAr...
END_NAMESPACE(NStaticArray)
NCBI_XUTIL_EXPORT
Parameter to control printing diagnostic message about conversion of static array data from a differe...
void ReportIncorrectOrder(size_t curr_index, const char *file, int line)
Log error message about wrong order of elements in array and abort.
BEGIN_NAMESPACE(NStaticArray)
Namespace for static array templates' implementation.
getter::value_type value_type
getter::key_type key_type
PLessByKey(const key_compare &comp)
const key_compare & key_comp() const
bool operator()(const Type1 &v1, const Type2 &v2) const
Template structure SStaticPair is simlified replacement of STL pair<> Main reason of introducing this...
const value_slice::CValueConvert< value_slice::SRunTimeCP, FROM > Convert(const FROM &value)
static const char * type_name(CS_INT value)