1 /* $Id: User_object.hpp 574980 2018-11-21 14:24:48Z ucko $
2  * ===========================================================================
3  *
4  *                            PUBLIC DOMAIN NOTICE
5  *               National Center for Biotechnology Information
6  *
7  *  This software/database is a "United States Government Work" under the
8  *  terms of the United States Copyright Act.  It was written as part of
9  *  the author's official duties as a United States Government employee and
10  *  thus cannot be copyrighted.  This software/database is freely available
11  *  to the public for use. The National Library of Medicine and the U.S.
12  *  Government have not placed any restriction on its use or reproduction.
13  *
14  *  Although all reasonable efforts have been taken to ensure the accuracy
15  *  and reliability of the software and data, the NLM and the U.S.
16  *  Government do not and cannot warrant the performance or results that
17  *  may be obtained by using this software or data. The NLM and the U.S.
18  *  Government disclaim all warranties, express or implied, including
19  *  warranties of performance, merchantability or fitness for any particular
20  *  purpose.
21  *
22  *  Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author:  .......
27  *
28  * File Description:
29  *   .......
30  *
31  * Remark:
32  *   This code was originally generated by application DATATOOL
33  *   using specifications from the ASN data definition file
34  *   'general.asn'.
35  */
36 
37 #ifndef OBJECTS_GENERAL_USER_OBJECT_HPP
38 #define OBJECTS_GENERAL_USER_OBJECT_HPP
39 
40 
41 // generated includes
42 #include <objects/general/User_object_.hpp>
43 
44 // generated classes
45 
46 BEGIN_NCBI_SCOPE
47 
48 BEGIN_objects_SCOPE // namespace ncbi::objects::
49 
50 class NCBI_GENERAL_EXPORT CUser_object : public CUser_object_Base
51 {
52     typedef CUser_object_Base Tparent;
53 public:
54     /// constructor
55     CUser_object(void);
56     /// destructor
57     ~CUser_object(void);
58 
59     /// how to interpret the value in the AddField() conversion functions below.
60     enum EParseField {
61         eParse_String,    ///< Add string even if all numbers
62         eParse_Number     ///< Parse a real or integer number, otherwise string
63     };
64 
65     /// add a data field to the user object that holds a given value
66     CUser_object& AddField(const string& label, const string& value,
67                            EParseField parse = eParse_String);
68     CUser_object& AddField(const string& label, const char* value,
69                            EParseField parse = eParse_String);
70     CUser_object& AddField(const string& label, int           value);
71     CUser_object& AddField(const string& label, Int8          value);
72     CUser_object& AddField(const string& label, double        value);
73     CUser_object& AddField(const string& label, bool          value);
74 #ifdef NCBI_STRICT_GI
75     CUser_object& AddField(const string& label, TGi           value);
76 #endif
77 
78     CUser_object& AddField(const string& label, const vector<string>& value);
79     CUser_object& AddField(const string& label, const vector<int>&    value);
80     CUser_object& AddField(const string& label, const vector<double>& value);
81 
82     CUser_object& AddField(const string& label, CUser_object& value);
83     CUser_object& AddField(const string& label,
84                            const vector< CRef<CUser_object> >& value);
85     CUser_object& AddField(const string& label,
86                            const vector< CRef<CUser_field> >& value);
87 
88     /// Access a named field in this user object.  This is a little
89     /// sneaky in that it interprets a delimiter for recursion.
90     /// This version will throw an exception if the field
91     /// doesn't exist.
92     const CUser_field&     GetField(const string& str,
93                                     const string& delim = ".",
94                                     NStr::ECase use_case = NStr::eCase) const;
95     CConstRef<CUser_field> GetFieldRef(const string& str,
96                                        const string& delim = ".",
97                                        NStr::ECase use_case = NStr::eCase) const;
98 
99     /// Access a named field in this user object.  This is a little
100     /// sneaky in that it interprets a delimiter for recursion.  The
101     /// 'obj_subtype' parameter is used to set the subtype of a
102     /// sub-object if a new sub-object needs to be created
103     CUser_field&      SetField(const string& str,
104                                const string& delim = ".",
105                                const string& obj_subtype = kEmptyStr,
106                                NStr::ECase use_case = NStr::eCase);
107     CRef<CUser_field> SetFieldRef(const string& str,
108                                   const string& delim = ".",
109                                   const string& obj_subtype = kEmptyStr,
110                                   NStr::ECase use_case = NStr::eCase);
111 
112     /// Verify that a named field exists
113     bool HasField(const string& str,
114                   const string& delim = ".",
115                   NStr::ECase use_case = NStr::eCase) const;
116 
117     /// enum controlling what to return for a label
118     /// this mirrors a request inside of feature::GetLabel()
119     enum ELabelContent {
120         eType,
121         eContent,
122         eBoth
123     };
124 
125     /// Append a label to label.  The type defaults to content for
126     /// backward compatibility
127     void GetLabel(string* label, ELabelContent mode = eContent) const;
128 
129     ///
130     /// enums for implicit typing of user objects
131     ///
132 
133     /// general category
134     enum ECategory {
135         eCategory_Unknown = -1,
136         eCategory_Experiment
137     };
138 
139     /// sub-category experiment
140     enum EExperiment {
141         eExperiment_Unknown = -1,
142         eExperiment_Sage
143     };
144 
145     /// accessors: classify a given user object
146     ECategory GetCategory(void) const;
147 
148     /// sub-category accessors:
149     EExperiment GetExperimentType(void) const;
150     const CUser_object& GetExperiment(void) const;
151 
152     /// format a user object as a given type.  This returns a user-object
153     /// that is suitable for containing whatever specifics might be needed
154     CUser_object& SetCategory(ECategory category);
155 
156     /// format a user object as a given type.  This returns a user-object
157     /// that is suitable for containing whatever specifics might be needed
158     CUser_object& SetExperiment(EExperiment category);
159 
160     /// Object Type
161     enum EObjectType {
162         eObjectType_Unknown = -1,
163         eObjectType_DBLink,
164         eObjectType_StructuredComment,
165         eObjectType_OriginalId,
166         eObjectType_Unverified,
167         eObjectType_ValidationSuppression,
168         eObjectType_Cleanup,
169         eObjectType_AutodefOptions,
170         eObjectType_FileTrack,
171         eObjectType_RefGeneTracking
172     };
173 
174     EObjectType GetObjectType() const;
175     void SetObjectType(EObjectType obj_type);
IsDBLink() const176     bool IsDBLink() const { return GetObjectType() == eObjectType_DBLink; }
IsStructuredComment() const177     bool IsStructuredComment() const { return GetObjectType() == eObjectType_StructuredComment; }
IsOriginalId() const178     bool IsOriginalId() const { return GetObjectType() == eObjectType_OriginalId; }
IsUnverified() const179     bool IsUnverified() const { return GetObjectType() == eObjectType_Unverified; }
IsValidationSuppression() const180     bool IsValidationSuppression() const { return GetObjectType() == eObjectType_ValidationSuppression; }
IsCleanup() const181     bool IsCleanup() const { return GetObjectType() == eObjectType_Cleanup; }
IsAutodefOptions() const182     bool IsAutodefOptions() const { return GetObjectType() == eObjectType_AutodefOptions; }
IsFileTrack() const183     bool IsFileTrack() const { return GetObjectType() == eObjectType_FileTrack; }
IsRefGeneTracking() const184     bool IsRefGeneTracking() const { return GetObjectType() == eObjectType_RefGeneTracking; }
185 
186     // for Unverified User-objects: Can have Organism and/or Feature and/or Misassembled
187     bool IsUnverifiedOrganism() const;
188     void AddUnverifiedOrganism();
189     void RemoveUnverifiedOrganism();
190     bool IsUnverifiedFeature() const;
191     void AddUnverifiedFeature();
192     void RemoveUnverifiedFeature();
193     bool IsUnverifiedMisassembled() const;
194     void AddUnverifiedMisassembled();
195     void RemoveUnverifiedMisassembled();
196     bool IsUnverifiedContaminant() const;
197     void AddUnverifiedContaminant();
198     void RemoveUnverifiedContaminant();
199 
200     void UpdateNcbiCleanup(int version);
201 
202     // returns true if one or more matching fields were removed
203     bool RemoveNamedField(const string& field_name, NStr::ECase ecase = NStr::eCase);
204 
205     // Set FileTrack URL
206     void SetFileTrackURL(const string& url);
207     void SetFileTrackUploadId(const string& upload_id);
208 
209     // For RefGeneTracking
210     // See https://confluence.ncbi.nlm.nih.gov/display/REF/RefGeneTracking+user+object?focusedCommentId=94310717#comment-94310717 for spec
211     // JIRA:MSS-677
212     enum ERefGeneTrackingStatus {
213         eRefGeneTrackingStatus_Error = -1,
214         eRefGeneTrackingStatus_NotSet,
215         eRefGeneTrackingStatus_PREDICTED,
216         eRefGeneTrackingStatus_PROVISIONAL,
217         eRefGeneTrackingStatus_INFERRED,
218         eRefGeneTrackingStatus_VALIDATED,
219         eRefGeneTrackingStatus_REVIEWED,
220         eRefGeneTrackingStatus_PIPELINE,
221         eRefGeneTrackingStatus_WGS
222     };
223     void SetRefGeneTrackingStatus(ERefGeneTrackingStatus status);
224     ERefGeneTrackingStatus GetRefGeneTrackingStatus() const;
225     void ResetRefGeneTrackingStatus();
IsSetRefGeneTrackingStatus() const226     bool IsSetRefGeneTrackingStatus() const
227     {
228         ERefGeneTrackingStatus val = GetRefGeneTrackingStatus();
229         return (val != eRefGeneTrackingStatus_NotSet && val != eRefGeneTrackingStatus_Error);
230     }
231 
232     void SetRefGeneTrackingGenomicSource(const string& genomic_source);
233     const string& GetRefGeneTrackingGenomicSource() const;
234     void ResetRefGeneTrackingGenomicSource();
IsSetRefGeneTrackingGenomicSource() const235     bool IsSetRefGeneTrackingGenomicSource() const { return !GetRefGeneTrackingGenomicSource().empty(); }
236 
237     void SetRefGeneTrackingGenerated(bool val = true);
238     bool GetRefGeneTrackingGenerated() const;
239     void ResetRefGeneTrackingGenerated();
240 
241     // Collaborator field in RefGeneTracking User-object
242     void SetRefGeneTrackingCollaborator(const string& collaborator);
243     const string& GetRefGeneTrackingCollaborator() const;
244     void ResetRefGeneTrackingCollaborator();
IsSetRefGeneTrackingCollaborator() const245     bool IsSetRefGeneTrackingCollaborator() const { return !GetRefGeneTrackingCollaborator().empty(); }
246 
247 
248     // CollaboratorURL field in RefGeneTracking User-object
249     void SetRefGeneTrackingCollaboratorURL(const string& collaborator_url);
250     const string& GetRefGeneTrackingCollaboratorURL() const;
251     void ResetRefGeneTrackingCollaboratorURL();
IsSetRefGeneTrackingCollaboratorURL() const252     bool IsSetRefGeneTrackingCollaboratorURL() const { return !GetRefGeneTrackingCollaboratorURL().empty(); }
253 
254     class CRefGeneTrackingException : public CException
255     {
256     public:
257         enum EErrCode {
258             eUserFieldWithoutLabel,
259             eBadUserFieldName,
260             eBadUserFieldData,
261             eBadStatus
262         };
263 
GetErrCodeString() const264         virtual const char* GetErrCodeString() const override
265         {
266             switch (GetErrCode()) {
267             case eUserFieldWithoutLabel: return "User field without label";
268             case eBadUserFieldData: return "Unexpected data type";
269             default:     return CException::GetErrCodeString();
270             }
271         }
272 
273         NCBI_EXCEPTION_DEFAULT(CRefGeneTrackingException, CException);
274     };
275 
276     class CRefGeneTrackingAccession : public CObject {
277     public:
CRefGeneTrackingAccession()278         CRefGeneTrackingAccession() {}
CRefGeneTrackingAccession(const string & accession,TGi gi=ZERO_GI,TSeqPos from=kInvalidSeqPos,TSeqPos to=kInvalidSeqPos,const string & comment=kEmptyStr,const string & acc_name=kEmptyStr)279         CRefGeneTrackingAccession(const string& accession,
280                                   TGi gi = ZERO_GI,
281                                   TSeqPos from = kInvalidSeqPos,
282                                   TSeqPos to = kInvalidSeqPos,
283                                   const string& comment = kEmptyStr,
284                                   const string& acc_name = kEmptyStr) :
285             m_Accession(accession),
286             m_GI(gi),
287             m_From(from),
288             m_To(to),
289             m_Comment(comment),
290             m_Name(acc_name) {}
291 
~CRefGeneTrackingAccession()292         ~CRefGeneTrackingAccession() {}
293 
GetAccession() const294         const string& GetAccession() const { return m_Accession; }
IsSetAccession() const295         bool IsSetAccession() const { return !m_Accession.empty(); }
GetComment() const296         const string& GetComment() const { return m_Comment; }
IsSetComment() const297         bool IsSetComment() const { return !m_Comment.empty(); }
GetName() const298         const string& GetName() const { return m_Name; }
IsSetName() const299         bool IsSetName() const { return !m_Name.empty(); }
GetGI() const300         TGi GetGI() const { return m_GI; }
IsSetGI() const301         bool IsSetGI() const { return m_GI > ZERO_GI; }
GetFrom() const302         TSeqPos GetFrom() const { return m_From; }
IsSetFrom() const303         bool IsSetFrom() const { return m_From != kInvalidSeqPos; }
GetTo() const304         TSeqPos GetTo() const { return m_To; }
IsSetTo() const305         bool IsSetTo() const { return m_To != kInvalidSeqPos; }
306 
IsEmpty() const307         bool IsEmpty() const { return !(IsSetAccession() || IsSetComment() ||
308                                        IsSetName() || IsSetGI() ||
309                                        IsSetFrom() || IsSetTo()); }
310 
311         CRef<CUser_field> MakeAccessionField() const;
312         static CRef<CRefGeneTrackingAccession> MakeAccessionFromUserField(const CUser_field& field);
313 
314     private:
315         string m_Accession;
316         TGi m_GI;
317         TSeqPos m_From;
318         TSeqPos m_To;
319         string m_Comment;
320         string m_Name;
321 
322         /// Prohibit copy constructor and assignment operator
323         CRefGeneTrackingAccession(const CRefGeneTrackingAccession& cpy) = delete;
324         CRefGeneTrackingAccession& operator=(const CRefGeneTrackingAccession& value) = delete;
325     };
326 
327     typedef vector<CConstRef<CRefGeneTrackingAccession> > TRefGeneTrackingAccessions;
328 
329     // "IdenticalTo" field in RefGeneTracking User-object: can have only one accession
330     void SetRefGeneTrackingIdenticalTo(const CRefGeneTrackingAccession& accession);
331     CConstRef<CRefGeneTrackingAccession> GetRefGeneTrackingIdenticalTo() const;
332     void ResetRefGeneTrackingIdenticalTo();
IsSetRefGeneTrackingIdenticalTo() const333     bool IsSetRefGeneTrackingIdenticalTo() const { return GetRefGeneTrackingIdenticalTo() != CConstRef<CRefGeneTrackingAccession>(NULL); }
334 
335     // "Assembly" field in RefGeneTracking User-object: can have one or more accessions
336     void SetRefGeneTrackingAssembly(const TRefGeneTrackingAccessions& acc_list);
337     TRefGeneTrackingAccessions GetRefGeneTrackingAssembly() const;
338     void ResetRefGeneTrackingAssembly();
IsSetRefGeneTrackingAssembly() const339     bool IsSetRefGeneTrackingAssembly() const { return GetRefGeneTrackingAssembly().size() > 0; }
340 
341 private:
342     /// Prohibit copy constructor and assignment operator
343     CUser_object(const CUser_object& value);
344     CUser_object& operator=(const CUser_object& value);
345 
346     bool x_IsUnverifiedType(const string& val) const;
347     bool x_IsUnverifiedType(const string& val, const CUser_field& field) const;
348     void x_AddUnverifiedType(const string& val);
349     void x_RemoveUnverifiedType(const string& val);
350 
351     // for RefGeneTracking
352     void x_SetRefGeneTrackingField(const string& field_name, const string& value);
353     const string& x_GetRefGeneTrackingField(const string& field_name) const;
354 };
355 
356 
357 
358 /////////////////// CUser_object inline methods
359 
360 // constructor
361 inline
CUser_object(void)362 CUser_object::CUser_object(void)
363 {
364 }
365 
366 
367 /////////////////// end of CUser_object inline methods
368 
369 
370 END_objects_SCOPE // namespace ncbi::objects::
371 
372 END_NCBI_SCOPE
373 
374 #endif // OBJECTS_GENERAL_USER_OBJECT_HPP
375