NCBI C++ ToolKit
static_set.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef UTIL___STATIC_SET__HPP
2 #define UTIL___STATIC_SET__HPP
3 
4 /* $Id: static_set.hpp 77707 2017-05-03 12:47:35Z ivanov $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Mike DiCuccio, Eugene Vasilchenko
30  *
31  * File Description:
32  * CStaticArraySet<> -- template class to provide convenient access to
33  * a statically-defined array, while making sure that
34  * the order of the array meets sort criteria in
35  * debug builds.
36  *
37  */
38 
39 #include <util/error_codes.hpp>
40 #include <corelib/ncbistd.hpp>
41 #include <corelib/ncbimtx.hpp>
42 #include <corelib/ncbi_param.hpp>
43 #include <utility>
44 #include <typeinfo>
45 #include <algorithm>
46 #include <functional>
47 
48 
50 
51 
52 ///
53 /// Template structure SStaticPair is simlified replacement of STL pair<>
54 /// Main reason of introducing this structure is o allow static initialization
55 /// by { xxx } construct.
56 /// It's main use is for static const structures which do not need constructors
57 ///
58 template<class FirstType, class SecondType>
60 {
61  typedef FirstType first_type;
62  typedef SecondType second_type;
63 
66 };
67 
68 
69 /// Parameter to control printing diagnostic message about conversion
70 /// of static array data from a different type.
71 /// Default value is "off".
73 typedef NCBI_PARAM_TYPE(NCBI, STATIC_ARRAY_COPY_WARNING) TParamStaticArrayCopyWarning;
74 
75 
76 /// Parameter to control printing diagnostic message about unsafe static type.
77 /// Default value is "on".
79 typedef NCBI_PARAM_TYPE(NCBI, STATIC_ARRAY_UNSAFE_TYPE_WARNING) TParamStaticArrayUnsafeTypeWarning;
80 
81 
82 /// Namespace for static array templates' implementation.
83 BEGIN_NAMESPACE(NStaticArray);
84 
85 
86 template<class KeyValueGetter, class KeyCompare>
87 struct PLessByKey : public KeyCompare
88 {
89  typedef KeyValueGetter getter;
90  typedef typename getter::value_type value_type;
91  typedef typename getter::key_type key_type;
92  typedef KeyCompare key_compare;
93 
95  {
96  }
97 
98  PLessByKey(const key_compare& comp)
99  : key_compare(comp)
100  {
101  }
102 
103  const key_compare& key_comp() const
104  {
105  return *this;
106  }
107 
108  template<class Type1, class Type2>
109  bool operator()(const Type1& v1, const Type2& v2) const
110  {
111  return key_comp()(getter::get_key(v1), getter::get_key(v2));
112  }
113 };
114 
115 
116 template<class Value>
118 {
119 public:
120  typedef Value value_type;
123 
124  static const key_type& get_key(const value_type& value)
125  {
126  return value;
127  }
128  static const mapped_type& get_mapped(const value_type& value)
129  {
130  return value;
131  }
133  {
134  return value;
135  }
136 };
137 
138 
139 template<class Value>
141 {
142 public:
143  typedef Value value_type;
144  typedef typename value_type::first_type key_type;
145  typedef typename value_type::second_type mapped_type;
146 
147  static const key_type& get_key(const key_type& key)
148  {
149  return key;
150  }
151  static const key_type& get_key(const value_type& value)
152  {
153  return value.first;
154  }
155  static const mapped_type& get_mapped(const value_type& value)
156  {
157  return value.second;
158  }
160  {
161  return value.second;
162  }
163 };
164 
165 
166 /// Helper class for single object conversion from static type to work type.
168 {
169 public:
170  virtual ~IObjectConverter(void) THROWS_NONE;
171  virtual const type_info& GetSrcTypeInfo(void) const THROWS_NONE = 0;
172  virtual const type_info& GetDstTypeInfo(void) const THROWS_NONE = 0;
173  virtual size_t GetSrcTypeSize(void) const THROWS_NONE = 0;
174  virtual size_t GetDstTypeSize(void) const THROWS_NONE = 0;
175  virtual void Convert(void* dst, const void* src) const = 0;
176  virtual void Destroy(void* dst) const THROWS_NONE = 0;
177 
179 };
180 
181 
182 enum ECopyWarn {
186 };
187 
188 
189 /// Helper class for holding and correct destruction of static array copy.
191 {
192 public:
194  ~CArrayHolder(void) THROWS_NONE;
195 
196  void* GetArrayPtr(void) const
197  {
198  return m_ArrayPtr;
199  }
200  size_t GetElementCount(void) const
201  {
202  return m_ElementCount;
203  }
204  void* ReleaseArrayPtr(void)
205  {
206  void* ret = m_ArrayPtr;
207  m_ArrayPtr = 0;
208  m_ElementCount = 0;
209  return ret;
210  }
211 
212  /// Convert data from static array of different type using
213  /// the holder's converter. The result is stored in the holder.
214  /// @param src_array
215  /// Pointer to the source static array.
216  /// @param size
217  /// Number of elements in the array.
218  /// @param file
219  /// Source file name of the static array declaration for diagnostics.
220  /// @param line
221  /// Source line number of the static array declaration for diagnostics.
222  void Convert(const void* src_array,
223  size_t size,
224  const char* file,
225  int line,
226  ECopyWarn warn);
227 
228 private:
229  unique_ptr<IObjectConverter> m_Converter;
230  void* m_ArrayPtr;
232 
233 private:
235  void operator=(const CArrayHolder&);
236 };
237 
238 
239 /// Helper class for destruction of field 'first' in pair<> if exception
240 /// is thrown while constructing 'second'.
242 {
243 public:
245  IObjectConverter* converter) THROWS_NONE
246  : m_Ptr(ptr),
247  m_Converter(converter)
248  {
249  }
251  {
252  if ( m_Ptr ) {
254  }
255  }
257  {
258  m_Ptr = 0;
259  }
260 
261 private:
262  void* m_Ptr;
264 
265 private:
268 };
269 
270 
271 template<typename DstType, typename SrcType>
273 {
274 public:
275  const type_info& GetSrcTypeInfo(void) const THROWS_NONE
276  {
277  return typeid(SrcType);
278  }
279  const type_info& GetDstTypeInfo(void) const THROWS_NONE
280  {
281  return typeid(DstType);
282  }
283  size_t GetSrcTypeSize(void) const THROWS_NONE
284  {
285  return sizeof(SrcType);
286  }
287  size_t GetDstTypeSize(void) const THROWS_NONE
288  {
289  return sizeof(DstType);
290  }
291  void Destroy(void* dst) const THROWS_NONE
292  {
293  static_cast<DstType*>(dst)->~DstType();
294  }
295 };
296 
297 
298 /// Implementation of converter for a single-object conversion.
299 template<typename DstType, typename SrcType>
301 {
302 public:
303  const type_info& GetSrcTypeInfo(void) const THROWS_NONE
304  {
305  return typeid(SrcType);
306  }
307  const type_info& GetDstTypeInfo(void) const THROWS_NONE
308  {
309  return typeid(DstType);
310  }
311  size_t GetSrcTypeSize(void) const THROWS_NONE
312  {
313  return sizeof(SrcType);
314  }
315  size_t GetDstTypeSize(void) const THROWS_NONE
316  {
317  return sizeof(DstType);
318  }
319  void Destroy(void* dst) const THROWS_NONE
320  {
321  static_cast<DstType*>(dst)->~DstType();
322  }
323  void Convert(void* dst, const void* src) const
324  {
325  new (dst)DstType(*static_cast<const SrcType*>(src));
326  }
327 };
328 
329 
330 template<typename DstType, typename SrcType>
331 inline
332 IObjectConverter* MakeConverter(DstType* /*dst_ptr*/,
333  SrcType* /*src_ptr*/)
334 {
336 }
337 
338 
339 template<typename DstType, typename SrcType>
340 IObjectConverter* MakePairConverter(DstType* /*dst_ptr*/,
341  SrcType* /*src_ptr*/);
342 
343 
344 template<typename DstType1, typename DstType2,
345  typename SrcType1, typename SrcType2>
346 inline
347 IObjectConverter* MakeConverter(pair<DstType1, DstType2>* dst_ptr,
348  pair<SrcType1, SrcType2>* src_ptr)
349 {
350  return MakePairConverter(dst_ptr, src_ptr);
351 }
352 
353 
354 template<typename DstType1, typename DstType2,
355  typename SrcType1, typename SrcType2>
356 inline
357 IObjectConverter* MakeConverter(pair<DstType1, DstType2>* dst_ptr,
359 {
360  return MakePairConverter(dst_ptr, src_ptr);
361 }
362 
363 
364 template<typename DstType1, typename DstType2,
365  typename SrcType1, typename SrcType2>
366 inline
369 {
370  return MakePairConverter(dst_ptr, src_ptr);
371 }
372 
373 
374 /// Implementation of converter for pair<> conversion.
375 template<typename DstType, typename SrcType>
376 class CPairConverter : public CObjectConverterBase<DstType, SrcType>
377 {
378 public:
379  const type_info& GetSrcTypeInfo(void) const THROWS_NONE
380  {
381  return typeid(SrcType);
382  }
383  const type_info& GetDstTypeInfo(void) const THROWS_NONE
384  {
385  return typeid(DstType);
386  }
387  size_t GetSrcTypeSize(void) const THROWS_NONE
388  {
389  return sizeof(SrcType);
390  }
391  size_t GetDstTypeSize(void) const THROWS_NONE
392  {
393  return sizeof(DstType);
394  }
395  void Destroy(void* dst) const THROWS_NONE
396  {
397  static_cast<DstType*>(dst)->~DstType();
398  }
399  void Convert(void* dst_ptr, const void* src_ptr) const
400  {
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);
410  CObjectDestroyerGuard guard((void*)&dst.first, conv1.get());
411  conv2->Convert((void*)&dst.second, &src.second);
412  guard.EndOfConversion();
413  }
414 };
415 
416 
417 template<typename DstType, typename SrcType>
418 inline
419 IObjectConverter* MakePairConverter(DstType* /*dst_ptr*/,
420  SrcType* /*src_ptr*/)
421 {
423 }
424 
425 
426 /// Log error message about non-MT-safe static type (string, pair<>) if it's
427 /// configured by TParamStaticArrayUnsafeTypeWarning parameter.
429 void ReportUnsafeStaticType(const char* type_name,
430  const char* file,
431  int line);
432 
433 
434 /// Log error message about wrong order of elements in array and abort.
436 void ReportIncorrectOrder(size_t curr_index,
437  const char* file,
438  int line);
439 
440 
441 /// Template for checking if the static array type is MT-safe,
442 /// i.e. doesn't have a constructor.
443 /// Only few standard types are detected - std::string, and std::pair<>.
444 template<typename Type>
445 inline
446 void CheckStaticType(const Type* /*type_ptr*/,
447  const char* /*file*/,
448  int /*line*/)
449 {
450  // By default all types are allowed in static variables
451 }
452 
453 
454 template<typename Type1, typename Type2>
455 inline
456 void CheckStaticType(const pair<Type1, Type2>* type_ptr,
457  const char* file,
458  int line);
459 
460 
461 template<typename Type1, typename Type2>
462 inline
463 void CheckStaticType(const SStaticPair<Type1, Type2>* type_ptr,
464  const char* file,
465  int line);
466 
467 
468 inline
469 void CheckStaticType(const string* /*type_ptr*/,
470  const char* file,
471  int line)
472 {
473  // Strings are bad in static variables
474  NStaticArray::ReportUnsafeStaticType("std::string", file, line);
475 }
476 
477 
478 template<typename Type1, typename Type2>
479 inline
480 void CheckStaticType(const pair<Type1, Type2>* /*type_ptr*/,
481  const char* file,
482  int line)
483 {
484  // The std::pair<> is not good for static variables
485  NStaticArray::ReportUnsafeStaticType("std::pair<>", file, line);
486  // check types of both members of the pair
487  CheckStaticType(static_cast<const Type1*>(0), file, line);
488  CheckStaticType(static_cast<const Type2*>(0), file, line);
489 }
490 
491 
492 template<typename Type1, typename Type2>
493 inline
495  const char* file,
496  int line)
497 {
498  // check types of both members of the pair
499  CheckStaticType(static_cast<const Type1*>(0), file, line);
500  CheckStaticType(static_cast<const Type2*>(0), file, line);
501 }
502 
503 
504 template<typename Type>
505 inline
506 void CheckStaticType(const char* file,
507  int line)
508 {
509  CheckStaticType(static_cast<const Type*>(0), file, line);
510 }
511 
512 
513 END_NAMESPACE(NStaticArray);
514 
515 ///
516 /// class CStaticArraySet<> is an array adaptor that provides an STLish
517 /// interface to statically-defined arrays, while making efficient use
518 /// of the inherent sort order of such arrays.
519 ///
520 /// This class can be used both to verify sorted order of a static array
521 /// and to access a static array cleanly. The template parameters are
522 /// as follows:
523 ///
524 /// KeyType -- type of object used for access
525 /// KeyCompare -- comparison functor. This must provide an operator().
526 /// This is patterned to accept PCase and PNocase and similar objects.
527 ///
528 /// To use this class, define your static array as follows:
529 ///
530 /// static const char* sc_MyArray[] = {
531 /// "val1",
532 /// "val2",
533 /// "val3"
534 /// };
535 ///
536 /// Then, declare a static variable such as:
537 ///
538 /// typedef StaticArraySet<const char*, PNocase_CStr> TStaticArray;
539 /// static TStaticArray sc_Array(sc_MyArray, sizeof(sc_MyArray));
540 ///
541 /// In debug mode, the constructor will scan the list of items and insure
542 /// that they are in the sort order defined by the comparator used. If the
543 /// sort order is not correct, then the constructor will ASSERT().
544 ///
545 /// This can then be accessed as
546 ///
547 /// if (sc_Array.find(some_value) != sc_Array.end()) {
548 /// ...
549 /// }
550 ///
551 /// or
552 ///
553 /// size_t idx = sc_Array.index_of(some_value);
554 /// if (idx != TStaticArray::eNpos) {
555 /// ...
556 /// }
557 ///
558 ///
559 template <typename KeyValueGetter, typename KeyCompare>
561 {
562 public:
563  enum {
564  eNpos = -1
565  };
566 
567  typedef KeyValueGetter getter;
568  typedef typename getter::value_type value_type;
569  typedef typename getter::key_type key_type;
570  typedef typename getter::mapped_type mapped_type;
571  typedef KeyCompare key_compare;
572  typedef NStaticArray::PLessByKey<getter, key_compare> value_compare;
573  typedef const value_type& const_reference;
574  typedef const value_type* const_iterator;
575  typedef size_t size_type;
577 
578  /// Default constructor. This will build a set around a given array; the
579  /// storage of the end pointer is based on the supplied array size. In
580  /// debug mode, this will verify that the array is sorted.
581  template<size_t Size>
583  const char* file, int line,
585  {
586  x_Set(arr, sizeof(arr), file, line, warn);
587  }
588 
589  /// Constructor to initialize comparator object.
590  template<size_t Size>
592  const key_compare& comp,
593  const char* file, int line,
595  : m_Begin(comp)
596  {
597  x_Set(arr, sizeof(arr), file, line, warn);
598  }
599 
600  /// Default constructor. This will build a set around a given array; the
601  /// storage of the end pointer is based on the supplied array size. In
602  /// debug mode, this will verify that the array is sorted.
603  template<typename Type>
604  CStaticArraySearchBase(const Type* array_ptr, size_type array_size,
605  const char* file, int line,
607  {
608  x_Set(array_ptr, array_size, file, line, warn);
609  }
610 
611  /// Constructor to initialize comparator object.
612  template<typename Type>
613  CStaticArraySearchBase(const Type* array_ptr, size_type array_size,
614  const key_compare& comp,
615  const char* file, int line,
617  : m_Begin(comp)
618  {
619  x_Set(array_ptr, array_size, file, line, warn);
620  }
621 
622  /// Destructor
624  {
625  if ( m_DeallocateFunc ) {
627  }
628  }
629 
630  const value_compare& value_comp() const
631  {
632  return m_Begin.first();
633  }
634 
635  const key_compare& key_comp() const
636  {
637  return value_comp().key_comp();
638  }
639 
640  /// Return the start of the controlled sequence.
642  {
643  return m_Begin.second();
644  }
645 
646  /// Return the end of the controlled sequence.
648  {
649  return m_End;
650  }
651 
652  /// Return true if the container is empty.
653  bool empty() const
654  {
655  return begin() == end();
656  }
657 
658  /// Return number of elements in the container.
659  size_type size() const
660  {
661  return end() - begin();
662  }
663 
664  /// Return an iterator into the sequence such that the iterator's key
665  /// is less than or equal to the indicated key.
667  {
668  return std::lower_bound(begin(), end(), key, value_comp());
669  }
670 
671  /// Return an iterator into the sequence such that the iterator's key
672  /// is greater than the indicated key.
674  {
675  return std::upper_bound(begin(), end(), key, value_comp());
676  }
677 
678  /// Return a const_iterator pointing to the specified element, or
679  /// to the end if the element is not found.
681  {
683  return x_Bad(key, iter)? end(): iter;
684  }
685 
686  /// Return the count of the elements in the sequence. This will be
687  /// either 0 or 1, as this structure holds unique keys.
688  size_type count(const key_type& key) const
689  {
691  return x_Bad(key, iter)? 0: 1;
692  }
693 
694  /// Return a pair of iterators bracketing the given element in
695  /// the controlled sequence.
696  pair<const_iterator, const_iterator> equal_range(const key_type& key) const
697  {
698  const_iterator start = lower_bound(key);
699  const_iterator iter = start;
700  if ( !x_Bad(key, iter) ) {
701  ++iter;
702  }
703  return make_pair(start, iter);
704  }
705 
706  /// Return the index of the indicated element, or eNpos if the element is
707  /// not found.
709  {
711  return x_Bad(key, iter)? eNpos: iter - begin();
712  }
713 
714 protected:
715 
716  /// Perform sort-order validation. This is a no-op in release mode.
717  static void x_Validate(const value_type* _DEBUG_ARG(array),
718  size_t _DEBUG_ARG(size),
719  const value_compare& _DEBUG_ARG(comp),
720  const char* _DEBUG_ARG(file),
721  int _DEBUG_ARG(line))
722  {
723  using namespace NStaticArray;
724 #ifdef _DEBUG
725  for ( size_t i = 1; i < size; ++i ) {
726  if ( !comp(array[i-1], array[i]) ) {
727  ReportIncorrectOrder(i, file, line);
728  }
729  }
730 #endif
731  }
732 
733  /// Assign array pointer and end pointer without conversion.
734  void x_Set(const value_type* array_ptr, size_t array_size,
735  const char* file, int line,
736  NStaticArray::ECopyWarn /*warn*/)
737  {
738  using namespace NStaticArray;
739  CheckStaticType<value_type>(file, line);
740  _ASSERT(array_size % sizeof(value_type) == 0);
741  size_t sz = array_size / sizeof(value_type);
742  if ( m_Begin.second() ) {
743  _ASSERT(m_Begin.second() == array_ptr);
744  _ASSERT(m_End == array_ptr + sz);
746  }
747  else {
748  x_Validate(array_ptr, sz, value_comp(), file, line);
749  }
750  m_DeallocateFunc = 0;
751  m_Begin.second() = array_ptr;
752  m_End = array_ptr + sz;
753  }
754 
755  /// Assign array pointer and end pointer from differently typed array.
756  /// Allocate necessarily typed array and copy its content.
757  template<typename Type>
758  void x_Set(const Type* array2_ptr, size_t array2_size,
759  const char* file, int line,
761  {
762  using namespace NStaticArray;
763  CheckStaticType<Type>(file, line);
764  _ASSERT(array2_size % sizeof(Type) == 0);
765  size_t sz = array2_size / sizeof(Type);
766  CArrayHolder holder(MakeConverter(static_cast<value_type*>(0),
767  static_cast<Type*>(0)));
768  holder.Convert(array2_ptr, sz, file, line, warn);
769  if ( !m_Begin.second() ) {
770  x_Validate(static_cast<const value_type*>(holder.GetArrayPtr()),
771  holder.GetElementCount(), value_comp(), file, line);
772  }
773  {{
774  CFastMutexGuard guard(IObjectConverter::sx_InitMutex);
775  if ( !m_Begin.second() ) {
776  m_Begin.second() =
777  static_cast<const value_type*>(holder.ReleaseArrayPtr());
778  m_End = m_Begin.second() + sz;
780  }
781  }}
782  }
783 
784  /// Function used for array destruction and deallocation if it
785  /// was created from a differently typed static array.
786  static void x_DeallocateFunc(const_iterator& begin_ref,
787  const_iterator& end_ref)
788  {
789  using namespace NStaticArray;
791  {{
792  CFastMutexGuard guard(IObjectConverter::sx_InitMutex);
793  begin = begin_ref;
794  end = end_ref;
795  begin_ref = 0;
796  end_ref = 0;
797  }}
798  if ( begin ) {
799  for ( ; end != begin; ) { // destruct in reverse order
800  (--end)->~value_type();
801  }
802  free((void*)begin);
803  }
804  }
805 
808 
809 private:
813 
814  bool x_Bad(const key_type& key, const_iterator iter) const
815  {
816  return iter == end() || value_comp()(key, *iter);
817  }
818 };
819 
820 
821 template <class KeyType, class KeyCompare = less<KeyType> >
823  : public CStaticArraySearchBase<NStaticArray::PKeyValueSelf<KeyType>, KeyCompare>
824 {
826 public:
827  typedef typename TBase::value_type value_type;
829  typedef typename TBase::size_type size_type;
830  typedef typename TBase::key_compare key_compare;
831 
832  /// default constructor. This will build a map around a given array; the
833  /// storage of the end pointer is based on the supplied array size. In
834  /// debug mode, this will verify that the array is sorted.
835  template<size_t Size>
837  const char* file, int line,
839  : TBase(arr, file, line, warn)
840  {
841  }
842 
843  /// Constructor to initialize comparator object.
844  template<size_t Size>
846  const key_compare& comp,
847  const char* file, int line,
849  : TBase(arr, comp, file, line, warn)
850  {
851  }
852 
853  /// default constructor. This will build a map around a given array; the
854  /// storage of the end pointer is based on the supplied array size. In
855  /// debug mode, this will verify that the array is sorted.
856  template<class Type>
857  CStaticArraySet(const Type* array_ptr, size_t array_size,
858  const char* file, int line,
860  : TBase(array_ptr, array_size, file, line, warn)
861  {
862  }
863 
864  /// Constructor to initialize comparator object.
865  template<class Type>
866  CStaticArraySet(const Type* array_ptr, size_t array_size,
867  const key_compare& comp,
868  const char* file, int line,
870  : TBase(array_ptr, array_size, comp, file, line, warn)
871  {
872  }
873 
876  size_type array_size));
877 
880  size_type array_size,
881  const key_compare& comp));
882 };
883 
884 
885 #define DECLARE_CLASS_STATIC_ARRAY_MAP(Type, Var) \
886  static const Type Var
887 
888 #define DEFINE_STATIC_ARRAY_MAP(Type, Var, Array) \
889  static const Type (Var)((Array), sizeof(Array), __FILE__, __LINE__)
890 
891 #define DEFINE_CLASS_STATIC_ARRAY_MAP(Type, Var, Array) \
892  const Type (Var)((Array), sizeof(Array), __FILE__, __LINE__)
893 
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)
897 
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)
901 
902 
903 // Deprecated constructors (defined here to avoid GCC 3.3 parse errors)
904 
905 template <class KeyType, class KeyCompare>
906 inline
908 (const_iterator obj,
909  size_type array_size)
910  : TBase(obj, array_size, 0, 0, NStaticArray::eCopyWarn_default)
911 {
912 }
913 
914 template <class KeyType, class KeyCompare>
915 inline
917 (const_iterator obj,
918  size_type array_size,
919  const key_compare& comp)
920  : TBase(obj, array_size, comp, 0, 0, NStaticArray::eCopyWarn_default)
921 {
922 }
923 
924 
926 
927 #endif // UTIL___STATIC_SET__HPP
Helper class for holding and correct destruction of static array copy.
Definition: static_set.hpp:191
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.
Definition: static_set.cpp:79
void * m_ArrayPtr
Definition: static_set.hpp:230
void * ReleaseArrayPtr(void)
Definition: static_set.hpp:204
size_t m_ElementCount
Definition: static_set.hpp:231
size_t GetElementCount(void) const
Definition: static_set.hpp:200
CArrayHolder(const CArrayHolder &)
void * GetArrayPtr(void) const
Definition: static_set.hpp:196
unique_ptr< IObjectConverter > m_Converter
Definition: static_set.hpp:229
size_t GetDstTypeSize(void) const THROWS_NONE
Definition: static_set.hpp:287
const type_info & GetDstTypeInfo(void) const THROWS_NONE
Definition: static_set.hpp:279
void Destroy(void *dst) const THROWS_NONE
Definition: static_set.hpp:291
size_t GetSrcTypeSize(void) const THROWS_NONE
Definition: static_set.hpp:283
const type_info & GetSrcTypeInfo(void) const THROWS_NONE
Definition: static_set.hpp:275
Helper class for destruction of field 'first' in pair<> if exception is thrown while constructing 'se...
Definition: static_set.hpp:242
void EndOfConversion(void) THROWS_NONE
Definition: static_set.hpp:256
void operator=(const CObjectDestroyerGuard &)
IObjectConverter * m_Converter
Definition: static_set.hpp:263
~CObjectDestroyerGuard(void) THROWS_NONE
Definition: static_set.hpp:250
CObjectDestroyerGuard(void *ptr, IObjectConverter *converter) THROWS_NONE
Definition: static_set.hpp:244
CObjectDestroyerGuard(const CObjectDestroyerGuard &)
Implementation of converter for pair<> conversion.
Definition: static_set.hpp:377
const type_info & GetDstTypeInfo(void) const THROWS_NONE
Definition: static_set.hpp:383
const type_info & GetSrcTypeInfo(void) const THROWS_NONE
Definition: static_set.hpp:379
size_t GetDstTypeSize(void) const THROWS_NONE
Definition: static_set.hpp:391
void Convert(void *dst_ptr, const void *src_ptr) const
Definition: static_set.hpp:399
size_t GetSrcTypeSize(void) const THROWS_NONE
Definition: static_set.hpp:387
void Destroy(void *dst) const THROWS_NONE
Definition: static_set.hpp:395
Implementation of converter for a single-object conversion.
Definition: static_set.hpp:301
const type_info & GetSrcTypeInfo(void) const THROWS_NONE
Definition: static_set.hpp:303
size_t GetDstTypeSize(void) const THROWS_NONE
Definition: static_set.hpp:315
const type_info & GetDstTypeInfo(void) const THROWS_NONE
Definition: static_set.hpp:307
size_t GetSrcTypeSize(void) const THROWS_NONE
Definition: static_set.hpp:311
void Convert(void *dst, const void *src) const
Definition: static_set.hpp:323
void Destroy(void *dst) const THROWS_NONE
Definition: static_set.hpp:319
class CStaticArraySet<> is an array adaptor that provides an STLish interface to statically-defined a...
Definition: static_set.hpp:561
const_iterator m_End
Definition: static_set.hpp:811
CStaticArraySearchBase(const value_type(&arr)[Size], const char *file, int line, NStaticArray::ECopyWarn warn)
Default constructor.
Definition: static_set.hpp:582
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.
Definition: static_set.hpp:717
difference_type index_of(const key_type &key) const
Return the index of the indicated element, or eNpos if the element is not found.
Definition: static_set.hpp:708
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.
Definition: static_set.hpp:673
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.
Definition: static_set.hpp:680
CStaticArraySearchBase(const Type *array_ptr, size_type array_size, const char *file, int line, NStaticArray::ECopyWarn warn)
Default constructor.
Definition: static_set.hpp:604
const_iterator end() const
Return the end of the controlled sequence.
Definition: static_set.hpp:647
pair_base_member< value_compare, const_iterator > m_Begin
Definition: static_set.hpp:810
getter::mapped_type mapped_type
Definition: static_set.hpp:570
getter::value_type value_type
Definition: static_set.hpp:568
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.
Definition: static_set.hpp:696
const value_type * const_iterator
Definition: static_set.hpp:574
const_iterator begin() const
Return the start of the controlled sequence.
Definition: static_set.hpp:641
bool empty() const
Return true if the container is empty.
Definition: static_set.hpp:653
void(* TDeallocateFunc)(const_iterator &begin, const_iterator &end)
Definition: static_set.hpp:806
getter::key_type key_type
Definition: static_set.hpp:569
KeyValueGetter getter
Definition: static_set.hpp:567
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.
Definition: static_set.hpp:613
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...
Definition: static_set.hpp:786
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...
Definition: static_set.hpp:666
TDeallocateFunc m_DeallocateFunc
Definition: static_set.hpp:812
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.
Definition: static_set.hpp:734
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.
Definition: static_set.hpp:758
const key_compare & key_comp() const
Definition: static_set.hpp:635
~CStaticArraySearchBase(void)
Destructor.
Definition: static_set.hpp:623
const value_compare & value_comp() const
Definition: static_set.hpp:630
NStaticArray::PLessByKey< getter, key_compare > value_compare
Definition: static_set.hpp:572
CStaticArraySearchBase(const value_type(&arr)[Size], const key_compare &comp, const char *file, int line, NStaticArray::ECopyWarn warn)
Constructor to initialize comparator object.
Definition: static_set.hpp:591
const value_type & const_reference
Definition: static_set.hpp:573
size_type count(const key_type &key) const
Return the count of the elements in the sequence.
Definition: static_set.hpp:688
bool x_Bad(const key_type &key, const_iterator iter) const
Definition: static_set.hpp:814
size_type size() const
Return number of elements in the container.
Definition: static_set.hpp:659
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.
Definition: static_set.hpp:845
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.
Definition: static_set.hpp:866
TBase::const_iterator const_iterator
Definition: static_set.hpp:828
TBase::size_type size_type
Definition: static_set.hpp:829
CStaticArraySet(const Type *array_ptr, size_t array_size, const char *file, int line, NStaticArray::ECopyWarn warn=NStaticArray::eCopyWarn_default)
default constructor.
Definition: static_set.hpp:857
TBase::key_compare key_compare
Definition: static_set.hpp:830
CStaticArraySearchBase< NStaticArray::PKeyValueSelf< KeyType >, KeyCompare > TBase
Definition: static_set.hpp:825
TBase::value_type value_type
Definition: static_set.hpp:827
CStaticArraySet(const value_type(&arr)[Size], const char *file, int line, NStaticArray::ECopyWarn warn=NStaticArray::eCopyWarn_default)
default constructor.
Definition: static_set.hpp:836
Helper class for single object conversion from static type to work type.
Definition: static_set.hpp:168
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)
Definition: static_set.hpp:159
static const mapped_type & get_mapped(const value_type &value)
Definition: static_set.hpp:155
static const key_type & get_key(const value_type &value)
Definition: static_set.hpp:151
value_type::second_type mapped_type
Definition: static_set.hpp:145
static const key_type & get_key(const key_type &key)
Definition: static_set.hpp:147
value_type::first_type key_type
Definition: static_set.hpp:144
value_type mapped_type
Definition: static_set.hpp:122
static const mapped_type & get_mapped(const value_type &value)
Definition: static_set.hpp:128
static const key_type & get_key(const value_type &value)
Definition: static_set.hpp:124
static mapped_type & get_mapped(value_type &value)
Definition: static_set.hpp:132
value_type key_type
Definition: static_set.hpp:121
Include a standard set of the NCBI C++ Toolkit most basic headers.
const first_type & first() const
Definition: ncbimisc.hpp:269
#define NCBI_DEPRECATED_CTOR(decl)
Macro used to mark a constructor as deprecated.
Definition: ncbimisc.hpp:1209
const second_type & second() const
Definition: ncbimisc.hpp:278
#define _DEBUG_ARG(arg)
Definition: ncbidbg.hpp:134
#define THROWS_NONE
Do not use 'throw' dynamic exception specification for C++11 compilers.
Definition: ncbiexpt.hpp:74
const CVect2< U > & v2
Definition: globals.hpp:440
#define NCBI_PARAM_DECL_EXPORT(expname, type, section, name)
Same as NCBI_PARAM_DECL but with export specifier (e.g.
Definition: ncbi_param.hpp:164
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
Definition of all error codes used in util (xutil.lib).
FILE * file
int i
double value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:228
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
Definition: pointer.h:1227
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2107
int ssize_t
Definition: ncbiconf_msvc.h:93
Multi-threading – mutexes; rw-locks; semaphore.
IObjectConverter * MakeConverter(DstType *, SrcType *)
Definition: static_set.hpp:332
ECopyWarn
Definition: static_set.hpp:182
@ eCopyWarn_default
Definition: static_set.hpp:183
@ eCopyWarn_hide
Definition: static_set.hpp:185
@ eCopyWarn_show
Definition: static_set.hpp:184
IObjectConverter * MakePairConverter(DstType *, SrcType *)
Definition: static_set.hpp:419
void CheckStaticType(const Type *, const char *, int)
Template for checking if the static array type is MT-safe, i.e.
Definition: static_set.hpp:446
STATIC_ARRAY_COPY_WARNING
Definition: static_set.hpp:72
typedef NCBI_PARAM_TYPE(NCBI, STATIC_ARRAY_COPY_WARNING) TParamStaticArrayCopyWarning
STATIC_ARRAY_UNSAFE_TYPE_WARNING
Definition: static_set.hpp:78
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...
Definition: static_set.cpp:118
END_NAMESPACE(NStaticArray)
NCBI_XUTIL_EXPORT
Parameter to control printing diagnostic message about conversion of static array data from a differe...
Definition: static_set.hpp:72
void ReportIncorrectOrder(size_t curr_index, const char *file, int line)
Log error message about wrong order of elements in array and abort.
Definition: static_set.cpp:142
NCBI
Definition: static_set.hpp:72
BEGIN_NAMESPACE(NStaticArray)
Namespace for static array templates' implementation.
getter::value_type value_type
Definition: static_set.hpp:90
getter::key_type key_type
Definition: static_set.hpp:91
KeyValueGetter getter
Definition: static_set.hpp:89
KeyCompare key_compare
Definition: static_set.hpp:92
PLessByKey(const key_compare &comp)
Definition: static_set.hpp:98
const key_compare & key_comp() const
Definition: static_set.hpp:103
bool operator()(const Type1 &v1, const Type2 &v2) const
Definition: static_set.hpp:109
Template structure SStaticPair is simlified replacement of STL pair<> Main reason of introducing this...
Definition: static_set.hpp:60
SecondType second_type
Definition: static_set.hpp:62
first_type first
Definition: static_set.hpp:64
FirstType first_type
Definition: static_set.hpp:61
second_type second
Definition: static_set.hpp:65
#define _ASSERT
#define Type
const value_slice::CValueConvert< value_slice::SRunTimeCP, FROM > Convert(const FROM &value)
static const char * type_name(CS_INT value)
Definition: will_convert.c:122
void free(voidpf ptr)
Modified on Thu Apr 25 08:19:44 2024 by modify_doxy.py rev. 669887