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

Go to the SVN repository for this file.

1 #ifndef OBJTOOLS_FORMAT___ITEM_FORMATTER_HPP
2 #define OBJTOOLS_FORMAT___ITEM_FORMATTER_HPP
3 
4 /* $Id: item_formatter.hpp 95792 2021-12-23 15:43:41Z stakhovv $
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: Aaron Ucko, NCBI
30 * Mati Shomrat
31 *
32 * File Description:
33 *
34 *
35 */
36 #include <corelib/ncbistd.hpp>
37 #include <corelib/ncbiobj.hpp>
38 
41 
42 
45 
46 
47 class IFlatItem;
48 class CLocusItem;
49 class CDeflineItem;
50 class CAccessionItem;
51 class CVersionItem;
52 class CKeywordsItem;
53 class CSegmentItem;
54 class CSourceItem;
55 class CReferenceItem;
56 class CCacheItem;
57 class CCommentItem;
58 class CFeatHeaderItem;
59 class CFeatureItemBase;
60 class CBaseCountItem;
61 class CSequenceItem;
62 class CPrimaryItem;
63 class CFeatHeaderItem;
64 class CContigItem;
65 class CWGSItem;
66 class CTSAItem;
67 class CGenomeItem;
68 class CFlatTextOStream;
69 class CDateItem;
70 class CDBSourceItem;
71 class COriginItem;
72 
73 
75 {
76 public:
77 
78  // virtual constructor
80 
81  virtual ~CFlatItemFormatter(void);
82 
83 
84  // control methods
85  virtual void Start (IFlatTextOStream&);
87  virtual void EndSection (const CEndSectionItem&, IFlatTextOStream&) {}
88  virtual void End (IFlatTextOStream&);
89 
90  // Format methods
91  void Format(const IFlatItem& item, IFlatTextOStream& text_os);
92  virtual void FormatLocus (const CLocusItem&, IFlatTextOStream&) {}
93  virtual void FormatDefline (const CDeflineItem&, IFlatTextOStream&) {}
94  virtual void FormatAccession (const CAccessionItem&, IFlatTextOStream&) {}
95  virtual void FormatVersion (const CVersionItem&, IFlatTextOStream&) {}
96  virtual void FormatSegment (const CSegmentItem&, IFlatTextOStream&) {}
97  virtual void FormatKeywords (const CKeywordsItem&, IFlatTextOStream&) {}
98  virtual void FormatSource (const CSourceItem&, IFlatTextOStream&) {}
99  virtual void FormatReference (const CReferenceItem&, IFlatTextOStream&) {}
100  virtual void FormatCache (const CCacheItem&, IFlatTextOStream&) {}
101  virtual void FormatComment (const CCommentItem&, IFlatTextOStream&) {}
103  virtual void FormatSequence (const CSequenceItem&, IFlatTextOStream&) {}
106  virtual void FormatDate (const CDateItem&, IFlatTextOStream&) {}
107  virtual void FormatDBSource (const CDBSourceItem&, IFlatTextOStream&) {}
108  virtual void FormatPrimary (const CPrimaryItem&, IFlatTextOStream&) {}
109  virtual void FormatContig (const CContigItem&, IFlatTextOStream&) {}
110  virtual void FormatWGS (const CWGSItem&, IFlatTextOStream&) {}
111  virtual void FormatTSA (const CTSAItem&, IFlatTextOStream&) {}
112  virtual void FormatGenome (const CGenomeItem&, IFlatTextOStream&) {}
113  virtual void FormatOrigin (const COriginItem&, IFlatTextOStream&) {}
114  virtual void FormatGap (const CGapItem&, IFlatTextOStream&) {}
115  virtual void FormatAlignment (const CAlignmentItem& , IFlatTextOStream&) {}
116  virtual void FormatGenomeProject(
118 
119  // Context
120  void SetContext(CFlatFileContext& ctx);
121  const CFlatFileContext& GetContext(void) const
122  { return *m_Ctx; }
123 
124 protected:
126 
127  CFlatItemFormatter(void) : m_WrapFlags(NStr::fWrap_FlatFile) {}
128 
129  enum EPadContext {
134  eBarcode
135  };
136 
137  static const string s_GenbankMol[];
138  static const string s_EmblMol[];
139 
140  virtual SIZE_TYPE GetWidth(void) const { return 78; }
141 
142  static string& x_Pad(const string& s, string& out, SIZE_TYPE width,
143  const string& indent = kEmptyStr);
144  virtual string& Pad(const string& s, string& out, EPadContext where) const;
145  virtual list<string>& Wrap(list<string>& l, SIZE_TYPE width,
146  const string& tag, const string& body, EPadContext where = ePara, bool htmlaware = false) const;
147  virtual list<string>& Wrap(list<string>& l, const string& tag,
148  const string& body, EPadContext where = ePara, bool htmlaware = false, int internalIndent = 0 ) const;
149 
150  void x_FormatRefLocation(CNcbiOstrstream& os, const CSeq_loc& loc,
151  const string& to, const string& delim,
152  CBioseqContext& ctx) const;
153  void x_FormatRefJournal(const CReferenceItem& ref, string& journal,
154  CBioseqContext& ctx) const;
155  string x_FormatAccession(const CAccessionItem& acc, char separator) const;
156 
157  void x_GetKeywords(const CKeywordsItem& kws, const string& prefix,
158  list<string>& l) const;
159 
160  const string& GetIndent(void) const { return m_Indent; }
161  void SetIndent(const string& indent) { m_Indent = indent; }
162 
163  const string& GetFeatIndent(void) const { return m_FeatIndent; }
164  void SetFeatIndent(const string& feat_indent) { m_FeatIndent = feat_indent; }
165 
166  const string& GetBarcodeIndent(void) const { return m_BarcodeIndent; }
167  void SetBarcodeIndent(const string& barcode_indent) { m_BarcodeIndent = barcode_indent; }
168 
169  TWrapFlags& SetWrapFlags(void) { return m_WrapFlags; }
170 
171 private:
174 
175  // data
176  string m_Indent;
177  string m_FeatIndent;
181 };
182 
183 
186 
187 #endif /* OBJTOOLS_FORMAT___ITEM_FORMATTER_HPP */
NStr::TWrapFlags TWrapFlags
const CFlatFileContext & GetContext(void) const
virtual void FormatLocus(const CLocusItem &, IFlatTextOStream &)
virtual void FormatDate(const CDateItem &, IFlatTextOStream &)
virtual void FormatGenomeProject(const CGenomeProjectItem &, IFlatTextOStream &)
virtual void FormatAlignment(const CAlignmentItem &, IFlatTextOStream &)
virtual void FormatAccession(const CAccessionItem &, IFlatTextOStream &)
virtual void StartSection(const CStartSectionItem &, IFlatTextOStream &)
const string & GetBarcodeIndent(void) const
virtual SIZE_TYPE GetWidth(void) const
CFlatItemFormatter & operator=(const CFlatItemFormatter &)
virtual void FormatComment(const CCommentItem &, IFlatTextOStream &)
virtual void FormatSequence(const CSequenceItem &, IFlatTextOStream &)
virtual void FormatWGS(const CWGSItem &, IFlatTextOStream &)
virtual void FormatDBSource(const CDBSourceItem &, IFlatTextOStream &)
virtual void FormatSegment(const CSegmentItem &, IFlatTextOStream &)
virtual void FormatGap(const CGapItem &, IFlatTextOStream &)
virtual void FormatContig(const CContigItem &, IFlatTextOStream &)
const string & GetIndent(void) const
void SetFeatIndent(const string &feat_indent)
virtual void EndSection(const CEndSectionItem &, IFlatTextOStream &)
void SetBarcodeIndent(const string &barcode_indent)
CFlatItemFormatter(const CFlatItemFormatter &)
virtual void FormatReference(const CReferenceItem &, IFlatTextOStream &)
virtual void FormatTSA(const CTSAItem &, IFlatTextOStream &)
void SetIndent(const string &indent)
virtual void FormatVersion(const CVersionItem &, IFlatTextOStream &)
virtual void FormatGenome(const CGenomeItem &, IFlatTextOStream &)
virtual void FormatKeywords(const CKeywordsItem &, IFlatTextOStream &)
virtual void FormatSource(const CSourceItem &, IFlatTextOStream &)
const string & GetFeatIndent(void) const
virtual void FormatPrimary(const CPrimaryItem &, IFlatTextOStream &)
CRef< CFlatFileContext > m_Ctx
virtual void FormatCache(const CCacheItem &, IFlatTextOStream &)
virtual void FormatFeatHeader(const CFeatHeaderItem &, IFlatTextOStream &)
virtual void FormatDefline(const CDeflineItem &, IFlatTextOStream &)
virtual void FormatOrigin(const COriginItem &, IFlatTextOStream &)
virtual void FormatBasecount(const CBaseCountItem &, IFlatTextOStream &)
TWrapFlags & SetWrapFlags(void)
virtual void FormatFeature(const CFeatureItemBase &, IFlatTextOStream &)
virtual void Format(const IFlatItem &item, IFlatTextOStream &text_os)=0
virtual void Start(IFlatTextOStream &text_os)=0
virtual void End(IFlatTextOStream &text_os)=0
NStr –.
Definition: ncbistr.hpp:243
Include a standard set of the NCBI C++ Toolkit most basic headers.
std::ofstream out("events_result.xml")
main entry point for tests
CS_CONTEXT * ctx
Definition: t0006.c:12
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
#define kEmptyStr
Definition: ncbistr.hpp:123
int TWrapFlags
Bitwise OR of "EWrapFlags".
Definition: ncbistr.hpp:3232
#define NCBI_FORMAT_EXPORT
Definition: ncbi_export.h:496
const char * tag
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
static Format format
Definition: njn_ioutil.cpp:53
static const char * prefix[]
Definition: pcregrep.c:405
CRef< CPub > journal(ParserPtr pp, char *bptr, char *eptr, CRef< CAuth_list > &auth_list, CRef< CTitle::C_E > &title, bool has_muid, CRef< CCit_art > &cit_art, Int4 er)
Definition: ref.cpp:1452
string indent(" ")
Modified on Sat Apr 13 11:50:05 2024 by modify_doxy.py rev. 669887