NCBI C++ ToolKit
/home/coremake/doxygen/cxx/include/corelib/ncbimisc.hpp

Buffer with an embedded pre-reserved space.It is convenient to use if you want to avoid allocation in heap for smaller requested sizes, and use stack for such cases.

CFastBuffer<2048> buf(some_size);

#ifndef CORELIB___NCBIMISC__HPP
#define CORELIB___NCBIMISC__HPP
/* $Id: ncbimisc.hpp 100071 2023-06-12 19:29:39Z sadyrovr $
* ===========================================================================
*
* PUBLIC DOMAIN NOTICE
* National Center for Biotechnology Information
*
* This software/database is a "United States Government Work" under the
* terms of the United States Copyright Act. It was written as part of
* the author's official duties as a United States Government employee and
* thus cannot be copyrighted. This software/database is freely available
* to the public for use. The National Library of Medicine and the U.S.
* Government have not placed any restriction on its use or reproduction.
*
* Although all reasonable efforts have been taken to ensure the accuracy
* and reliability of the software and data, the NLM and the U.S.
* Government do not and cannot warrant the performance or results that
* may be obtained by using this software or data. The NLM and the U.S.
* Government disclaim all warranties, express or implied, including
* warranties of performance, merchantability or fitness for any particular
* purpose.
*
* Please cite the author in any work or product based on this material.
*
* ===========================================================================
*
* Author: Denis Vakatov, Eugene Vasilchenko
*
*
*/
/// @file ncbimisc.hpp
/// Miscellaneous common-use basic types and functionality
#include <stdlib.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#if !defined(HAVE_NULLPTR) && !defined(nullptr)
# define nullptr NULL
#endif
/** @addtogroup AppFramework
*
* @{
*/
#ifndef NCBI_ESWITCH_DEFINED
#define NCBI_ESWITCH_DEFINED
extern "C" {
/*
* ATTENTION! Do not change this enumeration!
*
* It must always be kept in sync with its plain C counterpart defined in
* "connect/ncbi_types.h". If you absolutely(sic!) need to alter this
* type, please apply equivalent changes to both definitions.
*/
/** Aux. enum to set/unset/default various features.
*/
typedef enum ENcbiSwitch {
eOff = 0,
eOn,
} // extern "C"
#endif //!NCBI_ESWITCH_DEFINED
#ifndef NCBI_EOWNERSHIP_DEFINED
#define NCBI_EOWNERSHIP_DEFINED
extern "C" {
/*
* ATTENTION! Do not change this enumeration!
*
* It must always be kept in sync with its plain C counterpart defined in
* "connect/ncbi_types.h". If you absolutely(sic!) need to alter this
* type, please apply equivalent changes to both definitions.
*/
/** Ownership relations between objects.
*
* Can be used to define or transfer ownership of objects.
* For example, specify if a CSocket object owns its underlying SOCK object.
*/
typedef enum ENcbiOwnership {
eNoOwnership, /** No ownership assumed */
eTakeOwnership /** An object can take ownership of another */
} // extern "C"
#endif //!NCBI_EOWNERSHIP_DEFINED
/// Whether a value is nullable.
enum ENullable {
eNullable, ///< Value can be null
eNotNullable ///< Value cannot be null
};
/// Signedness of a value.
enum ESign {
eNegative = -1, ///< Value is negative
eZero = 0, ///< Value is zero
ePositive = 1 ///< Value is positive
};
/// Enumeration to represent a tristate value.
enum ETriState {
eTriState_Unknown = -1, ///< The value is indeterminate
eTriState_False = 0, ///< The value is equivalent to false/no
eTriState_True = 1, ///< The value is equivalent to true/yes
};
/// Whether to truncate/round a value.
enum ERound {
eTrunc, ///< Value must be truncated
eRound ///< Value must be rounded
};
/// Whether to follow symbolic links (also known as shortcuts or aliases)
eIgnoreLinks, ///< Do not follow symbolic links
eFollowLinks ///< Follow symbolic links
};
/// Whether to normalize a path
eNormalizePath, ///< Normalize a path
eNotNormalizePath ///< Do not normalize a path
};
/// Interrupt on signal mode
///
/// On UNIX some functions can be interrupted by a signal and EINTR errno
/// value. We can restart or cancel its execution.
eInterruptOnSignal, ///< Cancel operation if interrupted by a signal
eRestartOnSignal ///< Restart operation if interrupted by a signal
};
/// Can the action be retried?
enum ERetriable {
eRetriable_No, ///< It makes no sense to retry the action
eRetriable_Unknown, ///< It is unknown if the action can succeed if retried
eRetriable_Yes ///< It makes sense to try again
};
/////////////////////////////////////////////////////////////////////////////
/// Support for safe bool operators
/////////////////////////////////////////////////////////////////////////////
/// Low level macro for declaring safe bool operator.
#define DECLARE_SAFE_BOOL_METHOD(Expr) \
struct SSafeBoolTag { \
void SafeBoolTrue(SSafeBoolTag*) {} \
}; \
typedef void (SSafeBoolTag::*TBoolType)(SSafeBoolTag*); \
operator TBoolType() const { \
return (Expr)? &SSafeBoolTag::SafeBoolTrue: 0; \
} \
private: \
bool operator==(TBoolType) const; \
bool operator!=(TBoolType) const; \
public: \
friend struct SSafeBoolTag
/// Declaration of safe bool operator from boolean expression.
/// Actual operator declaration will be:
/// operator TBoolType(void) const;
/// where TBoolType is a typedef convertible to bool (member pointer).
#define DECLARE_OPERATOR_BOOL(Expr) \
DECLARE_SAFE_BOOL_METHOD(Expr)
/// Declaration of safe bool operator from pointer expression.
/// Actual operator declaration will be:
/// operator bool(void) const;
#define DECLARE_OPERATOR_BOOL_PTR(Ptr) \
DECLARE_OPERATOR_BOOL((Ptr) != 0)
/// Declaration of safe bool operator from CRef<>/CConstRef<> expression.
/// Actual operator declaration will be:
/// operator bool(void) const;
#define DECLARE_OPERATOR_BOOL_REF(Ref) \
DECLARE_OPERATOR_BOOL((Ref).NotNull())
/// Override the DECLARE_OPERATOR_BOOL, etc.
/// from an ancestor class. This is needed because sometimes you can't just
/// use DECLARE_OPERATOR_BOOL due to cases such as the ancestor class
/// being privately inherited from.
#define OVERRIDE_OPERATOR_BOOL(TAncestorClass, NewBoolExpr) \
using TAncestorClass::TBoolType; \
using TAncestorClass::SSafeBoolTag; \
operator TBoolType() const { \
return (NewBoolExpr)? & SSafeBoolTag::SafeBoolTrue : 0; \
}
/// Template used for empty base class optimization.
/// See details in the August '97 "C++ Issue" of Dr. Dobb's Journal
/// Also available from http://www.cantrip.org/emptyopt.html
/// We store usually empty template argument class together with data member.
/// This template is much like STL's pair<>, but the access to members
/// is done though methods first() and second() returning references
/// to corresponding members.
/// First template argument is represented as private base class,
/// while second template argument is represented as private member.
/// In addition to constructor taking two arguments,
/// we add constructor for initialization of only data member (second).
/// This is useful since usually first type is empty and doesn't require
/// non-trivial constructor.
/// We do not define any comparison functions as this template is intented
/// to be used internally within another templates,
/// which themselves should provide any additional functionality.
template<class Base, class Member>
class pair_base_member : private Base
{
public:
typedef Base base_type;
typedef Base first_type;
typedef Member member_type;
typedef Member second_type;
{
}
explicit pair_base_member(const member_type& member_value)
: base_type(), m_Member(member_value)
{
}
explicit pair_base_member(const first_type& first_value,
const second_type& second_value)
: base_type(first_value), m_Member(second_value)
{
}
const first_type& first() const
{
return *this;
}
{
return *this;
}
const second_type& second() const
{
return m_Member;
}
{
return m_Member;
}
{
if (static_cast<void*>(&first()) != static_cast<void*>(&second())){
// work around an IBM compiler bug which causes it to perform
// a spurious 1-byte swap, yielding mixed-up values.
swap(first(), p.first());
}
swap(second(), p.second());
}
private:
};
/// Template used to replace bool type arguments with some strict equivalent.
/// This allow to prevent compiler to do an implicit casts from other types
/// to bool. "TEnum" should be an enumerated type with two values:
/// - negative (FALSE/OFF) should have value 0
// - positive (TRUE/ON) have value 1.
template <class TEnum>
class CBoolEnum
{
public:
// Constructors
/// Operator bool
operator bool() const { return m_Value; }
/// Operator enum
operator TEnum () const { return TEnum(m_Value); }
private:
bool m_Value;
private:
// Disable implicit conversions from/to other types
CBoolEnum(char*);
CBoolEnum(int);
CBoolEnum(unsigned int);
template <class T> CBoolEnum(T);
operator int() const;
operator unsigned int() const;
};
/// Functor template for allocating object.
template<class X>
struct Creater
{
/// Default create function.
static X* Create(void)
{ return new X; }
};
/// Functor template for deleting object.
template<class X>
struct Deleter
{
/// Default delete function.
static void Delete(X* object)
{ delete object; }
};
/// Functor template for deleting array of objects.
template<class X>
{
/// Array delete function.
static void Delete(X* object)
{ delete[] object; }
};
/// Functor template for the C language deallocation function, free().
template<class X>
struct CDeleter
{
/// C Language deallocation function.
static void Delete(X* object)
{ free(object); }
};
/////////////////////////////////////////////////////////////////////////////
///
/// AutoPtr --
///
/// Define an "auto_ptr" like class that can be used inside STL containers.
///
/// The Standard auto_ptr template from STL doesn't allow the auto_ptr to be
/// put in STL containers (list, vector, map etc.). The reason for this is
/// the absence of copy constructor and assignment operator.
/// We decided that it would be useful to have an analog of STL's auto_ptr
/// without this restriction - AutoPtr.
///
/// Due to the nature of AutoPtr its copy constructor and assignment operator
/// modify the state of the source AutoPtr object as it transfers the ownership
/// to the target AutoPtr object. Also, we added possibility to redefine the
/// way pointer will be deleted: the second argument of the template allows
/// pointers from "malloc" in AutoPtr, or you can use "ArrayDeleter" (see
/// above) to properly delete an array of objects using "delete[]" instead
/// of "delete". By default, the internal pointer is deleted by the C++
/// "delete" operator.
///
/// @sa
/// Deleter(), ArrayDeleter(), CDeleter()
template< class X, class Del = Deleter<X> >
class AutoPtr
{
public:
typedef X element_type; ///< Define element type.
typedef Del deleter_type; ///< Alias for template argument.
/// Constructor.
: m_Ptr(p), m_Data(true)
{ }
/// Constructor.
AutoPtr(element_type* p, const deleter_type& deleter)
: m_Ptr(p), m_Data(deleter, true)
{ }
/// Constructor, own the pointed object if ownership == eTakeOwnership
: m_Ptr(p), m_Data(ownership != eNoOwnership)
{ }
/// Constructor, own the pointed object if ownership == eTakeOwnership
AutoPtr(element_type* p, const deleter_type& deleter, EOwnership ownership)
: m_Ptr(p), m_Data(deleter, ownership != eNoOwnership)
{ }
/// Copy constructor.
: m_Ptr(0), m_Data(p.m_Data)
{
}
/// Destructor.
~AutoPtr(void)
{
reset();
}
/// Assignment operator.
{
if (this != &p) {
bool owner = p.m_Data.second();
m_Data.second() = owner;
}
return *this;
}
/// Assignment operator.
{
reset(p);
return *this;
}
/// Bool operator for use in if() clause.
// Standard getters.
/// Dereference operator.
element_type& operator* (void) const { return *m_Ptr; }
/// Reference operator.
element_type* operator->(void) const { return m_Ptr; }
/// Get pointer.
element_type* get (void) const { return m_Ptr; }
/// Release will release ownership of pointer to caller.
{
m_Data.second() = false;
return m_Ptr;
}
/// Reset will delete the old pointer (if owned), set content to the new
/// value, and assume the ownership upon the new pointer by default.
void reset(element_type* p = 0, EOwnership ownership = eTakeOwnership)
{
if ( m_Ptr != p ) {
if (m_Ptr && m_Data.second()) {
m_Data.first().Delete(release());
}
m_Ptr = p;
}
m_Data.second() = ownership != eNoOwnership;
}
{
swap(m_Ptr, a.m_Ptr);
swap(m_Data, a.m_Data);
}
bool IsOwned(void) const { return m_Ptr && m_Data.second(); }
private:
element_type* m_Ptr; ///< Internal pointer representation.
mutable pair_base_member<deleter_type, bool> m_Data; ///< State info.
/// Release for const object.
element_type* x_Release(void) const
{
return const_cast<AutoPtr<X, Del>*>(this)->release();
}
};
/////////////////////////////////////////////////////////////////////////////
///
/// AutoArray --
///
/// "AutoPtr" like class for using with arrays
///
/// vector<> template comes with a performance penalty, since it always
/// initializes its content. This template is not a vector replacement,
/// it's a version of AutoPtr<> tuned for array pointers. For convenience
/// it defines array style access operator [] and size based contructor.
///
/// @sa AutoPtr
///
template< class X, class Del = ArrayDeleter<X> >
class AutoArray
{
public:
typedef X element_type; ///< Define element type.
typedef Del deleter_type; ///< Alias for template argument.
public:
/// Construct the array using C++ new[] operator
/// @note In this case you should use ArrayDeleter<> or compatible
explicit AutoArray(size_t size)
{ }
explicit AutoArray(element_type* p = 0)
: m_Ptr(p), m_Data(true)
{ }
AutoArray(element_type* p, const deleter_type& deleter)
: m_Ptr(p), m_Data(deleter, true)
{ }
: m_Ptr(0), m_Data(p.m_Data)
{
}
~AutoArray(void)
{
reset();
}
/// Assignment operator.
{
if (this != &p) {
bool owner = p.m_Data.second();
m_Data.second() = owner;
}
return *this;
}
/// Assignment operator.
{
reset(p);
return *this;
}
/// Bool operator for use in if() clause.
/// Get pointer.
element_type* get (void) const { return m_Ptr; }
/// Release will release ownership of pointer to caller.
{
m_Data.second() = false;
return m_Ptr;
}
/// Array style dereference (returns value)
const element_type& operator[](size_t pos) const { return m_Ptr[pos]; }
/// Array style dereference (returns reference)
element_type& operator[](size_t pos) { return m_Ptr[pos]; }
/// Reset will delete the old pointer, set content to the new value,
/// and assume the ownership upon the new pointer.
void reset(element_type* p = 0)
{
if (m_Ptr != p) {
if (m_Ptr && m_Data.second()) {
m_Data.first().Delete(release());
}
m_Ptr = p;
}
m_Data.second() = true;
}
{
swap(m_Ptr, a.m_Ptr);
swap(m_Data, a.m_Data);
}
private:
/// Release for const object.
element_type* x_Release(void) const
{
return const_cast<AutoArray<X, Del>*>(this)->release();
}
private:
mutable pair_base_member<deleter_type, bool> m_Data; ///< State info.
};
/////////////////////////////////////////////////////////////////////////////
///
/// CNullable --
///
/// A value whith 'unassigned' state.
///
/// Define "null" pointer value.
#ifdef __cpp_using_enum
enum class ENull {
null = 0
};
using enum ENull;
#else
enum ENull {
null = 0
};
#endif
// Default callback for null value - throws CCoreException.
NCBI_NORETURN NCBI_XNCBI_EXPORT void g_ThrowOnNull(void);
// Default callback template.
template <class TValue>
{
TValue operator()(void) const
{
}
};
/// Template class allowing to store a value or null (unassigned) state.
/// TNullToValue functor can be used to perform an action when the value
/// is requested from a null object. By default CCoreException is thrown.
/// To perform other actions (e.g. provide a default value) the functor
/// must define 'TValue operator()(void) const' method.
/// @deprecated: Use std::optional<> instead.
template <class TValue, class TNullToValue = SThrowOnNull<TValue> >
class CNullable
//
// DEPRECATED! - Use std::optional<> instead.
//
{
public:
/// Create an empty nullable.
CNullable(ENull = null)
: m_IsNull(true) {}
/// Initialize nullable with a specific value.
CNullable(TValue value)
/// Check if the object is unassigned.
bool IsNull(void) const
{
return m_IsNull;
}
/// Get nullable value.
/// If NULL, then call TNullToValue and use the value return by the latter.
/// @attention The default implementation of TNullToValue (g_ThrowOnNull)
/// throws an exception!
operator TValue(void) const
{
return m_IsNull ? TNullToValue()() : m_Value;
}
/// Get a const reference to the current value. If NULL, the reference is
/// a copy of the default value or throw (depending on TNullToValue
/// implementation). In any case the IsNull state is unchanged.
const TValue& GetValue(void) const
{
if ( m_IsNull ) {
const_cast<TValue&>(m_Value) = TNullToValue()();
}
return m_Value;
}
/// Get a non-const reference to the value. If NULL, try to initialize this
/// instance with the default value or throw.
TValue& SetValue(void)
{
if ( m_IsNull ) {
*this = TNullToValue()();
}
return m_Value;
}
/// Assign a value to the nullable.
{
m_IsNull = false; m_Value = value;
return *this;
}
/// Reset nullable to unassigned state.
CNullable& operator= (ENull /*null_value*/)
{
m_IsNull = true;
return *this;
}
private:
bool m_IsNull;
TValue m_Value;
};
template <class TValue, class TNullToValue = SThrowOnNull<TValue> >
{
return (l.IsNull() && r.IsNull()) ||
(!l.IsNull() && !r.IsNull() && l.GetValue() == r.GetValue());
}
template <class TValue, class TNullToValue = SThrowOnNull<TValue> >
{
return !operator==(l, r);
}
// "min" and "max" templates
//
// Always get rid of the old non-conformant min/max macros
#ifdef min
# undef min
#endif
#ifdef max
# undef max
#endif
// strdup()
//
#ifndef HAVE_STRDUP
/// Supply string duplicate function, if one is not defined.
extern char* strdup(const char* str);
#endif
// ITERATE
// NON_CONST_ITERATE
// REVERSE_ITERATE
// NON_CONST_REVERSE_ITERATE
// ERASE_ITERATE
//
// Useful macros to write 'for' statements with the STL container iterator as
// a variable.
//
// *ITERATE helper to enforce constness of the container reference
template<typename Type>
inline const Type& s_ITERATE_ConstRef(const Type& obj)
{
return obj;
}
#define ITERATE_CONST(Cont) NCBI_NS_NCBI::s_ITERATE_ConstRef(Cont)
// *ITERATE helper to verify that the container isn't a temporary object
#ifdef _DEBUG
template<typename Type>
inline bool s_ITERATE_SameObject(const Type& obj1, const Type& obj2)
{
return &obj1 == &obj2;
}
# define ITERATE_BEGIN(Cont, Begin) \
(NCBI_ASSERT_EXPR(NCBI_NS_NCBI::s_ITERATE_SameObject(Cont, Cont), \
"rvalue container in *ITERATE"), (Cont).Begin())
#else
# define ITERATE_BEGIN(Cont, Begin) ((Cont).Begin())
#endif
// *ITERATE helper macro to declare iterator variable
#if 0 && defined(NCBI_HAVE_CXX11)
# define ITERATE_VAR(Type) auto
#else
# define ITERATE_VAR(Type) Type
#endif
/// ITERATE macro to sequence through container elements.
#define ITERATE(Type, Var, Cont) \
for ( ITERATE_VAR(Type::const_iterator) \
Var = ITERATE_BEGIN(ITERATE_CONST(Cont), begin), \
NCBI_NAME2(Var,_end) = ITERATE_CONST(Cont).end(); \
Var != NCBI_NAME2(Var,_end); ++Var )
/// Non constant version of ITERATE macro.
#define NON_CONST_ITERATE(Type, Var, Cont) \
for ( ITERATE_VAR(Type::iterator) Var = ITERATE_BEGIN(Cont, begin); \
Var != (Cont).end(); ++Var )
/// ITERATE macro to reverse sequence through container elements.
#define REVERSE_ITERATE(Type, Var, Cont) \
for ( ITERATE_VAR(Type::const_reverse_iterator) \
Var = ITERATE_BEGIN(ITERATE_CONST(Cont), rbegin), \
NCBI_NAME2(Var,_end) = ITERATE_CONST(Cont).rend(); \
Var != NCBI_NAME2(Var,_end); ++Var )
/// Non constant version of REVERSE_ITERATE macro.
#define NON_CONST_REVERSE_ITERATE(Type, Var, Cont) \
for ( ITERATE_VAR(Type::reverse_iterator) \
Var = ITERATE_BEGIN(Cont, rbegin); \
Var != (Cont).rend(); ++Var )
/// Non-constant version with ability to erase current element, if container
/// permits. Use only on containers, for which erase do not ruin other
/// iterators into the container, e.g. map, list, but NOT vector.
/// See also VECTOR_ERASE
#define ERASE_ITERATE(Type, Var, Cont) \
for ( ITERATE_VAR(Type::iterator) Var = ITERATE_BEGIN(Cont, begin), \
NCBI_NAME2(Var,_next) = Var; \
(Var = NCBI_NAME2(Var,_next)) != (Cont).end() && \
(++NCBI_NAME2(Var,_next), true); )
/// Use this macro inside body of ERASE_ITERATE cycle to erase from
/// vector-like container. Plain erase() call would invalidate Var_next
/// iterator and would make the cycle controlling code to fail.
#define VECTOR_ERASE(Var, Cont) (NCBI_NAME2(Var,_next) = (Cont).erase(Var))
/// The body of the loop will be run with Var equal to false and then true.
/// The seemlingly excessive complexity of this macro is to get around a couple of limitations:
/// * A bool only has two states, so it's not possible to represent the complete state space
/// of (first iteration, second iteration, done) without another variable.
/// * The variables declared in a for-loop's first part must be of the same type, so
/// the other variable has to be a bool instead of something more convenient such as
/// as a loop-counter.
#define ITERATE_BOTH_BOOL_VALUES(BoolVar) \
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 )
/// idx loops from 0 (inclusive) to up_to (exclusive)
#define ITERATE_0_IDX(idx, up_to) \
for( TSeqPos idx = 0; idx < up_to; ++idx )
/// Just repeat the body of the loop num_iters times
#define ITERATE_SIMPLE(num_iters) \
ITERATE_0_IDX( _dummy_idx_94768308_##__LINE__, num_iters ) // the number has no significance; it is entirely random.
/// Type for sequence locations and lengths.
///
/// Use this typedef rather than its expansion, which may change.
typedef unsigned int TSeqPos;
/// Define special value for invalid sequence position.
const TSeqPos kInvalidSeqPos = ((TSeqPos) (-1));
/// Type for signed sequence position.
///
/// Use this type when and only when negative values are a possibility
/// for reporting differences between positions, or for error reporting --
/// though exceptions are generally better for error reporting.
/// Use this typedef rather than its expansion, which may change.
typedef int TSignedSeqPos;
/// Template class for strict ID types.
template<class TKey, class TStorage>
class CStrictId
{
public:
typedef TStorage TId;
CStrictId(void) : m_Id(0) {}
CStrictId(const TThis& other) : m_Id(other.m_Id) {}
TThis& operator=(const TThis& other) { m_Id = other.m_Id; return *this; }
bool operator==(const TThis& id) const { return m_Id == id.m_Id; }
bool operator!=(const TThis& id) const { return m_Id != id.m_Id; }
bool operator<(const TThis& id) const { return m_Id < id.m_Id; }
bool operator<=(const TThis& id) const { return m_Id <= id.m_Id; }
bool operator>(const TThis& id) const { return m_Id > id.m_Id; }
bool operator>=(const TThis& id) const { return m_Id >= id.m_Id; }
TThis& operator++(void) { m_Id++; return *this; }
TThis operator++(int) { TThis tmp = *this; m_Id++; return tmp; }
TThis& operator--(void) { m_Id--; return *this; }
TThis operator--(int) { TThis tmp = *this; m_Id--; return tmp; }
TThis operator+(const TThis& id) const { return TThis(m_Id + id.m_Id); }
TThis operator-(const TThis& id) const { return TThis(m_Id - id.m_Id); }
TThis operator-(void) const { return TThis(-m_Id); }
//template<typename T>
//operator typename enable_if<is_same<T, bool>::value, bool>::type(void) const { return m_Id != 0; }
TId Get(void) const { return m_Id; }
void Set(TId id) { m_Id = id; }
TId& Set(void) { return m_Id; }
#if !defined(NCBI_TEST_APPLICATION)
template<typename T>
explicit CStrictId(T id, typename enable_if<is_same<T, TId>::value, T>::type = 0) : m_Id(id) {}
private:
#else
template<typename T>
CStrictId(T id, typename enable_if<is_arithmetic<T>::value, T>::type = 0) : m_Id(id) {}
template<typename T>
typename enable_if<is_arithmetic<T>::value, TThis>::type& operator=(T id) { m_Id = id; return *this; }
template<typename T>
typename enable_if<is_arithmetic<T>::value, bool>::type operator==(T id) const { return m_Id == id; }
operator T(void) const { return static_cast<T>(m_Id); }
#endif
private:
};
template<class TKey, class TStorage>
inline
{
return out << id.Get();
}
template<class TKey, class TStorage>
inline
{
in >> id.Set();
return in;
}
/// Type for sequence GI.
///
/// Use this typedef rather than its expansion, which may change.
//#define NCBI_INT4_GI
//#define NCBI_STRICT_GI
//#define NCBI_STRICT_ENTREZ_ID
//#define NCBI_STRICT_TAX_ID
#if defined(NCBI_INT4_GI)
# ifdef NCBI_INT8_GI
# error "Both NCBI_INT4_GI and NCBI_INT8_GI must not be defined!"
# endif
# ifdef NCBI_STRICT_GI
# error "Both NCBI_INT4_GI and NCBI_STRICT_GI must not be defined!"
# endif
#elif !defined(NCBI_INT8_GI)
# define NCBI_INT8_GI
#endif
#ifdef NCBI_TEST_STRICT_ENTREZ_ID
// Allow strict TEntrezId test builds
#define NCBI_STRICT_ENTREZ_ID
#else
// Temporary fix: disable strict TEntrezId
# ifdef NCBI_STRICT_ENTREZ_ID
# undef NCBI_STRICT_ENTREZ_ID
# endif
#endif
#ifndef NCBI_STRICT_GI
# undef NCBI_STRICT_ENTREZ_ID
# undef NCBI_STRICT_TAX_ID
#endif
#ifdef NCBI_INT8_GI
// Generic id type which needs to be the same size as GI.
typedef Int8 TIntId;
typedef Uint8 TUintId;
#else // NCBI_INT8_GI
typedef int TGi;
typedef Int4 TIntId;
typedef Uint4 TUintId;
#endif
/// Key structs must always be defined - they are used in aliasinfo.cpp
struct SStrictId_Gi {
typedef TIntId TId;
};
typedef TIntId TId;
};
struct SStrictId_Tax {
typedef int TId;
};
#ifdef NCBI_STRICT_GI
/// @deprecated: Use TGi/TEntrezId typedefs.
#else // NCBI_STRICT_GI
#endif // NCBI_STRICT_GI
/// TEntrezId type for entrez ids which require the same strictness as TGi.
#ifdef NCBI_STRICT_ENTREZ_ID
#else
#endif
/// Taxon id type.
#ifdef NCBI_STRICT_TAX_ID
#else
#endif
/// a helper template to enforce constness of argument to GI_CONST macro
template<class TId, TId id>
public:
#ifndef NCBI_COMPILER_MSVC
enum : TId {
value = id
};
#else
static const TId value = id;
#endif
};
#ifdef NCBI_STRICT_GI
/// Macros to convert TGi to other types (int, unsigned etc.).
#define STRICT_ID_TO(TId, TInt, id) (static_cast<TInt>((id).Get()))
#define STRICT_ID_FROM(TIdType, TIntType, id) (TIdType(static_cast<TIdType::TId>(id)))
#define STRICT_ID_CONST(type, id) \
(type(static_cast<type::TId>(ncbi::CConstIdChecker<type::TId, id>::value)))
#define STRICT_ID_ZERO(type) STRICT_ID_CONST(type, 0)
#define STRICT_ID_INVALID(type) STRICT_ID_CONST(type, -1)
#else // NCBI_STRICT_GI
#define STRICT_ID_TO(TId, TInt, id) (static_cast<TInt>(id))
#define STRICT_ID_FROM(TIdType, TIntType, id) (static_cast<TIdType>(id))
#define STRICT_ID_CONST(type, id) (ncbi::CConstIdChecker<type, id>::value)
#define STRICT_ID_ZERO(type) type(0)
#define STRICT_ID_INVALID(type) type(-1)
#endif // NCBI_STRICT_GI
#define GI_TO(T, gi) STRICT_ID_TO(ncbi::TGi, T, gi)
#define GI_FROM(T, value) STRICT_ID_FROM(ncbi::TGi, T, value)
#define GI_CONST(gi) STRICT_ID_CONST(ncbi::TGi, gi)
#define ZERO_GI STRICT_ID_ZERO(ncbi::TGi)
#define INVALID_GI STRICT_ID_INVALID(ncbi::TGi)
#ifdef NCBI_STRICT_ENTREZ_ID
# define ENTREZ_ID_TO(T, entrez_id) STRICT_ID_TO(ncbi::TEntrezId, T, entrez_id)
# define ENTREZ_ID_FROM(T, value) STRICT_ID_FROM(ncbi::TEntrezId, T, value)
# define ENTREZ_ID_CONST(id) STRICT_ID_CONST(ncbi::TEntrezId, id)
#else
# define ENTREZ_ID_TO(T, entrez_id) (static_cast<T>(entrez_id))
# define ENTREZ_ID_FROM(T, value) (static_cast<ncbi::TEntrezId>(value))
# define ENTREZ_ID_CONST(id) id
#endif
#define ZERO_ENTREZ_ID ENTREZ_ID_CONST(0)
#define INVALID_ENTREZ_ID ENTREZ_ID_CONST(-1)
#ifdef NCBI_STRICT_TAX_ID
# define TAX_ID_TO(T, tax_id) STRICT_ID_TO(ncbi::TTaxId, T, tax_id)
# define TAX_ID_FROM(T, value) STRICT_ID_FROM(ncbi::TTaxId, T, value)
# define TAX_ID_CONST(id) STRICT_ID_CONST(ncbi::TTaxId, id)
#else
# define TAX_ID_TO(T, tax_id) (static_cast<T>(tax_id))
# define TAX_ID_FROM(T, value) (static_cast<ncbi::TTaxId>(value))
# define TAX_ID_CONST(id) id
#endif
#define ZERO_TAX_ID TAX_ID_CONST(0)
#define INVALID_TAX_ID TAX_ID_CONST(-1)
/// Convert gi-compatible int to/from other types.
#define INT_ID_TO(T, id) (static_cast<T>(id))
#define INT_ID_FROM(T, value) (static_cast<ncbi::TIntId>(value))
/// Helper address class
{
public:
/// add offset to object reference (to get object's member)
static void* Add(void* object, ssize_t offset);
static const void* Add(const void* object, ssize_t offset);
/// calculate offset inside object
static ssize_t Sub(const void* first, const void* second);
};
inline
void* CRawPointer::Add(void* object, ssize_t offset)
{
return static_cast<char*> (object) + offset;
}
inline
const void* CRawPointer::Add(const void* object, ssize_t offset)
{
return static_cast<const char*> (object) + offset;
}
inline
ssize_t CRawPointer::Sub(const void* first, const void* second)
{
return (ssize_t)/*ptrdiff_t*/
(static_cast<const char*> (first) - static_cast<const char*> (second));
}
/// Buffer with an embedded pre-reserved space.
///
/// It is convenient to use if you want to avoid allocation in heap
/// for smaller requested sizes, and use stack for such cases.
/// @example:
/// CFastBuffer<2048> buf(some_size);
template <size_t KEmbeddedSize, class TType = char>
{
public:
CFastBuffer(size_t buf_size)
: m_Size(buf_size),
m_Buffer(buf_size <= KEmbeddedSize ? m_EmbeddedBuffer : new TType[buf_size])
{}
TType operator[] (size_t pos) const { return m_Buffer[pos]; }
TType& operator* (void) { return *m_Buffer; }
const TType& operator* (void) const { return *m_Buffer; }
TType* operator+ (size_t offset) { return m_Buffer + offset; }
const TType* operator+ (size_t offset) const { return m_Buffer + offset; }
TType* begin(void) { return m_Buffer; }
const TType* begin(void) const { return m_Buffer; }
TType* end(void) { return m_Buffer + m_Size; }
const TType* end(void) const { return m_Buffer + m_Size; }
size_t size(void) const { return m_Size; }
private:
size_t m_Size;
TType* m_Buffer;
TType m_EmbeddedBuffer[KEmbeddedSize];
};
/// Macro used to mark a constructor as deprecated.
///
/// The correct syntax for this varies from compiler to compiler:
/// older versions of GCC (prior to 3.4) require NCBI_DEPRECATED to
/// follow any relevant constructor declarations, but some other
/// compilers (Microsoft Visual Studio 2005, IBM Visual Age / XL)
/// require it to precede any relevant declarations, whether or not
/// they are for constructors.
#if defined(NCBI_COMPILER_MSVC) || defined(NCBI_COMPILER_VISUALAGE)
# define NCBI_DEPRECATED_CTOR(decl) NCBI_DEPRECATED decl
#else
# define NCBI_DEPRECATED_CTOR(decl) decl NCBI_DEPRECATED
#endif
/// Macro used to mark a class as deprecated.
///
/// @sa NCBI_DEPRECATED_CTOR
#define NCBI_DEPRECATED_CLASS NCBI_DEPRECATED_CTOR(class)
//#define NCBI_ENABLE_SAFE_FLAGS
#ifdef NCBI_ENABLE_SAFE_FLAGS
/////////////////////////////////////////////////////////////////////////////
/// Support for safe enum flags
/////////////////////////////////////////////////////////////////////////////
///
/// The CSafeFlags enum is used to define flags with enum definition
/// so that they preserve type after bit-wise operations,
/// and doesn't allow to be used in context of another enum/flags/int type.
/// With the definition of enum, usually inside class that uses it:
/// class CMyClass {
// public:
/// enum EFlags {
/// fFlag1 = 1<<0,
/// fFlag2 = 1<<1,
/// fFlag3 = 1<<1,
/// fMask = fFlag1|fFlag2
/// };
/// you can add at the same level a macro declaration:
/// DECLARE_SAFE_FLAGS_TYPE(EFlags, TFlags);
/// };
/// and then outside the class, or at the same level if it's not a class definition:
/// DECLARE_SAFE_FLAGS(CMyClass::EFlags);
/// The first macro DECLARE_SAFE_FLAGS_TYPE() declares a typedef for safe-flags.
/// The second macro DECLARE_SAFE_FLAGS() marks the enum as a safe-flags enum, so that
/// bit-wise operations on its values will preserve the safe-flags type.
/// No other modification is necessary in code that uses enum flags correctly.
/// In case the enum values are used in a wrong context, like with a different enum type,
/// compilation error will occur.
/// Safe enum flags template, not to be used explicitly.
/// Use macros DECLARE_SAFE_FLAGS_TYPE and DECLARE_SAFE_FLAGS instead.
template<class Enum>
class CSafeFlags {
public:
typedef Enum enum_type;
: m_Flags(0)
{
}
explicit
{
}
: m_Flags(static_cast<storage_type>(flags))
{
}
storage_type get() const
{
return m_Flags;
}
bool operator==(const CSafeFlags& b) const
{
return get() == b.get();
}
bool operator!=(const CSafeFlags& b) const
{
return get() != b.get();
}
// the following operators are necessary to allow comparison with 0
bool operator==(int v) const
{
return get() == storage_type(v);
}
bool operator!=(int v) const
{
return get() != storage_type(v);
}
{
return CSafeFlags(~get());
}
{
return CSafeFlags(get() & b.get());
}
{
m_Flags &= b.get();
return *this;
}
{
return CSafeFlags(get() | b.get());
}
{
m_Flags |= b.get();
return *this;
}
{
return CSafeFlags(get() ^ b.get());
}
{
m_Flags ^= b.get();
return *this;
}
private:
};
/// Macro DECLARE_SAFE_FLAGS_TYPE defines a typedef for safe-flags.
/// First argument is enum name, second argument is the new typedef name.
/// In place of old typedef:
/// typedef int TFlags;
/// put new macro:
/// DECLARE_SAFE_FLAGS_TYPE(EFlags, TFlags);
#define DECLARE_SAFE_FLAGS_TYPE(E, T) \
typedef NCBI_NS_NCBI::CSafeFlags<E> T
/// Macro DECLARE_SAFE_FLAGS marks a enum as safe-flags enum.
/// The argument is the enum name.
/// If the enum is defined inside a class then DECLARE_SAFE_FLAGS()
/// must be placed outside the class definition:
/// DECLARE_SAFE_FLAGS(CMyClass::EFlags);
#define DECLARE_SAFE_FLAGS(E) \
inline NCBI_NS_NCBI::CSafeFlags<E> operator|(E a, E b) \
{ return NCBI_NS_NCBI::CSafeFlags<E>(a) | b; } \
inline NCBI_NS_NCBI::CSafeFlags<E> operator&(E a, E b) \
{ return NCBI_NS_NCBI::CSafeFlags<E>(a) & b; } \
inline NCBI_NS_NCBI::CSafeFlags<E> operator^(E a, E b) \
{ return NCBI_NS_NCBI::CSafeFlags<E>(a) ^ b; } \
inline NCBI_NS_NCBI::CSafeFlags<E> operator~(E a) \
{ return ~NCBI_NS_NCBI::CSafeFlags<E>(a); }
/// Helper operators for safe-flags enums.
/// These operators will be used only for enums marked
/// as safe-flag enums by macro DECLARE_SAFE_FLAGS()
template<class E> inline CSafeFlags<E> operator|(E a, CSafeFlags<E> b)
{
return b | a;
}
template<class E> inline CSafeFlags<E> operator&(E a, CSafeFlags<E> b)
{
return b & a;
}
template<class E> inline CSafeFlags<E> operator^(E a, CSafeFlags<E> b)
{
return b ^ a;
}
template<class E> inline
ostream& operator<<(ostream& out, const CSafeFlags<E>& v)
{
return out << v.get();
}
#else // NCBI_ENABLE_SAFE_FLAGS
// backup implementation of safe flag macros
# define DECLARE_SAFE_FLAGS_TYPE(Enum,Typedef) typedef underlying_type<Enum>::type Typedef
# define DECLARE_SAFE_FLAGS(Enum) NCBI_EAT_SEMICOLON(safe_flags)
#endif // NCBI_ENABLE_SAFE_FLAGS
/// CNcbiActionGuard class
/// Executes registered callbacks on request or on destruction.
{
public:
virtual ~CNcbiActionGuard(void) { ExecuteActions(); }
template<class TFunc> void AddAction(TFunc func)
{
m_Actions.push_back(unique_ptr<CAction_Base>(new CAction<TFunc>(func)));
}
void ExecuteActions(void)
{
try {
(*it)->Execute();
}
catch (exception& e) {
ERR_POST("Error executing action: " << e.what());
}
}
m_Actions.clear(); // prevent multiple executions
}
private:
// Action wrapper
class CAction_Base
{
public:
CAction_Base(void) {}
virtual ~CAction_Base() {}
virtual void Execute(void) const = 0;
private:
};
template<class TFunc> class CAction : public CAction_Base
{
public:
CAction(TFunc func) : m_Func(func) {}
virtual ~CAction(void) {}
void Execute(void) const override { m_Func(); }
private:
};
typedef list<unique_ptr<CAction_Base> > TActions;
};
/// Template helpers for unique_ptr to work with resource allocating/deallocating C functions.
/// @{
/// Eliminates the necessity for specifying type of deallocating C function.
template <class T>
using c_unique_ptr = unique_ptr<T, void(*)(T*)>;
/// Eliminates the necessity for specifying types of both allocated resource and deallocating C function.
template <class T, typename TDeleter>
unique_ptr<T, TDeleter> make_c_unique(T* p, TDeleter d)
{
return {p, d};
}
/// Overload for the above for all types of allocated memory that are to be deallocated by free()
template <class T>
unique_ptr<T, void(*)(void*)> make_c_unique(T* p)
{
return make_c_unique(p, &free);
}
/// @}
/// Helpers for exporting stand-alone functions from DLLs without changing the functions.
/// Useful for exporting third-party APIs without a need to adjust third-party headers.
/// @example:
/// dll_header.hpp: NCBI_EXPORT_FUNC_DECLARE(XCONNECT, mbedtls_strerror);
/// dll_source.cpp: NCBI_EXPORT_FUNC_DEFINE(XCONNECT, mbedtls_strerror);
/// app.cpp: NCBI_XCONNECT::mbedtls_strerror(err, buf, sizeof(buf));
/// @{
#define NCBI_EXPORT_FUNC_DECLARE(lib, func) \
namespace NCBI_ ## lib \
{ \
namespace S ## func \
{ \
using T = decltype(func); \
\
NCBI_ ## lib ## _EXPORT T* F(); \
\
template <class T> \
struct S; \
\
template <class TR, class... TArgs> \
struct S<TR (TArgs...)> \
{ \
static TR Call(TArgs... args) { return F()(args...); } \
}; \
} \
\
constexpr auto func = S ## func::S<S ## func::T>::Call; \
}
#define NCBI_EXPORT_FUNC_DEFINE(lib, func) \
namespace NCBI_ ## lib \
{ \
namespace S ## func \
{ \
T* F() { return ::func; } \
} \
}
/// @}
template<class T1, class T2>
inline
void swap(NCBI_NS_NCBI::pair_base_member<T1,T2>& pair1,
NCBI_NS_NCBI::pair_base_member<T1,T2>& pair2)
{
pair1.Swap(pair2);
}
template<class P, class D>
inline
void swap(NCBI_NS_NCBI::AutoPtr<P,D>& ptr1,
NCBI_NS_NCBI::AutoPtr<P,D>& ptr2)
{
ptr1.Swap(ptr2);
}
#if defined(NCBI_COMPILER_WORKSHOP) || defined(NCBI_COMPILER_MIPSPRO)
#define ArraySize(array) (sizeof(array)/sizeof((array)[0]))
#else
template<class Element, size_t Size>
inline
constexpr size_t ArraySize(const Element (&)[Size])
{
return Size;
}
#ifdef NCBI_STRICT_GI
template <class TKey, class TStorage> struct hash<ncbi::CStrictId<TKey, TStorage>>
{
size_t operator()(const ncbi::CStrictId<TKey, TStorage> & x) const
{
return hash<TStorage>()(x.Get());
}
};
#endif /* NCBI_STRICT_GI */
#endif
/* @} */
#endif /* CORELIB___NCBIMISC__HPP */
bool operator!=(const _Ht_iterator< _Val, _Nonconst_traits< _Val >, _Key, _HF, _ExK, _EqK, _All > &__x, const _Ht_iterator< _Val, _Const_traits< _Val >, _Key, _HF, _ExK, _EqK, _All > &__y)
Definition: _hashtable.h:173
AutoArray –.
Definition: ncbimisc.hpp:527
AutoPtr –.
Definition: ncbimisc.hpp:401
Template used to replace bool type arguments with some strict equivalent.
Definition: ncbimisc.hpp:310
a helper template to enforce constness of argument to GI_CONST macro
Definition: ncbimisc.hpp:1054
CNcbiActionGuard class Executes registered callbacks on request or on destruction.
Definition: ncbimisc.hpp:1387
Template class allowing to store a value or null (unassigned) state.
Definition: ncbimisc.hpp:676
Helper address class.
Definition: ncbimisc.hpp:1126
Support for safe enum flags.
Definition: ncbimisc.hpp:1250
Template class for strict ID types.
Definition: ncbimisc.hpp:893
Template used for empty base class optimization.
Definition: ncbimisc.hpp:246
static uch flags
#define T(s)
Definition: common.h:230
bool operator==(const CEquivRange &A, const CEquivRange &B)
CNcbiOstream & operator<<(CNcbiOstream &out, const CEquivRange &range)
Definition: equiv_range.cpp:96
std::ofstream out("events_result.xml")
main entry point for tests
#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
CNcbiIstream & operator>>(CNcbiIstream &s, const getcontig &c)
element_type * m_Ptr
Internal pointer representation.
Definition: ncbimisc.hpp:500
TValue operator()(void) const
Definition: ncbimisc.hpp:658
virtual ~CNcbiActionGuard(void)
Definition: ncbimisc.hpp:1390
SStrictId_Entrez::TId TEntrezId
TEntrezId type for entrez ids which require the same strictness as TGi.
Definition: ncbimisc.hpp:1041
CNcbiActionGuard(void)
Definition: ncbimisc.hpp:1389
const Type & s_ITERATE_ConstRef(const Type &obj)
Definition: ncbimisc.hpp:787
NCBI_XNCBI_EXPORT void g_ThrowOnNull(void)
Definition: ncbiexpt.cpp:861
Del deleter_type
Alias for template argument.
Definition: ncbimisc.hpp:404
#define DECLARE_OPERATOR_BOOL(Expr)
Declaration of safe bool operator from boolean expression.
Definition: ncbimisc.hpp:199
CStrictId(void)
Definition: ncbimisc.hpp:898
~AutoPtr(void)
Destructor.
Definition: ncbimisc.hpp:434
CNcbiActionGuard & operator=(const CNcbiActionGuard &)
ETriState
Enumeration to represent a tristate value.
Definition: ncbimisc.hpp:128
CSafeFlags operator~() const
Definition: ncbimisc.hpp:1294
AutoPtr< X, Del > & operator=(const AutoPtr< X, Del > &p)
Assignment operator.
Definition: ncbimisc.hpp:440
CBoolEnum(bool value)
Definition: ncbimisc.hpp:313
void AddAction(TFunc func)
Definition: ncbimisc.hpp:1392
bool IsOwned(void) const
Definition: ncbimisc.hpp:497
CAction_Base & operator=(const CAction_Base &)
X element_type
Define element type.
Definition: ncbimisc.hpp:529
CSafeFlags & operator|=(const CSafeFlags &b)
Definition: ncbimisc.hpp:1313
bool operator==(TBoolType) const
~AutoArray(void)
Definition: ncbimisc.hpp:554
element_type * x_Release(void) const
Release for const object.
Definition: ncbimisc.hpp:504
Uint8 TUintId
Definition: ncbimisc.hpp:1000
void reset(element_type *p=0, EOwnership ownership=eTakeOwnership)
Reset will delete the old pointer (if owned), set content to the new value, and assume the ownership ...
Definition: ncbimisc.hpp:480
void ExecuteActions(void)
Definition: ncbimisc.hpp:1397
storage_type get() const
Definition: ncbimisc.hpp:1269
TType * begin(void)
Definition: ncbimisc.hpp:1182
CSafeFlags operator&(const CSafeFlags &b) const
Definition: ncbimisc.hpp:1299
ERetriable
Can the action be retried?
Definition: ncbimisc.hpp:167
void Swap(AutoPtr< X, Del > &a)
Definition: ncbimisc.hpp:491
void Swap(pair_base_member< first_type, second_type > &p)
Definition: ncbimisc.hpp:287
pair_base_member< deleter_type, bool > m_Data
State info.
Definition: ncbimisc.hpp:501
Member second_type
Definition: ncbimisc.hpp:251
bool operator<(const TThis &id) const
Definition: ncbimisc.hpp:904
Member member_type
Definition: ncbimisc.hpp:250
element_type & operator*(void) const
Dereference operator.
Definition: ncbimisc.hpp:463
size_t size(void) const
Definition: ncbimisc.hpp:1188
CSafeFlags operator|(const CSafeFlags &b) const
Definition: ncbimisc.hpp:1309
bool operator!=(TBoolType) const
AutoArray< X, Del > & operator=(const AutoArray< X, Del > &p)
Assignment operator.
Definition: ncbimisc.hpp:560
static ssize_t Sub(const void *first, const void *second)
calculate offset inside object
Definition: ncbimisc.hpp:1149
bool m_Value
Definition: ncbimisc.hpp:322
const first_type & first() const
Definition: ncbimisc.hpp:269
bool IsNull(void) const
Check if the object is unassigned.
Definition: ncbimisc.hpp:686
element_type * operator->(void) const
Reference operator.
Definition: ncbimisc.hpp:466
CFastBuffer(size_t buf_size)
Definition: ncbimisc.hpp:1168
bool m_IsNull
Definition: ncbimisc.hpp:736
TGi CStrictGi
Definition: ncbimisc.hpp:1028
size_t m_Size
Definition: ncbimisc.hpp:1191
member_type m_Member
Definition: ncbimisc.hpp:298
void Execute(void) const override
Definition: ncbimisc.hpp:1431
X element_type
Define element type.
Definition: ncbimisc.hpp:403
ERound
Whether to truncate/round a value.
Definition: ncbimisc.hpp:136
TThis & operator=(const TThis &other)
Definition: ncbimisc.hpp:900
static void * Add(void *object, ssize_t offset)
add offset to object reference (to get object's member)
Definition: ncbimisc.hpp:1137
element_type * x_Release(void) const
Release for const object.
Definition: ncbimisc.hpp:617
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
void Swap(AutoPtr< X, Del > &a)
Definition: ncbimisc.hpp:609
storage_type m_Flags
Definition: ncbimisc.hpp:1330
bool operator==(const TThis &id) const
Definition: ncbimisc.hpp:902
bool operator<=(const TThis &id) const
Definition: ncbimisc.hpp:905
CSafeFlags operator^(const CSafeFlags &b) const
Definition: ncbimisc.hpp:1319
constexpr size_t ArraySize(const Element(&)[Size])
Definition: ncbimisc.hpp:1532
unique_ptr< T, void(*)(T *)> c_unique_ptr
Template helpers for unique_ptr to work with resource allocating/deallocating C functions.
Definition: ncbimisc.hpp:1444
AutoArray(size_t size)
Construct the array using C++ new[] operator.
Definition: ncbimisc.hpp:536
CStrictId< TKey, TStorage > TThis
Definition: ncbimisc.hpp:896
TType m_EmbeddedBuffer[KEmbeddedSize]
Definition: ncbimisc.hpp:1193
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
const element_type & operator[](size_t pos) const
Array style dereference (returns value)
Definition: ncbimisc.hpp:591
ENormalizePath
Whether to normalize a path.
Definition: ncbimisc.hpp:150
pair_base_member< deleter_type, bool > m_Data
State info.
Definition: ncbimisc.hpp:624
bool s_ITERATE_SameObject(const Type &obj1, const Type &obj2)
Definition: ncbimisc.hpp:796
CSafeFlags & operator^=(const CSafeFlags &b)
Definition: ncbimisc.hpp:1323
CNullable(ENull=null)
Create an empty nullable.
Definition: ncbimisc.hpp:679
underlying_type< enum_type >::type storage_type
Definition: ncbimisc.hpp:1253
bool operator>=(const TThis &id) const
Definition: ncbimisc.hpp:907
int TSignedSeqPos
Type for signed sequence position.
Definition: ncbimisc.hpp:887
element_type * get(void) const
Get pointer.
Definition: ncbimisc.hpp:469
static X * Create(void)
Default create function.
Definition: ncbimisc.hpp:342
AutoPtr(element_type *p=0)
Constructor.
Definition: ncbimisc.hpp:407
TActions m_Actions
Definition: ncbimisc.hpp:1437
TId & Set(void)
Definition: ncbimisc.hpp:923
TValue & SetValue(void)
Get a non-const reference to the value.
Definition: ncbimisc.hpp:713
static void Delete(X *object)
Array delete function.
Definition: ncbimisc.hpp:360
Int8 TIntId
Definition: ncbimisc.hpp:999
EFollowLinks
Whether to follow symbolic links (also known as shortcuts or aliases)
Definition: ncbimisc.hpp:143
TType operator[](size_t pos) const
Definition: ncbimisc.hpp:1174
CStrictId< SStrictId_Gi, SStrictId_Gi::TId > TGi
Definition: ncbimisc.hpp:1025
static void Delete(X *object)
Default delete function.
Definition: ncbimisc.hpp:351
TType * operator+(size_t offset)
Definition: ncbimisc.hpp:1179
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:1448
TThis operator+(const TThis &id) const
Definition: ncbimisc.hpp:914
SStrictId_Tax::TId TTaxId
Taxon id type.
Definition: ncbimisc.hpp:1048
Del deleter_type
Alias for template argument.
Definition: ncbimisc.hpp:530
EInterruptOnSignal
Interrupt on signal mode.
Definition: ncbimisc.hpp:160
CSafeFlags & operator&=(const CSafeFlags &b)
Definition: ncbimisc.hpp:1303
static void Delete(X *object)
C Language deallocation function.
Definition: ncbimisc.hpp:369
TType & operator*(void)
Definition: ncbimisc.hpp:1176
#define DECLARE_OPERATOR_BOOL_PTR(Ptr)
Declaration of safe bool operator from pointer expression.
Definition: ncbimisc.hpp:206
CSafeFlags< E > operator&(E a, CSafeFlags< E > b)
Definition: ncbimisc.hpp:1363
TThis & operator++(void)
Definition: ncbimisc.hpp:909
TStorage TId
Definition: ncbimisc.hpp:895
CSafeFlags< E > operator^(E a, CSafeFlags< E > b)
Definition: ncbimisc.hpp:1367
const TSeqPos kInvalidSeqPos
Define special value for invalid sequence position.
Definition: ncbimisc.hpp:878
CNullable & operator=(TValue value)
Assign a value to the nullable.
Definition: ncbimisc.hpp:722
pair_base_member(void)
Definition: ncbimisc.hpp:253
ENullable
Whether a value is nullable.
Definition: ncbimisc.hpp:113
element_type * get(void) const
Get pointer.
Definition: ncbimisc.hpp:581
TThis operator-(void) const
Definition: ncbimisc.hpp:916
TThis & operator--(void)
Definition: ncbimisc.hpp:911
TType * end(void)
Definition: ncbimisc.hpp:1185
list< unique_ptr< CAction_Base > > TActions
Definition: ncbimisc.hpp:1435
const second_type & second() const
Definition: ncbimisc.hpp:278
ENull
CNullable –.
Definition: ncbimisc.hpp:645
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
Definition: ncbimisc.hpp:1508
Enum enum_type
Definition: ncbimisc.hpp:1252
virtual void Execute(void) const =0
TId Get(void) const
Definition: ncbimisc.hpp:921
element_type * m_Ptr
Definition: ncbimisc.hpp:623
element_type * release(void)
Release will release ownership of pointer to caller.
Definition: ncbimisc.hpp:472
ESign
Signedness of a value.
Definition: ncbimisc.hpp:120
element_type * release(void)
Release will release ownership of pointer to caller.
Definition: ncbimisc.hpp:584
TValue m_Value
Definition: ncbimisc.hpp:737
bool operator!=(const TThis &id) const
Definition: ncbimisc.hpp:903
void reset(element_type *p=0)
Reset will delete the old pointer, set content to the new value, and assume the ownership upon the ne...
Definition: ncbimisc.hpp:598
bool operator>(const TThis &id) const
Definition: ncbimisc.hpp:906
TType * m_Buffer
Definition: ncbimisc.hpp:1192
const TValue & GetValue(void) const
Get a const reference to the current value.
Definition: ncbimisc.hpp:703
@ eTriState_False
The value is equivalent to false/no.
Definition: ncbimisc.hpp:130
@ eTriState_True
The value is equivalent to true/yes.
Definition: ncbimisc.hpp:131
@ eTriState_Unknown
The value is indeterminate.
Definition: ncbimisc.hpp:129
@ eRetriable_Unknown
It is unknown if the action can succeed if retried.
Definition: ncbimisc.hpp:169
@ eRetriable_No
It makes no sense to retry the action.
Definition: ncbimisc.hpp:168
@ eRetriable_Yes
It makes sense to try again.
Definition: ncbimisc.hpp:170
@ eTrunc
Value must be truncated.
Definition: ncbimisc.hpp:137
@ eRound
Value must be rounded.
Definition: ncbimisc.hpp:138
@ eNormalizePath
Normalize a path.
Definition: ncbimisc.hpp:151
@ eNotNormalizePath
Do not normalize a path.
Definition: ncbimisc.hpp:152
@ eOff
Definition: ncbi_types.h:110
@ eDefault
Definition: ncbi_types.h:112
@ eOn
Definition: ncbi_types.h:111
@ eIgnoreLinks
Do not follow symbolic links.
Definition: ncbimisc.hpp:144
@ eFollowLinks
Follow symbolic links.
Definition: ncbimisc.hpp:145
@ eRestartOnSignal
Restart operation if interrupted by a signal.
Definition: ncbimisc.hpp:162
@ eInterruptOnSignal
Cancel operation if interrupted by a signal.
Definition: ncbimisc.hpp:161
@ eNotNullable
Value cannot be null.
Definition: ncbimisc.hpp:115
@ eNullable
Value can be null.
Definition: ncbimisc.hpp:114
@ eNegative
Value is negative.
Definition: ncbimisc.hpp:121
@ ePositive
Value is positive.
Definition: ncbimisc.hpp:123
@ eZero
Value is zero.
Definition: ncbimisc.hpp:122
@ eTakeOwnership
An object can take ownership of another.
Definition: ncbi_types.h:136
@ eNoOwnership
No ownership is assumed.
Definition: ncbi_types.h:135
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
CFields operator|(CFields, CFields)
#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
#define BEGIN_NCBI_NAMESPACE
Definition: ncbistl.hpp:138
#define END_NCBI_NAMESPACE
Definition: ncbistl.hpp:139
#define BEGIN_STD_NAMESPACE
Definition: ncbistl.hpp:140
#define END_STD_NAMESPACE
Definition: ncbistl.hpp:141
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 ENcbiSwitch ESwitch
Aux.
enum ENcbiOwnership EOwnership
Ownership relations between objects.
ENcbiSwitch
Aux.
Definition: ncbi_types.h:109
ENcbiOwnership
Ownership relations between objects.
Definition: ncbi_types.h:134
#define NCBI_XNCBI_EXPORT
Definition: ncbi_export.h:1283
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
const struct ncbi::grid::netcache::search::fields::SIZE size
Magic spell ;-) needed for some weird compilers... very empiric.
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
#define strdup
Definition: ncbi_ansi_ext.h:70
unsigned int a
Definition: ncbi_localip.c:102
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_)
Functor template for deleting array of objects.
Definition: ncbimisc.hpp:358
Functor template for the C language deallocation function, free().
Definition: ncbimisc.hpp:367
Functor template for allocating object.
Definition: ncbimisc.hpp:340
Functor template for deleting object.
Definition: ncbimisc.hpp:349
Key structs must always be defined - they are used in aliasinfo.cpp.
Definition: ncbimisc.hpp:1012
Definition: _hash_fun.h:40
Definition: type.c:6
#define Type
void free(voidpf ptr)
Modified on Tue Apr 23 07:40:52 2024 by modify_doxy.py rev. 669887