1 #ifndef CASS_BLOB_ID__HPP
2 #define CASS_BLOB_ID__HPP
3 
4 /*  $Id: cass_blob_id.hpp 612246 2020-07-17 14:23:22Z satskyse $
5  * ===========================================================================
6  *
7  *                            PUBLIC DOMAIN NOTICE
8  *               National Center for Biotechnology Information
9  *
10  *  This software/database is a "United States Government Work" under the
11  *  terms of the United States Copyright Act.  It was written as part of
12  *  the author's official duties as a United States Government employee and
13  *  thus cannot be copyrighted.  This software/database is freely available
14  *  to the public for use. The National Library of Medicine and the U.S.
15  *  Government have not placed any restriction on its use or reproduction.
16  *
17  *  Although all reasonable efforts have been taken to ensure the accuracy
18  *  and reliability of the software and data, the NLM and the U.S.
19  *  Government do not and cannot warrant the performance or results that
20  *  may be obtained by using this software or data. The NLM and the U.S.
21  *  Government disclaim all warranties, express or implied, including
22  *  warranties of performance, merchantability or fitness for any particular
23  *  purpose.
24  *
25  *  Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Sergey Satskiy
30  *
31  * File Description: Cassandra processors blob id
32  *
33  */
34 
35 #include <objtools/pubseq_gateway/impl/cassandra/bioseq_info/record.hpp>
36 #include <string>
37 
38 USING_IDBLOB_SCOPE;
39 
40 
41 // Cassandra blob identifier consists of two integers: sat and sat key.
42 // The blob sat eventually needs to be resolved to a sat name.
43 struct SCass_BlobId
44 {
45     CBioseqInfoRecord::TSat     m_Sat;
46     CBioseqInfoRecord::TSatKey  m_SatKey;
47 
48     // Resolved sat
49     // The resolved sat appears later in the process
50     string                      m_Keyspace;
51 
SCass_BlobIdSCass_BlobId52     SCass_BlobId() :
53         m_Sat(-1), m_SatKey(-1)
54     {}
55 
SCass_BlobIdSCass_BlobId56     SCass_BlobId(int  sat, int  sat_key) :
57         m_Sat(sat), m_SatKey(sat_key)
58     {}
59 
60     SCass_BlobId(const string &  blob_id);
61 
62     SCass_BlobId(const SCass_BlobId &) = default;
63     SCass_BlobId(SCass_BlobId &&) = default;
64     SCass_BlobId &  operator=(const SCass_BlobId &) = default;
65     SCass_BlobId &  operator=(SCass_BlobId &&) = default;
66 
67     bool MapSatToKeyspace(void);
68 
ToStringSCass_BlobId69     string ToString(void) const
70     {
71         return to_string(m_Sat) + '.' + to_string(m_SatKey);
72     }
73 
IsValidSCass_BlobId74     bool IsValid(void) const
75     {
76         return m_Sat >= 0 && m_SatKey >= 0;
77     }
78 
operator <SCass_BlobId79     bool operator < (const SCass_BlobId &  other) const
80     {
81         if (m_Sat == other.m_Sat)
82             return m_SatKey < other.m_SatKey;
83         return m_Sat < other.m_Sat;
84     }
85 
operator ==SCass_BlobId86     bool operator == (const SCass_BlobId &  other) const
87     {
88         return m_Sat == other.m_Sat && m_SatKey == other.m_SatKey;
89     }
90 
operator !=SCass_BlobId91     bool operator != (const SCass_BlobId &  other) const
92     {
93         return !this->operator==(other);
94     }
95 };
96 
97 
98 #endif  // CASS_BLOB_ID__HPP
99 
100