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

Go to the repository for this file.

1 #ifndef CORELIB___NCBIMISC__HPP
2 #define CORELIB___NCBIMISC__HPP
3 
4 /* $Id: ncbimisc.hpp 107539 2026-09-28 14:16:57Z 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  * Author: Denis Vakatov, Eugene Vasilchenko
30  *
31  *
32  */
33 
34 /// @file ncbimisc.hpp
35 /// Miscellaneous common-use basic types and functionality
36 
37 
38 #include <corelib/ncbidbg.hpp>
39 #include <stdlib.h>
40 #ifdef HAVE_SYS_TYPES_H
41 # include <sys/types.h>
42 #endif
43 
44 #if __has_include(<format>)
45 # include <format>
46 #endif
47 
48 #if !defined(HAVE_NULLPTR) && !defined(nullptr)
49 # define nullptr NULL
50 #endif
51 
52 
53 /** @addtogroup AppFramework
54  *
55  * @{
56  */
57 
58 
59 #ifndef NCBI_ESWITCH_DEFINED
60 #define NCBI_ESWITCH_DEFINED
61 
62 extern "C" {
63 
64 /*
65  * ATTENTION! Do not change this enumeration!
66  *
67  * It must always be kept in sync with its plain C counterpart defined in
68  * "connect/ncbi_types.h". If you absolutely(sic!) need to alter this
69  * type, please apply equivalent changes to both definitions.
70  */
71 
72 /** Aux. enum to set/unset/default various features.
73  */
74 typedef enum ENcbiSwitch {
75  eOff = 0,
76  eOn,
77  eDefault
79 
80 } // extern "C"
81 
82 #endif //!NCBI_ESWITCH_DEFINED
83 
84 
85 #ifndef NCBI_EOWNERSHIP_DEFINED
86 #define NCBI_EOWNERSHIP_DEFINED
87 
88 extern "C" {
89 
90 /*
91  * ATTENTION! Do not change this enumeration!
92  *
93  * It must always be kept in sync with its plain C counterpart defined in
94  * "connect/ncbi_types.h". If you absolutely(sic!) need to alter this
95  * type, please apply equivalent changes to both definitions.
96  */
97 
98 /** Ownership relations between objects.
99  *
100  * Can be used to define or transfer ownership of objects.
101  * For example, specify if a CSocket object owns its underlying SOCK object.
102  */
103 typedef enum ENcbiOwnership {
104  eNoOwnership, /** No ownership assumed */
105  eTakeOwnership /** An object can take ownership of another */
107 
108 } // extern "C"
109 
110 #endif //!NCBI_EOWNERSHIP_DEFINED
111 
112 
114 
115 
116 /// Whether a value is nullable.
117 enum ENullable {
118  eNullable, ///< Value can be null
119  eNotNullable ///< Value cannot be null
120 };
121 
122 
123 /// Signedness of a value.
124 enum ESign {
125  eNegative = -1, ///< Value is negative
126  eZero = 0, ///< Value is zero
127  ePositive = 1 ///< Value is positive
128 };
129 
130 
131 /// Enumeration to represent a tristate value.
132 enum ETriState {
133  eTriState_Unknown = -1, ///< The value is indeterminate
134  eTriState_False = 0, ///< The value is equivalent to false/no
135  eTriState_True = 1, ///< The value is equivalent to true/yes
136 };
137 
138 
139 /// Whether to truncate/round a value.
140 enum ERound {
141  eTrunc, ///< Value must be truncated
142  eRound ///< Value must be rounded
143 };
144 
145 
146 /// Whether to follow symbolic links (also known as shortcuts or aliases)
148  eIgnoreLinks, ///< Do not follow symbolic links
149  eFollowLinks ///< Follow symbolic links
150 };
151 
152 
153 /// Whether to normalize a path
155  eNormalizePath, ///< Normalize a path
156  eNotNormalizePath ///< Do not normalize a path
157 };
158 
159 
160 /// Interrupt on signal mode
161 ///
162 /// On UNIX some functions can be interrupted by a signal and EINTR errno
163 /// value. We can restart or cancel its execution.
165  eInterruptOnSignal, ///< Cancel operation if interrupted by a signal
166  eRestartOnSignal ///< Restart operation if interrupted by a signal
167 };
168 
169 
170 /// Can the action be retried?
172  eRetriable_No, ///< It makes no sense to retry the action
173  eRetriable_Unknown, ///< It is unknown if the action can succeed if retried
174  eRetriable_Yes ///< It makes sense to try again
175 };
176 
177 
178 /////////////////////////////////////////////////////////////////////////////
179 /// Support for safe bool operators
180 /////////////////////////////////////////////////////////////////////////////
181 
182 
183 /// Low level macro for declaring safe bool operator.
184 #define DECLARE_SAFE_BOOL_METHOD(Expr) \
185  struct SSafeBoolTag { \
186  void SafeBoolTrue(SSafeBoolTag*) {} \
187  }; \
188  typedef void (SSafeBoolTag::*TBoolType)(SSafeBoolTag*); \
189  operator TBoolType() const { \
190  return (Expr)? &SSafeBoolTag::SafeBoolTrue: 0; \
191  } \
192  private: \
193  bool operator==(TBoolType) const; \
194  bool operator!=(TBoolType) const; \
195  public: \
196  friend struct SSafeBoolTag
197 
198 
199 /// Declaration of safe bool operator from boolean expression.
200 /// Actual operator declaration will be:
201 /// operator TBoolType(void) const;
202 /// where TBoolType is a typedef convertible to bool (member pointer).
203 #define DECLARE_OPERATOR_BOOL(Expr) \
204  DECLARE_SAFE_BOOL_METHOD(Expr)
205 
206 
207 /// Declaration of safe bool operator from pointer expression.
208 /// Actual operator declaration will be:
209 /// operator bool(void) const;
210 #define DECLARE_OPERATOR_BOOL_PTR(Ptr) \
211  DECLARE_OPERATOR_BOOL((Ptr) != 0)
212 
213 
214 /// Declaration of safe bool operator from CRef<>/CConstRef<> expression.
215 /// Actual operator declaration will be:
216 /// operator bool(void) const;
217 #define DECLARE_OPERATOR_BOOL_REF(Ref) \
218  DECLARE_OPERATOR_BOOL((Ref).NotNull())
219 
220 /// Override the DECLARE_OPERATOR_BOOL, etc.
221 /// from an ancestor class. This is needed because sometimes you can't just
222 /// use DECLARE_OPERATOR_BOOL due to cases such as the ancestor class
223 /// being privately inherited from.
224 #define OVERRIDE_OPERATOR_BOOL(TAncestorClass, NewBoolExpr) \
225  using TAncestorClass::TBoolType; \
226  using TAncestorClass::SSafeBoolTag; \
227  operator TBoolType() const { \
228  return (NewBoolExpr)? & SSafeBoolTag::SafeBoolTrue : 0; \
229  }
230 
231 /// Template used for empty base class optimization.
232 /// See details in the August '97 "C++ Issue" of Dr. Dobb's Journal
233 /// Also available from http://www.cantrip.org/emptyopt.html
234 /// We store usually empty template argument class together with data member.
235 /// This template is much like STL's pair<>, but the access to members
236 /// is done though methods first() and second() returning references
237 /// to corresponding members.
238 /// First template argument is represented as private base class,
239 /// while second template argument is represented as private member.
240 /// In addition to constructor taking two arguments,
241 /// we add constructor for initialization of only data member (second).
242 /// This is useful since usually first type is empty and doesn't require
243 /// non-trivial constructor.
244 /// We do not define any comparison functions as this template is intented
245 /// to be used internally within another templates,
246 /// which themselves should provide any additional functionality.
247 
248 template<class Base, class Member>
249 class pair_base_member : private Base
250 {
251 public:
252  typedef Base base_type;
253  typedef Base first_type;
254  typedef Member member_type;
255  typedef Member second_type;
256 
258  : base_type(), m_Member()
259  {
260  }
261 
262  explicit pair_base_member(const member_type& member_value)
263  : base_type(), m_Member(member_value)
264  {
265  }
266 
267  explicit pair_base_member(member_type&& member_value) noexcept
268  : base_type(), m_Member(std::move(member_value))
269  {
270  }
271 
272  explicit pair_base_member(const first_type& first_value,
273  const second_type& second_value)
274  : base_type(first_value), m_Member(second_value)
275  {
276  }
277 
278  const first_type& first() const noexcept
279  {
280  return *this;
281  }
282  first_type& first() noexcept
283  {
284  return *this;
285  }
286 
287  const second_type& second() const noexcept
288  {
289  return m_Member;
290  }
291  second_type& second() noexcept
292  {
293  return m_Member;
294  }
295 
297  {
298  if (static_cast<void*>(&first()) != static_cast<void*>(&second())){
299  // work around an IBM compiler bug which causes it to perform
300  // a spurious 1-byte swap, yielding mixed-up values.
301  swap(first(), p.first());
302  }
303  swap(second(), p.second());
304  }
305 
306 private:
308 };
309 
310 
311 /// Template used to replace bool type arguments with some strict equivalent.
312 /// This allow to prevent compiler to do an implicit casts from other types
313 /// to bool. "TEnum" should be an enumerated type with two values:
314 /// - negative (FALSE/OFF) should have value 0
315 // - positive (TRUE/ON) have value 1.
316 
317 template <class TEnum>
319 {
320 public:
321  // Constructors
324 
325  /// Operator bool
326  operator bool() const { return m_Value; }
327  /// Operator enum
328  operator TEnum () const { return TEnum(m_Value); }
329 
330 private:
331  bool m_Value;
332 
333 private:
334  // Disable implicit conversions from/to other types
335  CBoolEnum(char*);
336  CBoolEnum(int);
337  CBoolEnum(unsigned int);
338  template <class T> CBoolEnum(T);
339 
340  operator int() const;
341  operator unsigned int() const;
342 };
343 
344 
345 
346 /// Functor template for allocating object.
347 template<class X>
348 struct Creater
349 {
350  /// Default create function.
351  static X* Create(void)
352  { return new X; }
353 };
354 
355 /// Functor template for deleting object.
356 template<class X>
357 struct Deleter
358 {
359  /// Default delete function.
360  static void Delete(X* object)
361  { delete object; }
362 };
363 
364 /// Functor template for deleting array of objects.
365 template<class X>
367 {
368  /// Array delete function.
369  static void Delete(X* object)
370  { delete[] object; }
371 };
372 
373 /// Functor template for the C language deallocation function, free().
374 template<class X>
375 struct CDeleter
376 {
377  /// C Language deallocation function.
378  static void Delete(X* object)
379  { free(object); }
380 };
381 
382 
383 
384 /////////////////////////////////////////////////////////////////////////////
385 ///
386 /// AutoPtr --
387 ///
388 /// Define an "auto_ptr" like class that can be used inside STL containers.
389 ///
390 /// The Standard auto_ptr template from STL doesn't allow the auto_ptr to be
391 /// put in STL containers (list, vector, map etc.). The reason for this is
392 /// the absence of copy constructor and assignment operator.
393 /// We decided that it would be useful to have an analog of STL's auto_ptr
394 /// without this restriction - AutoPtr.
395 ///
396 /// Due to the nature of AutoPtr its copy constructor and assignment operator
397 /// modify the state of the source AutoPtr object as it transfers the ownership
398 /// to the target AutoPtr object. Also, we added possibility to redefine the
399 /// way pointer will be deleted: the second argument of the template allows
400 /// pointers from "malloc" in AutoPtr, or you can use "ArrayDeleter" (see
401 /// above) to properly delete an array of objects using "delete[]" instead
402 /// of "delete". By default, the internal pointer is deleted by the C++
403 /// "delete" operator.
404 ///
405 /// @sa
406 /// Deleter(), ArrayDeleter(), CDeleter()
407 
408 #define DEPRECATE_AUTO_PTR 1
409 
410 template< class X, class Del = Deleter<X> >
411 class AutoPtr
412 {
413 public:
414  typedef X element_type; ///< Define element type.
415  typedef Del deleter_type; ///< Alias for template argument.
416 
417  /// Constructor.
418  AutoPtr() noexcept
419  : m_Ptr(nullptr), m_Data(false)
420  { }
421 
422  /// Constructor.
423  AutoPtr(element_type* p) noexcept
424  : m_Ptr(p), m_Data(true)
425  { }
426 
427  /// Constructor.
428  AutoPtr(element_type* p, const deleter_type& deleter) noexcept
429  : m_Ptr(p), m_Data(deleter, true)
430  { }
431 
432  /// Constructor, own the pointed object if ownership == eTakeOwnership
433  AutoPtr(element_type* p, EOwnership ownership) noexcept
434  : m_Ptr(p), m_Data(ownership != eNoOwnership)
435  { }
436 
437  /// Constructor, own the pointed object if ownership == eTakeOwnership
438  AutoPtr(element_type* p, const deleter_type& deleter, EOwnership ownership) noexcept
439  : m_Ptr(p), m_Data(deleter, ownership != eNoOwnership)
440  { }
441 
442 #if DEPRECATE_AUTO_PTR
443  /// Move constructor.
444  AutoPtr(AutoPtr<X, Del>&& p) noexcept
445  : m_Data(p.m_Data) // copy ownership info first
446  {
447  m_Ptr = p.release(); // then the pointer
448  }
449 
451 #endif
452  /// Copy constructor.
453  AutoPtr(const AutoPtr<X, Del>& p) noexcept
454  : m_Data(p.m_Data) // copy ownership info first
455  {
456  m_Ptr = p.x_Release(); // then the pointer
457  }
458 
459  /// Destructor.
460  ~AutoPtr(void)
461  {
462  reset();
463  }
464 
465 #if DEPRECATE_AUTO_PTR
466  /// Move assignment operator.
468  {
469  if (this != &p) {
470  auto data = p.m_Data; // copy ownership info first
471  reset(p.release()); // then the pointer
472  m_Data = data;
473  }
474  return *this;
475  }
476 
478 #endif
479  /// Assignment operator.
481  {
482  if (this != &p) {
483  auto data = p.m_Data; // copy ownership info first
484  reset(p.x_Release()); // then the pointer
485  m_Data = data;
486  }
487  return *this;
488  }
489 
490  /// Assignment operator.
492  {
493  reset(p);
494  return *this;
495  }
496 
497  /// Bool operator for use in if() clause.
499 
500  // Standard getters.
501 
502  /// Dereference operator.
503  element_type& operator* (void) const noexcept { return *m_Ptr; }
504 
505  /// Reference operator.
506  element_type* operator->(void) const noexcept { return m_Ptr; }
507 
508  /// Get pointer.
509  element_type* get (void) const noexcept { return m_Ptr; }
510 
511  /// Release will release ownership of pointer to caller.
512  element_type* release(void) noexcept
513  {
514  auto ptr = m_Ptr;
515  m_Data.second() = false;
516 #if DEPRECATE_AUTO_PTR > 1
517  m_Ptr = nullptr; // strictly conforming release() resets the ptr
518 #endif
519  return ptr;
520  }
521 
522  /// Reset will delete the old pointer (if owned)
523  void reset() noexcept
524  {
525  if ( IsOwned() ) {
526  m_Data.first().Delete(release());
527  }
528  m_Ptr = nullptr;
529  m_Data.second() = false;
530  }
531 
532  /// Reset will delete the old pointer (if owned), set content to the new
533  /// value, and assume the ownership upon the new pointer by default.
534  void reset(element_type* p, EOwnership ownership = eTakeOwnership) noexcept
535  {
536  if ( m_Ptr != p ) {
537  reset();
538  }
539  if ( p ) {
540  m_Ptr = p;
541  m_Data.second() = ownership != eNoOwnership;
542  }
543  }
544 
545  void Swap(AutoPtr<X, Del>& a) noexcept
546  {
547  swap(m_Ptr, a.m_Ptr);
548  swap(m_Data, a.m_Data);
549  }
550 
551  bool IsOwned(void) const noexcept { return m_Ptr && m_Data.second(); }
552 
553 private:
554  element_type* m_Ptr; ///< Internal pointer representation.
556 
557  /// Release for const object, used in deprecated methods
558  element_type* x_Release(void) const noexcept
559  {
560  return const_cast<AutoPtr<X, Del>*>(this)->release();
561  }
562 };
563 
564 
565 /////////////////////////////////////////////////////////////////////////////
566 ///
567 /// AutoArray --
568 ///
569 /// "AutoPtr" like class for using with arrays
570 ///
571 /// vector<> template comes with a performance penalty, since it always
572 /// initializes its content. This template is not a vector replacement,
573 /// it's a version of AutoPtr<> tuned for array pointers. For convenience
574 /// it defines array style access operator [] and size based contructor.
575 ///
576 /// @sa AutoPtr
577 ///
578 
579 template< class X, class Del = ArrayDeleter<X> >
581 {
582 public:
583  typedef X element_type; ///< Define element type.
584  typedef Del deleter_type; ///< Alias for template argument.
585 
586 public:
587 
588  /// Construct the array using C++ new[] operator
589  /// @note In this case you should use ArrayDeleter<> or compatible
590  explicit AutoArray(size_t size) noexcept
591  : m_Ptr(new element_type[size]), m_Data(true)
592  { }
593 
594  AutoArray() noexcept
595  : m_Ptr(nullptr), m_Data(false)
596  { }
597 
598  explicit AutoArray(element_type* p) noexcept
599  : m_Ptr(p), m_Data(true)
600  { }
601 
602  AutoArray(element_type* p, const deleter_type& deleter) noexcept
603  : m_Ptr(p), m_Data(deleter, true)
604  { }
605 
606 #if DEPRECATE_AUTO_PTR
607  /// Move constructor
609  : m_Data(p.m_Data)
610  {
611  m_Ptr = p.release();
612  }
613 
615 #endif
616  /// Copy constructor
617  AutoArray(const AutoArray<X, Del>& p) noexcept
618  : m_Data(p.m_Data)
619  {
620  m_Ptr = p.x_Release();
621  }
622 
624  {
625  reset();
626  }
627 
628 #if DEPRECATE_AUTO_PTR
629  /// Move assignment operator.
631  {
632  if (this != &p) {
633  auto data = p.m_Data;
634  reset(p.release());
635  m_Data = data;
636  }
637  return *this;
638  }
639 
641 #endif
642  /// Assignment operator.
644  {
645  if (this != &p) {
646  auto data = p.m_Data;
647  reset(p.x_Release());
648  m_Data = data;
649  }
650  return *this;
651  }
652 
653  /// Assignment operator.
655  {
656  reset(p);
657  return *this;
658  }
659 
660  /// Bool operator for use in if() clause.
662 
663  /// Get pointer.
664  element_type* get (void) const noexcept { return m_Ptr; }
665 
666  /// Release will release ownership of pointer to caller.
667  element_type* release(void) noexcept
668  {
669  auto ptr = m_Ptr;
670  m_Data.second() = false;
671 #if DEPRECATE_AUTO_PTR > 1
672  m_Ptr = nullptr; // strictly conforming release() resets the ptr
673 #endif
674  return ptr;
675  }
676 
677  /// Array style dereference (returns value)
678  const element_type& operator[](size_t pos) const noexcept { return m_Ptr[pos]; }
679 
680  /// Array style dereference (returns reference)
681  element_type& operator[](size_t pos) noexcept { return m_Ptr[pos]; }
682 
683  /// Reset will delete the old pointer.
684  void reset() noexcept
685  {
686  if ( IsOwned() ) {
687  m_Data.first().Delete(release());
688  }
689  m_Ptr = nullptr;
690  m_Data.second() = false;
691  }
692 
693  /// Reset will delete the old pointer, set content to the new value,
694  /// and assume the ownership upon the new pointer.
695  void reset(element_type* p) noexcept
696  {
697  if (m_Ptr != p) {
698  reset();
699  }
700  if ( p ) {
701  m_Ptr = p;
702  m_Data.second() = true;
703  }
704  }
705 
706  void Swap(AutoPtr<X, Del>& a) noexcept
707  {
708  swap(m_Ptr, a.m_Ptr);
709  swap(m_Data, a.m_Data);
710  }
711 
712  bool IsOwned(void) const noexcept { return m_Ptr && m_Data.second(); }
713 
714 private:
715  /// Release for const object, used in deprecated methods
716  element_type* x_Release(void) const noexcept
717  {
718  return const_cast<AutoArray<X, Del>*>(this)->release();
719  }
720 
721 private:
724 };
725 
726 
727 
728 /////////////////////////////////////////////////////////////////////////////
729 ///
730 /// CNullable --
731 ///
732 /// A value whith 'unassigned' state.
733 ///
734 
735 
736 /// Define "null" pointer value.
737 #ifdef __cpp_using_enum
738 enum class ENull {
739  null = 0
740 };
741 
742 using enum ENull;
743 #else
744 enum ENull {
745  null = 0
746 };
747 #endif
748 
749 
750 // Default callback for null value - throws CCoreException.
751 NCBI_NORETURN NCBI_XNCBI_EXPORT void g_ThrowOnNull(void);
752 
753 // Default callback template.
754 template <class TValue>
756 {
757  TValue operator()(void) const
758  {
759  g_ThrowOnNull();
760  }
761 };
762 
763 
764 /// Template class allowing to store a value or null (unassigned) state.
765 /// TNullToValue functor can be used to perform an action when the value
766 /// is requested from a null object. By default CCoreException is thrown.
767 /// To perform other actions (e.g. provide a default value) the functor
768 /// must define 'TValue operator()(void) const' method.
769 /// @deprecated: Use std::optional<> instead.
770 template <class TValue, class TNullToValue = SThrowOnNull<TValue> >
772 //
773 // DEPRECATED! - Use std::optional<> instead.
774 //
775 {
776 public:
777  /// Create an empty nullable.
778  CNullable(ENull = null)
779  : m_IsNull(true) {}
780  /// Initialize nullable with a specific value.
781  CNullable(TValue value)
782  : m_IsNull(false), m_Value(value) {}
783 
784  /// Check if the object is unassigned.
785  bool IsNull(void) const
786  {
787  return m_IsNull;
788  }
789 
790  /// Get nullable value.
791  /// If NULL, then call TNullToValue and use the value return by the latter.
792  /// @attention The default implementation of TNullToValue (g_ThrowOnNull)
793  /// throws an exception!
794  operator TValue(void) const
795  {
796  return m_IsNull ? TNullToValue()() : m_Value;
797  }
798 
799  /// Get a const reference to the current value. If NULL, the reference is
800  /// a copy of the default value or throw (depending on TNullToValue
801  /// implementation). In any case the IsNull state is unchanged.
802  const TValue& GetValue(void) const
803  {
804  if ( m_IsNull ) {
805  const_cast<TValue&>(m_Value) = TNullToValue()();
806  }
807  return m_Value;
808  }
809 
810  /// Get a non-const reference to the value. If NULL, try to initialize this
811  /// instance with the default value or throw.
812  TValue& SetValue(void)
813  {
814  if ( m_IsNull ) {
815  *this = TNullToValue()();
816  }
817  return m_Value;
818  }
819 
820  /// Assign a value to the nullable.
822  {
823  m_IsNull = false; m_Value = value;
824  return *this;
825  }
826 
827  /// Reset nullable to unassigned state.
828  CNullable& operator= (ENull /*null_value*/)
829  {
830  m_IsNull = true;
831  return *this;
832  }
833 
834 private:
835  bool m_IsNull;
836  TValue m_Value;
837 };
838 
839 template <class TValue, class TNullToValue = SThrowOnNull<TValue> >
841 {
842  return (l.IsNull() && r.IsNull()) ||
843  (!l.IsNull() && !r.IsNull() && l.GetValue() == r.GetValue());
844 }
845 template <class TValue, class TNullToValue = SThrowOnNull<TValue> >
847 {
848  return !operator==(l, r);
849 }
850 
851 // "min" and "max" templates
852 //
853 
854 // Always get rid of the old non-conformant min/max macros
855 #ifdef min
856 # undef min
857 #endif
858 #ifdef max
859 # undef max
860 #endif
861 
862 
863 
864 // strdup()
865 //
866 
867 #ifndef HAVE_STRDUP
868 /// Supply string duplicate function, if one is not defined.
869 extern char* strdup(const char* str);
870 #endif
871 
872 
873 
874 // ITERATE
875 // NON_CONST_ITERATE
876 // REVERSE_ITERATE
877 // NON_CONST_REVERSE_ITERATE
878 // ERASE_ITERATE
879 //
880 // Useful macros to write 'for' statements with the STL container iterator as
881 // a variable.
882 //
883 
884 // *ITERATE helper to enforce constness of the container reference
885 template<typename Type>
886 inline const Type& s_ITERATE_ConstRef(const Type& obj)
887 {
888  return obj;
889 }
890 #define ITERATE_CONST(Cont) ncbi::s_ITERATE_ConstRef(Cont)
891 
892 // *ITERATE helper to verify that the container isn't a temporary object
893 #ifdef _DEBUG
894 template<typename Type>
895 inline bool s_ITERATE_SameObject(const Type& obj1, const Type& obj2)
896 {
897  return &obj1 == &obj2;
898 }
899 # define ITERATE_BEGIN(Cont, Begin) \
900  (NCBI_ASSERT_EXPR(ncbi::s_ITERATE_SameObject(Cont, Cont), \
901  "rvalue container in *ITERATE"), (Cont).Begin())
902 #else
903 # define ITERATE_BEGIN(Cont, Begin) ((Cont).Begin())
904 #endif
905 
906 // *ITERATE helper macro to declare iterator variable
907 #if 0 && defined(NCBI_HAVE_CXX11)
908 # define ITERATE_VAR(Type) auto
909 #else
910 # define ITERATE_VAR(Type) Type
911 #endif
912 
913 /// ITERATE macro to sequence through container elements.
914 #define ITERATE(Type, Var, Cont) \
915  for ( ITERATE_VAR(Type::const_iterator) \
916  Var = ITERATE_BEGIN(ITERATE_CONST(Cont), begin), \
917  NCBI_NAME2(Var,_end) = ITERATE_CONST(Cont).end(); \
918  Var != NCBI_NAME2(Var,_end); ++Var )
919 
920 /// Non constant version of ITERATE macro.
921 #define NON_CONST_ITERATE(Type, Var, Cont) \
922  for ( ITERATE_VAR(Type::iterator) Var = ITERATE_BEGIN(Cont, begin); \
923  Var != (Cont).end(); ++Var )
924 
925 /// ITERATE macro to reverse sequence through container elements.
926 #define REVERSE_ITERATE(Type, Var, Cont) \
927  for ( ITERATE_VAR(Type::const_reverse_iterator) \
928  Var = ITERATE_BEGIN(ITERATE_CONST(Cont), rbegin), \
929  NCBI_NAME2(Var,_end) = ITERATE_CONST(Cont).rend(); \
930  Var != NCBI_NAME2(Var,_end); ++Var )
931 
932 /// Non constant version of REVERSE_ITERATE macro.
933 #define NON_CONST_REVERSE_ITERATE(Type, Var, Cont) \
934  for ( ITERATE_VAR(Type::reverse_iterator) \
935  Var = ITERATE_BEGIN(Cont, rbegin); \
936  Var != (Cont).rend(); ++Var )
937 
938 /// Non-constant version with ability to erase current element, if container
939 /// permits. Use only on containers, for which erase do not ruin other
940 /// iterators into the container, e.g. map, list, but NOT vector.
941 /// See also VECTOR_ERASE
942 #define ERASE_ITERATE(Type, Var, Cont) \
943  for ( ITERATE_VAR(Type::iterator) Var = ITERATE_BEGIN(Cont, begin), \
944  NCBI_NAME2(Var,_next) = Var; \
945  (Var = NCBI_NAME2(Var,_next)) != (Cont).end() && \
946  (++NCBI_NAME2(Var,_next), true); )
947 
948 /// Use this macro inside body of ERASE_ITERATE cycle to erase from
949 /// vector-like container. Plain erase() call would invalidate Var_next
950 /// iterator and would make the cycle controlling code to fail.
951 #define VECTOR_ERASE(Var, Cont) (NCBI_NAME2(Var,_next) = (Cont).erase(Var))
952 
953 /// The body of the loop will be run with Var equal to false and then true.
954 /// The seemlingly excessive complexity of this macro is to get around a couple of limitations:
955 /// * A bool only has two states, so it's not possible to represent the complete state space
956 /// of (first iteration, second iteration, done) without another variable.
957 /// * The variables declared in a for-loop's first part must be of the same type, so
958 /// the other variable has to be a bool instead of something more convenient such as
959 /// as a loop-counter.
960 #define ITERATE_BOTH_BOOL_VALUES(BoolVar) \
961  for( bool BoolVar##BOTH_BOOL_VALUES_DONE##__LINE__ = false, BoolVar = false; ! BoolVar##BOTH_BOOL_VALUES_DONE##__LINE__ ; BoolVar##BOTH_BOOL_VALUES_DONE##__LINE__ = BoolVar, BoolVar = true )
962 
963 /// idx loops from 0 (inclusive) to up_to (exclusive)
964 #define ITERATE_0_IDX(idx, up_to) \
965  for( TSeqPos idx = 0; idx < up_to; ++idx )
966 
967 /// Just repeat the body of the loop num_iters times
968 #define ITERATE_SIMPLE(num_iters) \
969  ITERATE_0_IDX( _dummy_idx_94768308_##__LINE__, num_iters ) // the number has no significance; it is entirely random.
970 
971 /// Type for sequence locations and lengths.
972 ///
973 /// Use this typedef rather than its expansion, which may change.
974 typedef unsigned int TSeqPos;
975 
976 /// Define special value for invalid sequence position.
977 const TSeqPos kInvalidSeqPos = ((TSeqPos) (-1));
978 
979 
980 /// Type for signed sequence position.
981 ///
982 /// Use this type when and only when negative values are a possibility
983 /// for reporting differences between positions, or for error reporting --
984 /// though exceptions are generally better for error reporting.
985 /// Use this typedef rather than its expansion, which may change.
986 typedef int TSignedSeqPos;
987 
988 
989 /// Template class for strict ID types.
990 template<class TKey, class TStorage>
992 {
993 public:
994  typedef TStorage TId;
996 
997  CStrictId(void) : m_Id(0) {}
998  CStrictId(const TThis& other) : m_Id(other.m_Id) {}
999  TThis& operator=(const TThis& other) { m_Id = other.m_Id; return *this; }
1000 
1001  bool operator==(const TThis& id) const { return m_Id == id.m_Id; }
1002  bool operator!=(const TThis& id) const { return m_Id != id.m_Id; }
1003  bool operator<(const TThis& id) const { return m_Id < id.m_Id; }
1004  bool operator<=(const TThis& id) const { return m_Id <= id.m_Id; }
1005  bool operator>(const TThis& id) const { return m_Id > id.m_Id; }
1006  bool operator>=(const TThis& id) const { return m_Id >= id.m_Id; }
1007 
1008  TThis& operator++(void) { m_Id++; return *this; }
1009  TThis operator++(int) { TThis tmp = *this; m_Id++; return tmp; }
1010  TThis& operator--(void) { m_Id--; return *this; }
1011  TThis operator--(int) { TThis tmp = *this; m_Id--; return tmp; }
1012 
1013  TThis operator+(const TThis& id) const { return TThis(m_Id + id.m_Id); }
1014  TThis operator-(const TThis& id) const { return TThis(m_Id - id.m_Id); }
1015  TThis operator-(void) const { return TThis(-m_Id); }
1016 
1017  //template<typename T>
1018  //operator typename enable_if<is_same<T, bool>::value, bool>::type(void) const { return m_Id != 0; }
1019 
1020  TId Get(void) const { return m_Id; }
1021  void Set(TId id) { m_Id = id; }
1022  TId& Set(void) { return m_Id; }
1023 
1024 #if !defined(NCBI_TEST_APPLICATION)
1025  template<typename T>
1026  explicit CStrictId(T id, typename enable_if<is_same<T, TId>::value, T>::type = 0) : m_Id(id) {}
1027 private:
1028 #else
1029  template<typename T>
1030  CStrictId(T id, typename enable_if<is_arithmetic<T>::value, T>::type = 0) : m_Id(id) {}
1031  template<typename T>
1032  typename enable_if<is_arithmetic<T>::value, TThis>::type& operator=(T id) { m_Id = id; return *this; }
1033  template<typename T>
1034  typename enable_if<is_arithmetic<T>::value, bool>::type operator==(T id) const { return m_Id == id; }
1036  operator T(void) const { return static_cast<T>(m_Id); }
1037 #endif
1038 
1039 private:
1041 };
1042 
1043 template<class TKey, class TStorage>
1044 inline
1046 {
1047  return out << id.Get();
1048 }
1049 
1050 template<class TKey, class TStorage>
1051 inline
1053 {
1054  in >> id.Set();
1055  return in;
1056 }
1057 
1058 
1059 /// Type for sequence GI.
1060 ///
1061 /// Use this typedef rather than its expansion, which may change.
1062 
1063 //#define NCBI_INT4_GI
1064 //#define NCBI_STRICT_GI 1
1065 //#define NCBI_STRICT_ENTREZ_ID
1066 //#define NCBI_STRICT_TAX_ID
1067 
1068 
1069 #if defined(NCBI_INT4_GI)
1070 # ifdef NCBI_INT8_GI
1071 # error "Both NCBI_INT4_GI and NCBI_INT8_GI must not be defined!"
1072 # endif
1073 # ifdef NCBI_STRICT_GI
1074 # error "Both NCBI_INT4_GI and NCBI_STRICT_GI must not be defined!"
1075 # endif
1076 #elif !defined(NCBI_INT8_GI)
1077 # define NCBI_INT8_GI
1078 #endif
1079 
1080 #ifdef NCBI_TEST_STRICT_ENTREZ_ID
1081 // Allow strict TEntrezId test builds
1082 #define NCBI_STRICT_ENTREZ_ID
1083 #else
1084 // Temporary fix: disable strict TEntrezId
1085 # ifdef NCBI_STRICT_ENTREZ_ID
1086 # undef NCBI_STRICT_ENTREZ_ID
1087 # endif
1088 #endif
1089 
1090 #ifndef NCBI_STRICT_GI
1091 # undef NCBI_STRICT_ENTREZ_ID
1092 # undef NCBI_STRICT_TAX_ID
1093 #endif
1094 
1095 #ifdef NCBI_INT8_GI
1096 
1097 // Generic id type which needs to be the same size as GI.
1098 typedef Int8 TIntId;
1099 typedef Uint8 TUintId;
1100 
1101 #else // NCBI_INT8_GI
1102 
1103 typedef int TGi;
1104 typedef Int4 TIntId;
1105 typedef Uint4 TUintId;
1106 
1107 #endif
1108 
1109 
1110 /// Key structs must always be defined - they are used in aliasinfo.cpp
1112  typedef TIntId TId;
1113 };
1115  typedef TIntId TId;
1116 };
1118  typedef int TId;
1119 };
1120 
1121 
1122 #ifdef NCBI_STRICT_GI
1123 
1125 
1126 /// @deprecated: Use TGi/TEntrezId typedefs.
1128 
1129 #else // NCBI_STRICT_GI
1130 
1131 typedef SStrictId_Gi::TId TGi;
1132 
1133 #endif // NCBI_STRICT_GI
1134 
1135 
1136 /// TEntrezId type for entrez ids which require the same strictness as TGi.
1137 #ifdef NCBI_STRICT_ENTREZ_ID
1139 #else
1141 #endif
1142 
1143 /// Taxon id type.
1144 #ifdef NCBI_STRICT_TAX_ID
1146 #else
1148 #endif
1149 
1150 
1151 /// a helper template to enforce constness of argument to GI_CONST macro
1152 template<class TId, TId id>
1154 public:
1155 #ifndef NCBI_COMPILER_MSVC
1156  enum : TId {
1157  value = id
1158  };
1159 #else
1160  static const TId value = id;
1161 #endif
1162 };
1163 
1164 #ifdef NCBI_STRICT_GI
1165 
1166 /// Macros to convert TGi to other types (int, unsigned etc.).
1167 #define STRICT_ID_TO(TId, TInt, id) (static_cast<TInt>((id).Get()))
1168 #define STRICT_ID_FROM(TIdType, TIntType, id) (TIdType(static_cast<TIdType::TId>(id)))
1169 #define STRICT_ID_CONST(type, id) \
1170  (type(static_cast<type::TId>(ncbi::CConstIdChecker<type::TId, id>::value)))
1171 #define STRICT_ID_ZERO(type) STRICT_ID_CONST(type, 0)
1172 #define STRICT_ID_INVALID(type) STRICT_ID_CONST(type, -1)
1173 
1174 #else // NCBI_STRICT_GI
1175 
1176 #define STRICT_ID_TO(TId, TInt, id) (static_cast<TInt>(id))
1177 #define STRICT_ID_FROM(TIdType, TIntType, id) (static_cast<TIdType>(id))
1178 #define STRICT_ID_CONST(type, id) (ncbi::CConstIdChecker<type, id>::value)
1179 #define STRICT_ID_ZERO(type) type(0)
1180 #define STRICT_ID_INVALID(type) type(-1)
1181 
1182 #endif // NCBI_STRICT_GI
1183 
1184 #define GI_TO(T, gi) STRICT_ID_TO(ncbi::TGi, T, gi)
1185 #define GI_FROM(T, value) STRICT_ID_FROM(ncbi::TGi, T, value)
1186 #define GI_CONST(gi) STRICT_ID_CONST(ncbi::TGi, gi)
1187 #define ZERO_GI STRICT_ID_ZERO(ncbi::TGi)
1188 #define INVALID_GI STRICT_ID_INVALID(ncbi::TGi)
1189 
1190 
1191 #ifdef NCBI_STRICT_ENTREZ_ID
1192 # define ENTREZ_ID_TO(T, entrez_id) STRICT_ID_TO(ncbi::TEntrezId, T, entrez_id)
1193 # define ENTREZ_ID_FROM(T, value) STRICT_ID_FROM(ncbi::TEntrezId, T, value)
1194 # define ENTREZ_ID_CONST(id) STRICT_ID_CONST(ncbi::TEntrezId, id)
1195 #else
1196 # define ENTREZ_ID_TO(T, entrez_id) (static_cast<T>(entrez_id))
1197 # define ENTREZ_ID_FROM(T, value) (static_cast<ncbi::TEntrezId>(value))
1198 # define ENTREZ_ID_CONST(id) id
1199 #endif
1200 
1201 #define ZERO_ENTREZ_ID ENTREZ_ID_CONST(0)
1202 #define INVALID_ENTREZ_ID ENTREZ_ID_CONST(-1)
1203 
1204 #ifdef NCBI_STRICT_TAX_ID
1205 # define TAX_ID_TO(T, tax_id) STRICT_ID_TO(ncbi::TTaxId, T, tax_id)
1206 # define TAX_ID_FROM(T, value) STRICT_ID_FROM(ncbi::TTaxId, T, value)
1207 # define TAX_ID_CONST(id) STRICT_ID_CONST(ncbi::TTaxId, id)
1208 #else
1209 # define TAX_ID_TO(T, tax_id) (static_cast<T>(tax_id))
1210 # define TAX_ID_FROM(T, value) (static_cast<ncbi::TTaxId>(value))
1211 # define TAX_ID_CONST(id) id
1212 #endif
1213 
1214 #define ZERO_TAX_ID TAX_ID_CONST(0)
1215 #define INVALID_TAX_ID TAX_ID_CONST(-1)
1216 
1217 
1218 /// Convert gi-compatible int to/from other types.
1219 #define INT_ID_TO(T, id) (static_cast<T>(id))
1220 #define INT_ID_FROM(T, value) (static_cast<ncbi::TIntId>(value))
1221 
1222 
1223 /// Helper address class
1225 {
1226 public:
1227  /// add offset to object reference (to get object's member)
1228  static void* Add(void* object, ssize_t offset);
1229  static const void* Add(const void* object, ssize_t offset);
1230  /// calculate offset inside object
1231  static ssize_t Sub(const void* first, const void* second);
1232 };
1233 
1234 
1235 inline
1236 void* CRawPointer::Add(void* object, ssize_t offset)
1237 {
1238  return static_cast<char*> (object) + offset;
1239 }
1240 
1241 inline
1242 const void* CRawPointer::Add(const void* object, ssize_t offset)
1243 {
1244  return static_cast<const char*> (object) + offset;
1245 }
1246 
1247 inline
1248 ssize_t CRawPointer::Sub(const void* first, const void* second)
1249 {
1250  return (ssize_t)/*ptrdiff_t*/
1251  (static_cast<const char*> (first) - static_cast<const char*> (second));
1252 }
1253 
1254 
1255 
1256 /// Buffer with an embedded pre-reserved space.
1257 ///
1258 /// It is convenient to use if you want to avoid allocation in heap
1259 /// for smaller requested sizes, and use stack for such cases.
1260 /// @example:
1261 /// CFastBuffer<2048> buf(some_size);
1262 
1263 template <size_t KEmbeddedSize, class TType = char>
1265 {
1266 public:
1267  CFastBuffer(size_t buf_size)
1268  : m_Size(buf_size),
1269  m_Buffer(buf_size <= KEmbeddedSize ? m_EmbeddedBuffer : new TType[buf_size])
1270  {}
1272 
1273  TType operator[] (size_t pos) const { return m_Buffer[pos]; }
1274 
1275  TType& operator* (void) { return *m_Buffer; }
1276  const TType& operator* (void) const { return *m_Buffer; }
1277 
1278  TType* operator+ (size_t offset) { return m_Buffer + offset; }
1279  const TType* operator+ (size_t offset) const { return m_Buffer + offset; }
1280 
1281  TType* begin(void) { return m_Buffer; }
1282  const TType* begin(void) const { return m_Buffer; }
1283 
1284  TType* end(void) { return m_Buffer + m_Size; }
1285  const TType* end(void) const { return m_Buffer + m_Size; }
1286 
1287  size_t size(void) const { return m_Size; }
1288 
1289 private:
1290  size_t m_Size;
1291  TType* m_Buffer;
1292  TType m_EmbeddedBuffer[KEmbeddedSize];
1293 };
1294 
1295 
1296 
1297 /// Macro used to mark a constructor as deprecated.
1298 ///
1299 /// The correct syntax for this varies from compiler to compiler:
1300 /// older versions of GCC (prior to 3.4) require NCBI_DEPRECATED to
1301 /// follow any relevant constructor declarations, but some other
1302 /// compilers (Microsoft Visual Studio, IBM Visual Age / XL)
1303 /// require it to precede any relevant declarations, whether or not
1304 /// they are for constructors.
1305 #if defined(NCBI_COMPILER_MSVC)
1306 # define NCBI_DEPRECATED_CTOR(decl) NCBI_DEPRECATED decl
1307 #else
1308 # define NCBI_DEPRECATED_CTOR(decl) decl NCBI_DEPRECATED
1309 #endif
1310 
1311 /// Macro used to mark a class as deprecated.
1312 ///
1313 /// @sa NCBI_DEPRECATED_CTOR
1314 #define NCBI_DEPRECATED_CLASS NCBI_DEPRECATED_CTOR(class)
1315 
1316 #ifdef __clang__ // ... including modern ICC
1317 // Preexpand to reduce warning noise -- Clang otherwise recapitulates these
1318 // macros' expansions step by step.
1319 # undef NCBI_DEPRECATED_CTOR
1320 # undef NCBI_DEPRECATED_CLASS
1321 # define NCBI_DEPRECATED_CTOR(decl) decl __attribute__((deprecated))
1322 # define NCBI_DEPRECATED_CLASS class __attribute__((deprecated))
1323 #endif
1324 
1325 //#define NCBI_ENABLE_SAFE_FLAGS
1326 #ifdef NCBI_ENABLE_SAFE_FLAGS
1327 /////////////////////////////////////////////////////////////////////////////
1328 /// Support for safe enum flags
1329 /////////////////////////////////////////////////////////////////////////////
1330 ///
1331 /// The CSafeFlags enum is used to define flags with enum definition
1332 /// so that they preserve type after bit-wise operations,
1333 /// and doesn't allow to be used in context of another enum/flags/int type.
1334 /// With the definition of enum, usually inside class that uses it:
1335 /// class CMyClass {
1336 // public:
1337 /// enum EFlags {
1338 /// fFlag1 = 1<<0,
1339 /// fFlag2 = 1<<1,
1340 /// fFlag3 = 1<<1,
1341 /// fMask = fFlag1|fFlag2
1342 /// };
1343 /// you can add at the same level a macro declaration:
1344 /// DECLARE_SAFE_FLAGS_TYPE(EFlags, TFlags);
1345 /// };
1346 /// and then outside the class, or at the same level if it's not a class definition:
1347 /// DECLARE_SAFE_FLAGS(CMyClass::EFlags);
1348 /// The first macro DECLARE_SAFE_FLAGS_TYPE() declares a typedef for safe-flags.
1349 /// The second macro DECLARE_SAFE_FLAGS() marks the enum as a safe-flags enum, so that
1350 /// bit-wise operations on its values will preserve the safe-flags type.
1351 /// No other modification is necessary in code that uses enum flags correctly.
1352 /// In case the enum values are used in a wrong context, like with a different enum type,
1353 /// compilation error will occur.
1354 
1355 /// Safe enum flags template, not to be used explicitly.
1356 /// Use macros DECLARE_SAFE_FLAGS_TYPE and DECLARE_SAFE_FLAGS instead.
1357 template<class Enum>
1358 class CSafeFlags {
1359 public:
1360  typedef Enum enum_type;
1362 
1363  constexpr CSafeFlags()
1364  : m_Flags(0)
1365  {
1366  }
1367  explicit
1369  : m_Flags(flags)
1370  {
1371  }
1373  : m_Flags(static_cast<storage_type>(flags))
1374  {
1375  }
1376 
1378  {
1379  return m_Flags;
1380  }
1381 
1383 
1384  bool operator==(const CSafeFlags& b) const
1385  {
1386  return get() == b.get();
1387  }
1388  bool operator!=(const CSafeFlags& b) const
1389  {
1390  return get() != b.get();
1391  }
1392  // the following operators are necessary to allow comparison with 0
1393  bool operator==(int v) const
1394  {
1395  return get() == storage_type(v);
1396  }
1397  bool operator!=(int v) const
1398  {
1399  return get() != storage_type(v);
1400  }
1401 
1403  {
1404  return CSafeFlags(~get());
1405  }
1406 
1408  {
1409  return CSafeFlags(get() & b.get());
1410  }
1412  {
1413  m_Flags &= b.get();
1414  return *this;
1415  }
1416 
1418  {
1419  return CSafeFlags(get() | b.get());
1420  }
1422  {
1423  m_Flags |= b.get();
1424  return *this;
1425  }
1426 
1428  {
1429  return CSafeFlags(get() ^ b.get());
1430  }
1432  {
1433  m_Flags ^= b.get();
1434  return *this;
1435  }
1436 
1437 private:
1439 };
1440 /// Macro DECLARE_SAFE_FLAGS_TYPE defines a typedef for safe-flags.
1441 /// First argument is enum name, second argument is the new typedef name.
1442 /// In place of old typedef:
1443 /// typedef int TFlags;
1444 /// put new macro:
1445 /// DECLARE_SAFE_FLAGS_TYPE(EFlags, TFlags);
1446 #define DECLARE_SAFE_FLAGS_TYPE(E, T) \
1447  typedef ncbi::CSafeFlags<E> T
1448 
1449 /// Macro DECLARE_SAFE_FLAGS marks a enum as safe-flags enum.
1450 /// The argument is the enum name.
1451 /// If the enum is defined inside a class then DECLARE_SAFE_FLAGS()
1452 /// must be placed outside the class definition:
1453 /// DECLARE_SAFE_FLAGS(CMyClass::EFlags);
1454 #define DECLARE_SAFE_FLAGS(E) \
1455 inline ncbi::CSafeFlags<E> operator|(E a, E b) \
1456 { return ncbi::CSafeFlags<E>(a) | b; } \
1457 inline ncbi::CSafeFlags<E> operator&(E a, E b) \
1458 { return ncbi::CSafeFlags<E>(a) & b; } \
1459 inline ncbi::CSafeFlags<E> operator^(E a, E b) \
1460 { return ncbi::CSafeFlags<E>(a) ^ b; } \
1461 inline ncbi::CSafeFlags<E> operator~(E a) \
1462 { return ~ncbi::CSafeFlags<E>(a); }
1463 
1464 /// Helper operators for safe-flags enums.
1465 /// These operators will be used only for enums marked
1466 /// as safe-flag enums by macro DECLARE_SAFE_FLAGS()
1467 template<class E> inline CSafeFlags<E> operator|(E a, CSafeFlags<E> b)
1468 {
1469  return b | a;
1470 }
1471 template<class E> inline CSafeFlags<E> operator&(E a, CSafeFlags<E> b)
1472 {
1473  return b & a;
1474 }
1475 template<class E> inline CSafeFlags<E> operator^(E a, CSafeFlags<E> b)
1476 {
1477  return b ^ a;
1478 }
1479 template<class E> inline
1480 ostream& operator<<(ostream& out, const CSafeFlags<E>& v)
1481 {
1482  return out << v.get();
1483 }
1484 
1485 #else // NCBI_ENABLE_SAFE_FLAGS
1486 // backup implementation of safe flag macros
1487 # define DECLARE_SAFE_FLAGS_TYPE(Enum,Typedef) typedef underlying_type<Enum>::type Typedef
1488 # define DECLARE_SAFE_FLAGS(Enum)
1489 #endif // NCBI_ENABLE_SAFE_FLAGS
1490 
1491 
1492 /// CNcbiActionGuard class
1493 /// Executes registered callbacks on request or on destruction.
1495 {
1496 public:
1498  virtual ~CNcbiActionGuard(void) { ExecuteActions(); }
1499 
1500  template<class TFunc> void AddAction(TFunc func)
1501  {
1502  m_Actions.push_back(unique_ptr<CAction_Base>(new CAction<TFunc>(func)));
1503  }
1504 
1505  void ExecuteActions(void)
1506  {
1507  ITERATE(TActions, it, m_Actions) {
1508  try {
1509  (*it)->Execute();
1510  }
1511  catch (exception& e) {
1512  ERR_POST("Error executing action: " << e.what());
1513  }
1514  }
1515  m_Actions.clear(); // prevent multiple executions
1516  }
1517 
1518 private:
1521 
1522  // Action wrapper
1524  {
1525  public:
1526  CAction_Base(void) {}
1527  virtual ~CAction_Base() {}
1528  virtual void Execute(void) const = 0;
1529  private:
1532  };
1533 
1534  template<class TFunc> class CAction : public CAction_Base
1535  {
1536  public:
1537  CAction(TFunc func) : m_Func(func) {}
1538  virtual ~CAction(void) {}
1539  void Execute(void) const override { m_Func(); }
1540  private:
1542  };
1543  typedef list<unique_ptr<CAction_Base> > TActions;
1544 
1546 };
1547 
1548 /// Template helpers for unique_ptr to work with resource allocating/deallocating C functions.
1549 /// @{
1550 /// Eliminates the necessity for specifying type of deallocating C function.
1551 template <class T, class U = conditional_t<is_pointer_v<T>, remove_pointer_t<T>, T>>
1552 using c_unique_ptr = unique_ptr<U, void(*)(U*)>;
1553 
1554 /// Eliminates the necessity for specifying types of both allocated resource and deallocating C function.
1555 template <class T, typename TDeleter>
1556 unique_ptr<T, TDeleter> make_c_unique(T* p, TDeleter d)
1557 {
1558  return {p, d};
1559 }
1560 
1561 /// Overload for the above for all types of allocated memory that are to be deallocated by free()
1562 template <class T>
1563 unique_ptr<T, void(*)(void*)> make_c_unique(T* p)
1564 {
1565  return make_c_unique(p, &free);
1566 }
1567 /// @}
1568 
1569 
1570 /// Helpers for exporting stand-alone functions from DLLs without changing the functions.
1571 /// Useful for exporting third-party APIs without a need to adjust third-party headers.
1572 /// @example:
1573 /// dll_header.hpp: NCBI_EXPORT_FUNC_DECLARE(XCONNECT, mbedtls_strerror);
1574 /// dll_source.cpp: NCBI_EXPORT_FUNC_DEFINE(XCONNECT, mbedtls_strerror);
1575 /// app.cpp: NCBI_XCONNECT::mbedtls_strerror(err, buf, sizeof(buf));
1576 /// @{
1577 #define NCBI_EXPORT_FUNC_DECLARE(lib, func) \
1578 namespace NCBI_ ## lib \
1579 { \
1580  namespace S ## func \
1581  { \
1582  using T = decltype(func); \
1583  \
1584  NCBI_ ## lib ## _EXPORT T* F(); \
1585  \
1586  template <class T> \
1587  struct S; \
1588  \
1589  template <class TR, class... TArgs> \
1590  struct S<TR (TArgs...)> \
1591  { \
1592  static TR Call(TArgs... args) { return F()(args...); } \
1593  }; \
1594  } \
1595  \
1596  constexpr auto func = S ## func::S<S ## func::T>::Call; \
1597 }
1598 
1599 #define NCBI_EXPORT_FUNC_DEFINE(lib, func) \
1600 namespace NCBI_ ## lib \
1601 { \
1602  namespace S ## func \
1603  { \
1604  T* F() { return ::func; } \
1605  } \
1606 }
1607 /// @}
1608 
1609 
1611 
1613 
1614 template<class T1, class T2>
1615 inline
1616 void swap(ncbi::pair_base_member<T1,T2>& pair1,
1617  ncbi::pair_base_member<T1,T2>& pair2) noexcept
1618 {
1619  pair1.Swap(pair2);
1620 }
1621 
1622 
1623 template<class P, class D>
1624 inline
1625 void swap(ncbi::AutoPtr<P,D>& ptr1,
1626  ncbi::AutoPtr<P,D>& ptr2) noexcept
1627 {
1628  ptr1.Swap(ptr2);
1629 }
1630 
1631 
1632 template<class Element, size_t Size>
1633 inline
1634 constexpr size_t ArraySize(const Element (&)[Size])
1635 {
1636  return Size;
1637 }
1638 
1639 #ifdef NCBI_STRICT_GI
1640 template <class TKey, class TStorage> struct hash<ncbi::CStrictId<TKey, TStorage>>
1641 {
1642  size_t operator()(const ncbi::CStrictId<TKey, TStorage> & x) const
1643  {
1644  return hash<TStorage>()(x.Get());
1645  }
1646 };
1647 
1648 # if __has_include(<format>)
1649 template <class TKey, class TStorage, class TChar>
1650 struct formatter<ncbi::CStrictId<TKey, TStorage>, TChar>
1651  : public formatter<TStorage, TChar>
1652 {
1653  typedef ncbi::CStrictId<TKey, TStorage> TId;
1654 
1655  template<class TFmtContext>
1656  TFmtContext::iterator format(const TId& id, TFmtContext& ctx) const {
1658  }
1659 };
1660 # endif // __has_include(<format>)
1661 #endif /* NCBI_STRICT_GI */
1662 
1663 
1665 
1666 /* @} */
1667 
1668 #endif /* CORELIB___NCBIMISC__HPP */
AutoArray –.
Definition: ncbimisc.hpp:581
Template used to replace bool type arguments with some strict equivalent.
Definition: ncbimisc.hpp:319
a helper template to enforce constness of argument to GI_CONST macro
Definition: ncbimisc.hpp:1153
CNcbiActionGuard class Executes registered callbacks on request or on destruction.
Definition: ncbimisc.hpp:1495
Template class allowing to store a value or null (unassigned) state.
Definition: ncbimisc.hpp:775
Helper address class.
Definition: ncbimisc.hpp:1225
Support for safe enum flags.
Definition: ncbimisc.hpp:1358
Template class for strict ID types.
Definition: ncbimisc.hpp:992
definition of a Culling tree
Definition: ncbi_tree.hpp:100
Template used for empty base class optimization.
Definition: ncbimisc.hpp:250
static uch flags
#define T(s)
Definition: common.h:230
char TChar
Definition: interfaces.hpp:78
std::ofstream out("events_result.xml")
main entry point for tests
CS_CONTEXT * ctx
Definition: t0006.c:12
#define true
Definition: bool.h:35
#define false
Definition: bool.h:36
#define bool
Definition: bool.h:34
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
static int type
Definition: getdata.c:31
static const char * str(char *buf, int n)
Definition: stats.c:84
static char tmp[3200]
Definition: utf8.c:42
int offset
Definition: replacements.h:160
char data[12]
Definition: iconv.c:80
AutoPtr(element_type *p, EOwnership ownership) noexcept
Constructor, own the pointed object if ownership == eTakeOwnership.
Definition: ncbimisc.hpp:433
element_type & operator*(void) const noexcept
Dereference operator.
Definition: ncbimisc.hpp:503
void reset() noexcept
Reset will delete the old pointer (if owned)
Definition: ncbimisc.hpp:523
element_type * m_Ptr
Internal pointer representation.
Definition: ncbimisc.hpp:554
TValue operator()(void) const
Definition: ncbimisc.hpp:757
virtual ~CNcbiActionGuard(void)
Definition: ncbimisc.hpp:1498
SStrictId_Entrez::TId TEntrezId
TEntrezId type for entrez ids which require the same strictness as TGi.
Definition: ncbimisc.hpp:1140
CNcbiActionGuard(void)
Definition: ncbimisc.hpp:1497
const Type & s_ITERATE_ConstRef(const Type &obj)
Definition: ncbimisc.hpp:886
NCBI_XNCBI_EXPORT void g_ThrowOnNull(void)
Definition: ncbiexpt.cpp:861
Del deleter_type
Alias for template argument.
Definition: ncbimisc.hpp:415
CBoolEnum(TEnum value)
Definition: ncbimisc.hpp:323
BEGIN_STD_NAMESPACE
Definition: ncbimisc.hpp:1612
#define DECLARE_OPERATOR_BOOL(Expr)
Declaration of safe bool operator from boolean expression.
Definition: ncbimisc.hpp:203
CStrictId(void)
Definition: ncbimisc.hpp:997
~AutoPtr(void)
Destructor.
Definition: ncbimisc.hpp:460
CNcbiActionGuard & operator=(const CNcbiActionGuard &)
ETriState
Enumeration to represent a tristate value.
Definition: ncbimisc.hpp:132
CSafeFlags operator~() const
Definition: ncbimisc.hpp:1402
CNcbiOstream & operator<<(CNcbiOstream &out, const CStrictId< TKey, TStorage > &id)
Definition: ncbimisc.hpp:1045
CBoolEnum(bool value)
Definition: ncbimisc.hpp:322
void AddAction(TFunc func)
Definition: ncbimisc.hpp:1500
CAction_Base & operator=(const CAction_Base &)
X element_type
Define element type.
Definition: ncbimisc.hpp:583
CSafeFlags & operator|=(const CSafeFlags &b)
Definition: ncbimisc.hpp:1421
~AutoArray(void)
Definition: ncbimisc.hpp:623
enum ENcbiSwitch ESwitch
Aux.
AutoArray< X, Del > & operator=(const AutoArray< X, Del > &p) noexcept
Assignment operator.
Definition: ncbimisc.hpp:643
const element_type & operator[](size_t pos) const noexcept
Array style dereference (returns value)
Definition: ncbimisc.hpp:678
CStrictId(T id, typename enable_if< is_same< T, TId >::value, T >::type=0)
Definition: ncbimisc.hpp:1026
AutoPtr(element_type *p) noexcept
Constructor.
Definition: ncbimisc.hpp:423
Uint8 TUintId
Definition: ncbimisc.hpp:1099
void ExecuteActions(void)
Definition: ncbimisc.hpp:1505
bool operator!=(const CNullable< TValue, TNullToValue > &l, const CNullable< TValue, TNullToValue > &r)
Definition: ncbimisc.hpp:846
constexpr CSafeFlags(storage_type flags)
Definition: ncbimisc.hpp:1368
void swap(ncbi::pair_base_member< T1, T2 > &pair1, ncbi::pair_base_member< T1, T2 > &pair2) noexcept
Definition: ncbimisc.hpp:1616
char * strdup(const char *str)
Supply string duplicate function, if one is not defined.
Definition: ncbistr.cpp:5578
AutoArray< X, Del > & operator=(AutoArray< X, Del > &&p) noexcept
Move assignment operator.
Definition: ncbimisc.hpp:630
AutoArray(element_type *p, const deleter_type &deleter) noexcept
Definition: ncbimisc.hpp:602
AutoPtr() noexcept
Constructor.
Definition: ncbimisc.hpp:418
storage_type get() const
Definition: ncbimisc.hpp:1377
unique_ptr< U, void(*)(U *)> c_unique_ptr
Template helpers for unique_ptr to work with resource allocating/deallocating C functions.
Definition: ncbimisc.hpp:1552
TType * begin(void)
Definition: ncbimisc.hpp:1281
bool operator==(const CSafeFlags &b) const
Definition: ncbimisc.hpp:1384
CBoolEnum(int)
CSafeFlags operator&(const CSafeFlags &b) const
Definition: ncbimisc.hpp:1407
pair_base_member(const first_type &first_value, const second_type &second_value)
Definition: ncbimisc.hpp:272
ERetriable
Can the action be retried?
Definition: ncbimisc.hpp:171
CAction_Base(const CAction_Base &)
pair_base_member< deleter_type, bool > m_Data
State info.
Definition: ncbimisc.hpp:555
CSafeFlags< E > operator|(E a, CSafeFlags< E > b)
Helper operators for safe-flags enums.
Definition: ncbimisc.hpp:1467
Member second_type
Definition: ncbimisc.hpp:255
bool operator!=(const CSafeFlags &b) const
Definition: ncbimisc.hpp:1388
bool operator<(const TThis &id) const
Definition: ncbimisc.hpp:1003
Member member_type
Definition: ncbimisc.hpp:254
size_t size(void) const
Definition: ncbimisc.hpp:1287
CSafeFlags operator|(const CSafeFlags &b) const
Definition: ncbimisc.hpp:1417
CBoolEnum(char *)
element_type & operator[](size_t pos) noexcept
Array style dereference (returns reference)
Definition: ncbimisc.hpp:681
AutoPtr< X, Del > & operator=(element_type *p) noexcept
Assignment operator.
Definition: ncbimisc.hpp:491
TThis operator-(const TThis &id) const
Definition: ncbimisc.hpp:1014
static ssize_t Sub(const void *first, const void *second)
calculate offset inside object
Definition: ncbimisc.hpp:1248
bool m_Value
Definition: ncbimisc.hpp:331
void Swap(AutoPtr< X, Del > &a) noexcept
Definition: ncbimisc.hpp:545
bool IsNull(void) const
Check if the object is unassigned.
Definition: ncbimisc.hpp:785
CFastBuffer(size_t buf_size)
Definition: ncbimisc.hpp:1267
bool m_IsNull
Definition: ncbimisc.hpp:835
TGi CStrictGi
Definition: ncbimisc.hpp:1127
CNcbiActionGuard(const CNcbiActionGuard &)
size_t m_Size
Definition: ncbimisc.hpp:1290
second_type & second() noexcept
Definition: ncbimisc.hpp:291
member_type m_Member
Definition: ncbimisc.hpp:307
END_STD_NAMESPACE
Definition: ncbimisc.hpp:1664
void Execute(void) const override
Definition: ncbimisc.hpp:1539
AutoPtr< X, Del > & operator=(AutoPtr< X, Del > &&p) noexcept
Move assignment operator.
Definition: ncbimisc.hpp:467
AutoPtr(element_type *p, const deleter_type &deleter) noexcept
Constructor.
Definition: ncbimisc.hpp:428
void Swap(pair_base_member< first_type, second_type > &p) noexcept
Definition: ncbimisc.hpp:296
X element_type
Define element type.
Definition: ncbimisc.hpp:414
ERound
Whether to truncate/round a value.
Definition: ncbimisc.hpp:140
AutoArray(const AutoArray< X, Del > &p) noexcept
Copy constructor.
Definition: ncbimisc.hpp:617
TThis & operator=(const TThis &other)
Definition: ncbimisc.hpp:999
static void * Add(void *object, ssize_t offset)
add offset to object reference (to get object's member)
Definition: ncbimisc.hpp:1236
element_type * x_Release(void) const noexcept
Release for const object, used in deprecated methods.
Definition: ncbimisc.hpp:558
bool IsOwned(void) const noexcept
Definition: ncbimisc.hpp:712
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:974
element_type * operator->(void) const noexcept
Reference operator.
Definition: ncbimisc.hpp:506
storage_type m_Flags
Definition: ncbimisc.hpp:1438
bool operator==(const TThis &id) const
Definition: ncbimisc.hpp:1001
bool operator<=(const TThis &id) const
Definition: ncbimisc.hpp:1004
CSafeFlags operator^(const CSafeFlags &b) const
Definition: ncbimisc.hpp:1427
constexpr size_t ArraySize(const Element(&)[Size])
Definition: ncbimisc.hpp:1634
CNullable(TValue value)
Initialize nullable with a specific value.
Definition: ncbimisc.hpp:781
TThis operator--(int)
Definition: ncbimisc.hpp:1011
first_type & first() noexcept
Definition: ncbimisc.hpp:282
CStrictId< TKey, TStorage > TThis
Definition: ncbimisc.hpp:995
size_t operator()(const ncbi::CStrictId< TKey, TStorage > &x) const
Definition: ncbimisc.hpp:1642
TType m_EmbeddedBuffer[KEmbeddedSize]
Definition: ncbimisc.hpp:1292
AutoPtr< X, Del > & operator=(const AutoPtr< X, Del > &p) noexcept
Assignment operator.
Definition: ncbimisc.hpp:480
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:914
ENormalizePath
Whether to normalize a path.
Definition: ncbimisc.hpp:154
pair_base_member< deleter_type, bool > m_Data
State info.
Definition: ncbimisc.hpp:723
bool s_ITERATE_SameObject(const Type &obj1, const Type &obj2)
Definition: ncbimisc.hpp:895
CSafeFlags & operator^=(const CSafeFlags &b)
Definition: ncbimisc.hpp:1431
CNullable(ENull=null)
Create an empty nullable.
Definition: ncbimisc.hpp:778
underlying_type< enum_type >::type storage_type
Definition: ncbimisc.hpp:1361
bool operator>=(const TThis &id) const
Definition: ncbimisc.hpp:1006
AutoArray(element_type *p) noexcept
Definition: ncbimisc.hpp:598
int TSignedSeqPos
Type for signed sequence position.
Definition: ncbimisc.hpp:986
bool IsOwned(void) const noexcept
Definition: ncbimisc.hpp:551
AutoArray< X, Del > & operator=(element_type *p) noexcept
Assignment operator.
Definition: ncbimisc.hpp:654
static X * Create(void)
Default create function.
Definition: ncbimisc.hpp:351
TActions m_Actions
Definition: ncbimisc.hpp:1545
bool operator==(const CNullable< TValue, TNullToValue > &l, const CNullable< TValue, TNullToValue > &r)
Definition: ncbimisc.hpp:840
element_type * get(void) const noexcept
Get pointer.
Definition: ncbimisc.hpp:664
enum ENcbiOwnership EOwnership
Ownership relations between objects.
TId & Set(void)
Definition: ncbimisc.hpp:1022
const TType * begin(void) const
Definition: ncbimisc.hpp:1282
TValue & SetValue(void)
Get a non-const reference to the value.
Definition: ncbimisc.hpp:812
static void Delete(X *object)
Array delete function.
Definition: ncbimisc.hpp:369
pair_base_member(member_type &&member_value) noexcept
Definition: ncbimisc.hpp:267
element_type * x_Release(void) const noexcept
Release for const object, used in deprecated methods.
Definition: ncbimisc.hpp:716
AutoArray(AutoArray< X, Del > &&p) noexcept
Move constructor.
Definition: ncbimisc.hpp:608
Int8 TIntId
Definition: ncbimisc.hpp:1098
void reset(element_type *p, EOwnership ownership=eTakeOwnership) noexcept
Reset will delete the old pointer (if owned), set content to the new value, and assume the ownership ...
Definition: ncbimisc.hpp:534
EFollowLinks
Whether to follow symbolic links (also known as shortcuts or aliases)
Definition: ncbimisc.hpp:147
void reset(element_type *p) noexcept
Reset will delete the old pointer, set content to the new value, and assume the ownership upon the ne...
Definition: ncbimisc.hpp:695
END_NCBI_NAMESPACE
Definition: ncbimisc.hpp:1610
TType operator[](size_t pos) const
Definition: ncbimisc.hpp:1273
const second_type & second() const noexcept
Definition: ncbimisc.hpp:287
CStrictId< SStrictId_Gi, SStrictId_Gi::TId > TGi
Definition: ncbimisc.hpp:1124
static void Delete(X *object)
Default delete function.
Definition: ncbimisc.hpp:360
TType * operator+(size_t offset)
Definition: ncbimisc.hpp:1278
element_type * release(void) noexcept
Release will release ownership of pointer to caller.
Definition: ncbimisc.hpp:512
unique_ptr< T, TDeleter > make_c_unique(T *p, TDeleter d)
Eliminates the necessity for specifying types of both allocated resource and deallocating C function.
Definition: ncbimisc.hpp:1556
CStrictId(const TThis &other)
Definition: ncbimisc.hpp:998
element_type * release(void) noexcept
Release will release ownership of pointer to caller.
Definition: ncbimisc.hpp:667
TThis operator+(const TThis &id) const
Definition: ncbimisc.hpp:1013
SStrictId_Tax::TId TTaxId
Taxon id type.
Definition: ncbimisc.hpp:1147
Del deleter_type
Alias for template argument.
Definition: ncbimisc.hpp:584
EInterruptOnSignal
Interrupt on signal mode.
Definition: ncbimisc.hpp:164
CSafeFlags & operator&=(const CSafeFlags &b)
Definition: ncbimisc.hpp:1411
CNcbiIstream & operator>>(CNcbiIstream &in, CStrictId< TKey, TStorage > &id)
Definition: ncbimisc.hpp:1052
static void Delete(X *object)
C Language deallocation function.
Definition: ncbimisc.hpp:378
bool operator==(int v) const
Definition: ncbimisc.hpp:1393
BEGIN_NCBI_NAMESPACE
NCBI_EOWNERSHIP_DEFINED.
Definition: ncbimisc.hpp:113
TType & operator*(void)
Definition: ncbimisc.hpp:1275
AutoPtr(element_type *p, const deleter_type &deleter, EOwnership ownership) noexcept
Constructor, own the pointed object if ownership == eTakeOwnership.
Definition: ncbimisc.hpp:438
#define DECLARE_OPERATOR_BOOL_PTR(Ptr)
Declaration of safe bool operator from pointer expression.
Definition: ncbimisc.hpp:210
void Swap(AutoPtr< X, Del > &a) noexcept
Definition: ncbimisc.hpp:706
CSafeFlags< E > operator&(E a, CSafeFlags< E > b)
Definition: ncbimisc.hpp:1471
TThis & operator++(void)
Definition: ncbimisc.hpp:1008
void reset() noexcept
Reset will delete the old pointer.
Definition: ncbimisc.hpp:684
TStorage TId
Definition: ncbimisc.hpp:994
CSafeFlags< E > operator^(E a, CSafeFlags< E > b)
Definition: ncbimisc.hpp:1475
const TSeqPos kInvalidSeqPos
Define special value for invalid sequence position.
Definition: ncbimisc.hpp:977
CNullable & operator=(TValue value)
Assign a value to the nullable.
Definition: ncbimisc.hpp:821
pair_base_member(void)
Definition: ncbimisc.hpp:257
ENullable
Whether a value is nullable.
Definition: ncbimisc.hpp:117
constexpr CSafeFlags()
Definition: ncbimisc.hpp:1363
const first_type & first() const noexcept
Definition: ncbimisc.hpp:278
TThis operator-(void) const
Definition: ncbimisc.hpp:1015
TThis & operator--(void)
Definition: ncbimisc.hpp:1010
TThis operator++(int)
Definition: ncbimisc.hpp:1009
TType * end(void)
Definition: ncbimisc.hpp:1284
list< unique_ptr< CAction_Base > > TActions
Definition: ncbimisc.hpp:1543
AutoPtr(const AutoPtr< X, Del > &p) noexcept
Copy constructor.
Definition: ncbimisc.hpp:453
bool operator!=(int v) const
Definition: ncbimisc.hpp:1397
constexpr CSafeFlags(enum_type flags)
Definition: ncbimisc.hpp:1372
AutoArray(size_t size) noexcept
Construct the array using C++ new[] operator.
Definition: ncbimisc.hpp:590
ENull
CNullable –.
Definition: ncbimisc.hpp:744
AutoArray() noexcept
Definition: ncbimisc.hpp:594
Enum enum_type
Definition: ncbimisc.hpp:1360
virtual void Execute(void) const =0
TId Get(void) const
Definition: ncbimisc.hpp:1020
element_type * m_Ptr
Definition: ncbimisc.hpp:722
CBoolEnum(unsigned int)
ESign
Signedness of a value.
Definition: ncbimisc.hpp:124
TValue m_Value
Definition: ncbimisc.hpp:836
void Set(TId id)
Definition: ncbimisc.hpp:1021
bool operator!=(const TThis &id) const
Definition: ncbimisc.hpp:1002
AutoPtr(AutoPtr< X, Del > &&p) noexcept
Move constructor.
Definition: ncbimisc.hpp:444
element_type * get(void) const noexcept
Get pointer.
Definition: ncbimisc.hpp:509
bool operator>(const TThis &id) const
Definition: ncbimisc.hpp:1005
pair_base_member(const member_type &member_value)
Definition: ncbimisc.hpp:262
TType * m_Buffer
Definition: ncbimisc.hpp:1291
const TValue & GetValue(void) const
Get a const reference to the current value.
Definition: ncbimisc.hpp:802
const TType * end(void) const
Definition: ncbimisc.hpp:1285
@ eTriState_False
The value is equivalent to false/no.
Definition: ncbimisc.hpp:134
@ eTriState_True
The value is equivalent to true/yes.
Definition: ncbimisc.hpp:135
@ eTriState_Unknown
The value is indeterminate.
Definition: ncbimisc.hpp:133
@ eRetriable_Unknown
It is unknown if the action can succeed if retried.
Definition: ncbimisc.hpp:173
@ eRetriable_No
It makes no sense to retry the action.
Definition: ncbimisc.hpp:172
@ eRetriable_Yes
It makes sense to try again.
Definition: ncbimisc.hpp:174
@ eTrunc
Value must be truncated.
Definition: ncbimisc.hpp:141
@ eRound
Value must be rounded.
Definition: ncbimisc.hpp:142
@ eNormalizePath
Normalize a path.
Definition: ncbimisc.hpp:155
@ eNotNormalizePath
Do not normalize a path.
Definition: ncbimisc.hpp:156
@ eOff
Definition: ncbimisc.hpp:75
@ eDefault
Definition: ncbimisc.hpp:77
@ eOn
Definition: ncbimisc.hpp:76
@ eIgnoreLinks
Do not follow symbolic links.
Definition: ncbimisc.hpp:148
@ eFollowLinks
Follow symbolic links.
Definition: ncbimisc.hpp:149
@ eRestartOnSignal
Restart operation if interrupted by a signal.
Definition: ncbimisc.hpp:166
@ eInterruptOnSignal
Cancel operation if interrupted by a signal.
Definition: ncbimisc.hpp:165
@ eNotNullable
Value cannot be null.
Definition: ncbimisc.hpp:119
@ eNullable
Value can be null.
Definition: ncbimisc.hpp:118
@ eNegative
Value is negative.
Definition: ncbimisc.hpp:125
@ ePositive
Value is positive.
Definition: ncbimisc.hpp:127
@ eZero
Value is zero.
Definition: ncbimisc.hpp:126
@ eTakeOwnership
No ownership assumed.
Definition: ncbimisc.hpp:105
@ eNoOwnership
Definition: ncbimisc.hpp:104
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:185
#define NCBI_DEPRECATED
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
enum ENcbiOwnership EOwnership
Ownership relations between objects.
ENcbiSwitch
Aux.
Definition: ncbi_types.h:108
ENcbiOwnership
Ownership relations between objects.
Definition: ncbi_types.h:133
#define NCBI_XNCBI_EXPORT
Definition: ncbi_export.h:1299
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1282
The blob sat and sat key Both must be positive integers</td > n< td > Non empty string The interpretation of the blob id depends on a processor Cassandra n processor expects the following format
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
unsigned int a
Definition: ncbi_localip.c:103
int ssize_t
Definition: ncbiconf_msvc.h:93
NCBI C++ auxiliary debug macros.
const double E
std::istream & in(std::istream &in_, double &x_)
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
#define U
static SLJIT_INLINE sljit_ins l(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
Functor template for deleting array of objects.
Definition: ncbimisc.hpp:367
Functor template for the C language deallocation function, free().
Definition: ncbimisc.hpp:376
Functor template for allocating object.
Definition: ncbimisc.hpp:349
Functor template for deleting object.
Definition: ncbimisc.hpp:358
Key structs must always be defined - they are used in aliasinfo.cpp.
Definition: ncbimisc.hpp:1111
Definition: _hash_fun.h:40
Definition: type.c:6
#define Type
#define const
Definition: zconf.h:232
void free(voidpf ptr)
Modified on Sat Nov 07 14:10:48 2026 by modify_doxy.py rev. 717554