45 #define CIC_GENERICID_CLASS_NAME "CompoundID"
46 #define CIC_NETCACHEBLOBKEY_CLASS_NAME "NetCacheBlobKey"
47 #define CIC_NETSCHEDULEJOBKEY_CLASS_NAME "NetScheduleJobKey"
48 #define CIC_NETSTORAGEOBJECTLOC_CLASS_NAME_V1 "NetStorageObjectLocV1"
49 #define CIC_NETSTORAGEOBJECTLOC_CLASS_NAME "NetStorageObjectLoc"
51 #define CIT_ID_TYPE_NAME "id"
52 #define CIT_INTEGER_TYPE_NAME "int"
53 #define CIT_SERVICE_NAME_TYPE_NAME "service"
54 #define CIT_DATABASE_NAME_TYPE_NAME "database"
55 #define CIT_TIMESTAMP_TYPE_NAME "time"
56 #define CIT_RANDOM_TYPE_NAME "rand"
57 #define CIT_IPV4_ADDRESS_TYPE_NAME "ipv4_addr"
58 #define CIT_HOST_TYPE_NAME "host"
59 #define CIT_PORT_TYPE_NAME "port"
60 #define CIT_IPV4_SOCK_ADDR_TYPE_NAME "ipv4_sock_addr"
61 #define CIT_OBJECTREF_TYPE_NAME "object"
62 #define CIT_STRING_TYPE_NAME "str"
63 #define CIT_BOOLEAN_TYPE_NAME "bool"
64 #define CIT_FLAGS_TYPE_NAME "flags"
65 #define CIT_LABEL_TYPE_NAME "label"
66 #define CIT_CUE_TYPE_NAME "cue"
67 #define CIT_SEQ_ID_TYPE_NAME "seq_id"
68 #define CIT_TAX_ID_TYPE_NAME "tax_id"
69 #define CIT_NESTED_CID_TYPE_NAME "nested"
107 return "eInvalidType";
139 #define CIF_GET_IMPL(ret_type, method, type, member) \
140 CIF_GET_IMPL_(ret_type, method, type, m_Impl->m_Type != type, member)
142 #define CIF_GET_IMPL_(ret_type, method, type, cond, member) \
143 ret_type CCompoundIDField::method() const \
146 NCBI_THROW_FMT(CCompoundIDException, eInvalidType, \
147 "Compound ID field type mismatch (requested: " << \
148 s_TypeNames[type] << "; actual: " << \
149 s_TypeNames[m_Impl->m_Type] << ')'); \
151 return (ret_type) m_Impl->member; \
180 m_FieldList.Append(new_entry);
181 m_HomogeneousFields[field_type].Append(new_entry);
182 new_entry->
m_Type = field_type;
192 while (field !=
NULL) {
214 return m_Impl->m_Length == 0;
234 m_Impl->m_HomogeneousFields[field_type].m_Head;
240 #define CID_APPEND_IMPL(method, field_type, val_type, member) \
241 void CCompoundID::method(val_type value) \
243 m_Impl->AppendField(field_type)->member = value; \
256 AppendTimestamp(time(
NULL));
263 AppendRandom(m_Impl->m_Pool->GetRand());
292 last->m_CID = m_Impl;
302 int indent_depth,
const char*
indent)
304 while (--indent_depth >= 0)
309 int indent_depth,
const char*
indent)
359 sstr <<
"0b" << setw(8) << setfill(
'0') <<
362 sstr <<
"0b" << setw(16) << setfill(
'0') <<
370 indent_depth + 1,
indent);
400 m_Impl->m_RandomGen.Randomize();
412 return m_Impl->UnpackV0(cid);
419 const string& cid_dump) :
452 #define CID_PARSER_EXCEPTION(message) \
453 NCBI_THROW_FMT(CCompoundIDException, eInvalidDumpSyntax, \
454 "line " << m_ErrLine << ", column " << \
455 (m_ErrPos - m_LineBegin + 1) << ": " << message)
466 const char* token_begin =
m_Ch;
476 switch (*token_begin) {
494 new_id_class_name <<
'\'');
523 switch (*token_begin) {
587 field_type_name <<
'\'');
592 switch (field_type) {
612 if (random_number >= ((
Uint8) 1) << 8 *
sizeof(
Uint4)) {
614 "random number exceeds maximum allowed value");
655 if (bool_val ==
"false")
656 result.AppendBoolean(
false);
657 else if (bool_val ==
"true")
658 result.AppendBoolean(
true);
691 else if (*
m_Ch ==
'}')
707 if (*
m_Ch++ ==
'\n') {
721 else if (*
m_Ch++ ==
'\n') {
739 if (
x_EOF() || ((quote_char = *
m_Ch) !=
'"' && quote_char !=
'\'')) {
744 const char* str_begin = ++
m_Ch;
745 bool escaped =
false;
748 if (*
m_Ch == quote_char && !escaped)
751 else if (*
m_Ch ==
'\\') {
756 if (*
m_Ch++ ==
'\n') {
774 const char* token_begin;
790 token_begin = ++
m_Ch;
795 token_begin = ++
m_Ch;
813 if (
result == 0 && errno != 0) {
822 const char* token_begin =
m_Ch;
840 if (
result == 0 && errno != 0) {
850 Uint4 ipv4_address = 0;
851 unsigned char* octet =
reinterpret_cast<unsigned char*
>(&ipv4_address);
856 goto IPv4ParsingError;
859 goto IPv4ParsingError;
863 goto IPv4ParsingError;
864 unsigned digit = *
m_Ch -
'0';
867 goto IPv4ParsingError;
868 }
else if (*
m_Ch ==
'.') {
872 goto IPv4ParsingError;
874 *octet++ = (
unsigned char)
number;
875 }
while (--dots > 0);
877 goto IPv4ParsingError;
880 goto IPv4ParsingError;
885 unsigned digit = *
m_Ch -
'0';
888 goto IPv4ParsingError;
895 *octet = (
unsigned char)
number;
906 if (port_number >= 1 << 8 *
sizeof(
Uint2)) {
909 return (
Uint2) port_number;
924 #define SCRAMBLE_PASS() \
926 counter = seq_len - 1; \
928 pos[1] = (unsigned char)(pos[1] ^ *pos ^ length_factor--); \
930 } while (--counter > 0);
935 unsigned char length_factor = (
unsigned char)(((
unsigned char) seq_len << 1) - 1);
941 *seq = (
unsigned char)(*seq ^ *pos ^ length_factor--);
947 void g_PackID(
void* binary_id,
size_t binary_id_len,
string& packed_id)
949 s_Scramble((
unsigned char*) binary_id, binary_id_len);
951 size_t packed_id_len;
955 packed_id.resize(packed_id_len);
960 const_cast<char*
>(packed_id.data()), packed_id_len,
NULL);
963 #define UNSCRAMBLE_PASS() \
964 counter = seq_len - 1; \
966 *pos = (unsigned char)(*pos ^ pos[-1] ^ ++length_factor); \
968 } while (--counter > 0);
973 unsigned char length_factor = 0;
974 unsigned char* pos = seq + seq_len - 1;
979 pos = seq + seq_len - 1;
981 *seq = (
unsigned char)(*seq ^ *pos ^ ++length_factor);
989 size_t binary_id_len;
993 binary_id.resize(binary_id_len);
996 unsigned char* ptr = (
unsigned char*)
const_cast<char*
>(binary_id.data());
CCompoundIDDumpParser(CCompoundIDPool::TInstance cid_pool, const string &cid_dump)
void SkipSpaceToNextToken()
Uint4 x_ReadIPv4Address()
@ eInvalidType
Field type mismatch.
virtual const char * GetErrCodeString() const override
Get error code interpreted as text.
Compound ID field – an element of the compound ID that has a type and a value.
CCompoundIDField GetNextHomogeneous()
Return the next field of the same type.
CCompoundIDField GetNextNeighbor()
Return the next immediately adjacent field.
void Remove()
Remove this field from the compound ID that contains it.
ECompoundIDFieldType GetType()
Return the type of this field.
CNetRef< SCompoundIDFieldImpl > m_Impl
Pool of recycled CCompoundID objects.
CNetRef< SCompoundIDPoolImpl > m_Impl
CCompoundID NewID(ECompoundIDClass new_id_class)
Create and return a new CCompoundID objects.
CCompoundID FromString(const string &cid)
Unpack the base64-encoded ID and return a CCompoundID object for field extraction.
CCompoundIDPool()
Construct a new pool of CompoundID objects.
CCompoundID FromDump(const string &cid_dump)
Restore the compound ID from its textual representation created by CCompoundID::Dump().
Base64-encoded ID string that contains extractable typed fields.
CCompoundIDField GetFirstField()
Return the first field or NULL if this ID is empty.
CCompoundIDField GetFirst(ECompoundIDFieldType field_type)
Return the first field of the specified type or NULL if this compound ID contains no fields of such t...
string Dump()
Dump the contents of the ID in the human-readable format that can also be parsed by CCompoundIDPool::...
CNetRef< SCompoundIDImpl > m_Impl
string ToString()
Pack the ID and return its string representation.
unsigned GetLength() const
Return the number of fields this ID contains.
bool IsEmpty() const
Return TRUE if this compound ID contains no fields.
ECompoundIDClass GetClass() const
One of the registered ID classes.
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
#define CIT_SEQ_ID_TYPE_NAME
#define CIC_NETSCHEDULEJOBKEY_CLASS_NAME
#define CIT_STRING_TYPE_NAME
#define CIT_NESTED_CID_TYPE_NAME
void g_PackID(void *binary_id, size_t binary_id_len, string &packed_id)
#define CIT_DATABASE_NAME_TYPE_NAME
#define CIT_OBJECTREF_TYPE_NAME
static const char * s_TypeNames[eCIT_NumberOfTypes]
#define CIT_IPV4_SOCK_ADDR_TYPE_NAME
#define CIF_GET_IMPL(ret_type, method, type, member)
#define CIT_TAX_ID_TYPE_NAME
#define CIT_RANDOM_TYPE_NAME
#define CIT_SERVICE_NAME_TYPE_NAME
#define CIT_CUE_TYPE_NAME
#define CIC_NETSTORAGEOBJECTLOC_CLASS_NAME
#define UNSCRAMBLE_PASS()
#define CIT_INTEGER_TYPE_NAME
#define CIT_FLAGS_TYPE_NAME
#define CIC_GENERICID_CLASS_NAME
#define CIT_LABEL_TYPE_NAME
bool g_UnpackID(const string &packed_id, string &binary_id)
#define CID_PARSER_EXCEPTION(message)
static void s_Unscramble(unsigned char *seq, size_t seq_len)
#define CIF_GET_IMPL_(ret_type, method, type, cond, member)
#define CIT_HOST_TYPE_NAME
#define CIC_NETSTORAGEOBJECTLOC_CLASS_NAME_V1
static void s_DumpCompoundID(CNcbiOstrstream &sstr, SCompoundIDImpl *cid_impl, int indent_depth, const char *indent)
static const char * s_ClassNames[eCIC_NumberOfClasses]
#define CID_APPEND_IMPL(method, field_type, val_type, member)
#define CIT_PORT_TYPE_NAME
#define CIT_IPV4_ADDRESS_TYPE_NAME
#define CIT_TIMESTAMP_TYPE_NAME
#define CIC_NETCACHEBLOBKEY_CLASS_NAME
static void s_Indent(CNcbiOstrstream &sstr, int indent_depth, const char *indent)
#define CIT_BOOLEAN_TYPE_NAME
static void s_Scramble(unsigned char *seq, size_t seq_len)
@ eCIC_NetStorageObjectLocV1
Old version of NetStorageObjectLoc.
@ eCIC_NetStorageObjectLoc
Internal declarations of the CompoundID classes.
bool GetSeqID(const CRef< CSeq_align > &seqAlign, CRef< CSeq_id > &SeqID, bool getSlave=true)
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
static DLIST_TYPE *DLIST_NAME() last(DLIST_LIST_TYPE *list)
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
TErrCode GetErrCode(void) const
Get error code.
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
string GetLabel(const CSeq_id &id)
uint32_t Uint4
4-byte (32-bit) unsigned integer
uint16_t Uint2
2-byte (16-bit) unsigned integer
int64_t Int8
8-byte (64-bit) signed integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static string ntoa(unsigned int host)
BSD-like API. NB: when int, "host" must be in network byte order.
static string PrintableString(const CTempString str, TPrintableMode mode=fNewLine_Quote|fNonAscii_Passthru)
Get a printable version of the specified string.
static Int8 StringToInt8(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to Int8.
static string ParseEscapes(const CTempString str, EEscSeqRange mode=eEscSeqRange_Standard, char user_char='?')
Parse C-style escape sequences in the specified string.
static Uint8 StringToUInt8(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to Uint8.
static string UInt8ToString(Uint8 value, TNumToStringFlags flags=0, int base=10)
Convert UInt8 to string.
@ fConvErr_NoThrow
Do not throw an exception on error.
unsigned short GetPort() const
Get the listening port number back.
unsigned short m_Port
TCP port to listen on.
Uint4 GetHost(TEndpointKey key)
@ eBase64_OK
Transcoded successfully.
ECompoundIDFieldType m_Type
struct SCompoundIDFieldImpl::@975::@977 m_IPv4SockAddr
virtual void DeleteThis()
Virtual method "deleting" this object.
void Reset(SCompoundIDPoolImpl *pool, ECompoundIDClass id_class)
virtual void DeleteThis()
Virtual method "deleting" this object.
void Remove(SCompoundIDFieldImpl *field)
void ReturnToPool(Poolable *element)
SCompoundIDObjectPool< SCompoundIDImpl, ECompoundIDClass > m_CompoundIDPool
SCompoundIDObjectPool< SCompoundIDFieldImpl, ECompoundIDFieldType > m_FieldPool
SCompoundIDFieldImpl * m_Head
static SCompoundIDFieldImpl * GetNext(SCompoundIDFieldImpl *entry)
static bool GetInteger(wxSpinCtrl *spinctrl, int *value)