NCBI C++ ToolKit
asn_sample.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: asn_sample.cpp 90001 2020-05-04 12:53:02Z ivanov $
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: Denis Vakatov
27 *
28 * File Description:
29 * A part of the project demonstrating how to generate source code from
30 * an ASN.1 specification (see "sample_asn.asn") and then use that code
31 * to read, convert and write data matching that specification.
32 *
33 * ===========================================================================
34 */
35 
36 #include <ncbi_pch.hpp>
37 #include <corelib/ncbiapp.hpp>
39 
42 
43 
45 {
46  virtual void Init(void);
47  virtual int Run(void);
48 };
49 
50 
52 {
53  // Create command-line argument descriptions class
54  unique_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
55 
56  // Specify USAGE context
57  arg_desc->SetUsageContext
58  (GetArguments().GetProgramBasename(),
59  "Object serialization demo program");
60 
61  // Describe the expected command-line arguments
62  arg_desc->AddDefaultKey
63  ("input", "InputFile",
64  "name of file to read ASN.1 data from (standard input by default)",
66 
67  arg_desc->AddDefaultKey
68  ("output", "OutputFile",
69  "name of file to write XML data to (standard output by default)",
71 
72  // Setup arg.descriptions for this application
73  SetupArgDescriptions(arg_desc.release());
74 }
75 
76 
78 {
80 
81  // Read as text ASN.1
82  GetArgs()["input"].AsInputFile() >> MSerial_AsnText >> obj;
83 
84  // Write as XML
85  GetArgs()["output"].AsOutputFile() << MSerial_Xml << obj;
86 
87  return 0;
88 }
89 
90 
91 
92 /////////////////////////////////////////////////////////////////////////////
93 // MAIN
94 
95 int NcbiSys_main(int argc, ncbi::TXChar* argv[])
96 {
97  return CSampleAsnApplication().AppMain(argc, argv);
98 }
User-defined methods of the data storage class.
int NcbiSys_main(int argc, ncbi::TXChar *argv[])
Definition: asn_sample.cpp:95
USING_SCOPE(ncbi)
CArgDescriptions –.
Definition: ncbiargs.hpp:541
CNCBI_Sample_ASN_Type –.
virtual int Run(void)
Run the application.
Definition: asn_sample.cpp:77
virtual void Init(void)
Initialize the application.
Definition: asn_sample.cpp:51
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
Definition: ncbiapp.cpp:305
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
Definition: ncbiapp.cpp:819
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
Definition: ncbiapp.cpp:1195
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
@ fPreOpen
Open file right away; for eInputFile, eOutputFile, eIOFile.
Definition: ncbiargs.hpp:618
@ eInputFile
Name of file (must exist and be readable)
Definition: ncbiargs.hpp:595
@ eOutputFile
Name of file (must be writable)
Definition: ncbiargs.hpp:596
#define MSerial_Xml
Definition: serialbase.hpp:698
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
char TXChar
Definition: ncbistr.hpp:172
Magic spell ;-) needed for some weird compilers... very empiric.
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Modified on Sun May 05 05:20:23 2024 by modify_doxy.py rev. 669887