NCBI C++ ToolKit
bdb_filedump.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef BDB_FILEDUMP__HPP
2 #define BDB_FILEDUMP__HPP
3 
4 /* $Id: bdb_filedump.hpp 42205 2009-06-15 15:40:12Z ivanovp $
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  * Author: Anatoliy Kuznetsov
30  *
31  * File Description: Dumper for BDB files into text format.
32  *
33  */
34 
35 /// @file bdb_filedump.hpp
36 /// BDB File covertion into text.
37 
38 
40 
41 class CBDB_Query;
42 
43 /** @addtogroup BDB_Files
44  *
45  * @{
46  */
47 
48 class CBDB_File;
49 
50 /// Utility class to convert DBD files into text files.
51 ///
52 
54 {
55 public:
56  /// Constructor.
57  /// @param col_separator
58  /// Column separator
59  CBDB_FileDumper(const string& col_separator = "\t");
60  CBDB_FileDumper(const CBDB_FileDumper& fdump);
61  ~CBDB_FileDumper();
62 
63  CBDB_FileDumper& operator=(const CBDB_FileDumper& fdump);
64 
65 
66  void SetColumnSeparator(const string& col_separator);
67 
69  {
71  eDropNames
72  };
73 
74  /// Control field names printing
75  void SetColumnNames(EPrintFieldNames print_names);
76 
77  /// Field value formatting controls
78  /// @sa SetValueFormatting
79  ///
81  {
84  eQuoteAll
85  };
86 
87  void SetValueFormatting(EValueFormatting vf);
88 
89  /// BLOB value formatting controls
90  /// @sa SetBlobFormatting
91  ///
93  {
94  eBlobSummary = (1 << 0),
95  eBlobAll = (1 << 1),
96  eBlobAsHex = (1 << 2),
97  eBlobAsTxt = (1 << 3)
98  };
99 
100  typedef unsigned int TBlobFormat;
101 
102  void SetBlobFormat(TBlobFormat bf);
103  TBlobFormat GetBlobFormat() const { return m_BlobFormat; }
104 
105  /// Convert BDB file into text file
106  void Dump(const string& dump_file_name, CBDB_File& db);
107 
108  /// Convert BDB file into text and write it into the specified stream
109  void Dump(CNcbiOstream& out, CBDB_File& db);
110 
111  /// Dump BDB cursor to stream
112  void Dump(CNcbiOstream& out, CBDB_FileCursor& cur);
113 
114  /// Return number of records processed by Dump
115  unsigned GetRecordsDumped() const { return m_RecordsDumped; }
116 
117  /// Set query filter
118  void SetQuery(const string& query_str);
119 
120  /// Set BLOB dump file name
121  void SetBlobDumpFile(const string& fname) { m_BlobDumpFname = fname; }
122 
123  /// Set reference on output file
124  /// (mode when all dumped records are put into a separate database)
125  /// Class does not take ownership on out_dbf
126  void SetOutFile(CBDB_File* out_dbf) { m_OutFile = out_dbf; }
127 protected:
128 
129  void PrintHeader(CNcbiOstream& out,
130  const CBDB_BufferManager* key,
131  const CBDB_BufferManager* data);
132 
133 private:
134  void x_SetQuoteFlags(vector<unsigned>* flags,
135  const CBDB_BufferManager& bman);
136 
137  void x_DumpFields(CNcbiOstream& out,
138  const CBDB_BufferManager& bman,
139  const vector<unsigned>& quote_flags,
140  bool is_key);
141 
142 protected:
148  unsigned int m_RecordsDumped;
149 
150  string m_QueryStr;
152 
154 };
155 
156 /* @} */
157 
158 
159 inline
160 void CBDB_FileDumper::SetColumnSeparator(const string& col_separator)
161 {
162  m_ColumnSeparator = col_separator;
163 }
164 
165 inline
167 {
168  m_PrintNames = print_names;
169 }
170 
171 inline
173 {
174  m_ValueFormatting = vf;
175 }
176 
177 inline
179 {
180  m_BlobFormat = bf;
181 }
182 
184 
185 #endif
BDB Data Field Buffer manager class.
Definition: bdb_types.hpp:1768
Berkeley DB file cursor class.
Definition: bdb_cursor.hpp:95
Utility class to convert DBD files into text files.
Berkeley DB file class.
Definition: bdb_file.hpp:445
Query class incapsulates query tree (query clause) and implements set of utility methods to construct...
Definition: bdb_query.hpp:139
static uch flags
std::ofstream out("events_result.xml")
main entry point for tests
char data[12]
Definition: iconv.c:80
void SetValueFormatting(EValueFormatting vf)
EValueFormatting
Field value formatting controls.
CBDB_Query * m_Query
TBlobFormat m_BlobFormat
EValueFormatting m_ValueFormatting
unsigned GetRecordsDumped() const
Return number of records processed by Dump.
EPrintFieldNames m_PrintNames
void SetColumnNames(EPrintFieldNames print_names)
Control field names printing.
void SetColumnSeparator(const string &col_separator)
TBlobFormat GetBlobFormat() const
EBlobFormatting
BLOB value formatting controls.
void SetBlobDumpFile(const string &fname)
Set BLOB dump file name.
CBDB_File * m_OutFile
unsigned int TBlobFormat
string m_ColumnSeparator
unsigned int m_RecordsDumped
void SetBlobFormat(TBlobFormat bf)
void SetOutFile(CBDB_File *out_dbf)
Set reference on output file (mode when all dumped records are put into a separate database) Class do...
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define NCBI_BDB_EXPORT
Definition: ncbi_export.h:272
const struct ncbi::grid::netcache::search::fields::KEY key
void Dump(CSplitCacheApp *app, const C &obj, ESerialDataFormat format, const string &key, const string &suffix=kEmptyStr)
Modified on Tue May 28 05:53:04 2024 by modify_doxy.py rev. 669887