1 #ifndef JSONTOOL__HPP
2 #define JSONTOOL__HPP
3 
4 /*  $Id: cidtool.hpp 457251 2015-01-21 17:47:30Z kazimird $
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:  Dmitry Kazimirov
30  *
31  */
32 
33 /// @file cidtool.hpp
34 /// Declarations of command line interface arguments and handlers.
35 ///
36 
37 #include <corelib/ncbiapp.hpp>
38 
39 #include <connect/services/compound_id.hpp>
40 
41 #define GRID_APP_NAME "cidtool"
42 
43 #define INPUT_FILE_OPTION "input-file"
44 #define OUTPUT_FILE_OPTION "output-file"
45 
46 BEGIN_NCBI_SCOPE
47 
48 enum EOption {
49     eCID,
50     eInputFile,
51     eOutputFile,
52     eNumberOfOptions
53 };
54 
55 #define OPTION_ACCEPTED 1
56 #define OPTION_SET 2
57 #define OPTION_EXPLICITLY_SET 4
58 #define OPTION_N(number) (1 << number)
59 
60 class CComponentIDToolApp : public CNcbiApplication
61 {
62 public:
63     CComponentIDToolApp(int argc, const char* argv[]);
64 
65     virtual int Run();
66 
67     virtual ~CComponentIDToolApp();
68 
69 private:
70     int m_ArgC;
71     const char** m_ArgV;
72 
73     struct SOptions {
74         string cid;
75         FILE* input_stream;
76         FILE* output_stream;
77 
78         char option_flags[eNumberOfOptions];
79 
SOptionsCComponentIDToolApp::SOptions80         SOptions() : input_stream(NULL), output_stream(NULL)
81         {
82             memset(option_flags, 0, sizeof(option_flags));
83         }
84     } m_Opts;
85 
86 private:
MarkOptionAsAccepted(int option)87     void MarkOptionAsAccepted(int option)
88     {
89         m_Opts.option_flags[option] |= OPTION_ACCEPTED;
90     }
91 
IsOptionAccepted(EOption option) const92     bool IsOptionAccepted(EOption option) const
93     {
94         return (m_Opts.option_flags[option] & OPTION_ACCEPTED) != 0;
95     }
96 
IsOptionAccepted(EOption option,int mask) const97     int IsOptionAccepted(EOption option, int mask) const
98     {
99         return (m_Opts.option_flags[option] & OPTION_ACCEPTED) ? mask : 0;
100     }
101 
IsOptionAcceptedButNotSet(EOption option) const102     bool IsOptionAcceptedButNotSet(EOption option) const
103     {
104         return m_Opts.option_flags[option] == OPTION_ACCEPTED;
105     }
106 
IsOptionAcceptedAndSetImplicitly(EOption option) const107     bool IsOptionAcceptedAndSetImplicitly(EOption option) const
108     {
109         return m_Opts.option_flags[option] == (OPTION_ACCEPTED | OPTION_SET);
110     }
111 
MarkOptionAsSet(int option)112     void MarkOptionAsSet(int option)
113     {
114         m_Opts.option_flags[option] |= OPTION_SET;
115     }
116 
IsOptionSet(int option) const117     bool IsOptionSet(int option) const
118     {
119         return (m_Opts.option_flags[option] & OPTION_SET) != 0;
120     }
121 
IsOptionSet(int option,int mask) const122     int IsOptionSet(int option, int mask) const
123     {
124         return (m_Opts.option_flags[option] & OPTION_SET) ? mask : 0;
125     }
126 
MarkOptionAsExplicitlySet(int option)127     void MarkOptionAsExplicitlySet(int option)
128     {
129         m_Opts.option_flags[option] |= OPTION_SET | OPTION_EXPLICITLY_SET;
130     }
131 
IsOptionExplicitlySet(int option) const132     bool IsOptionExplicitlySet(int option) const
133     {
134         return (m_Opts.option_flags[option] & OPTION_EXPLICITLY_SET) != 0;
135     }
136 
IsOptionExplicitlySet(int option,int mask) const137     int IsOptionExplicitlySet(int option, int mask) const
138     {
139         return (m_Opts.option_flags[option] & OPTION_EXPLICITLY_SET) ? mask : 0;
140     }
141 
142 public:
143     int Cmd_Dump();
144     int Cmd_Make();
145 
146 private:
147     CCompoundIDPool m_CompoundIDPool;
148 };
149 
150 END_NCBI_SCOPE
151 
152 #endif // JSONTOOL__HPP
153