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

Go to the SVN repository for this file.

1 /* $Id: table_data_suc.cpp 39051 2017-07-21 19:55:56Z katargir $
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  * Authors: Colleen Bollin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 
38 
39 // maximal amount of SUC we should realistically see in a SUC table
40 const size_t CTableDataSUC::c_MaxRows(100000);
41 
42 // widths (in chars) of eBlock and eLine columns
43 // if wider, they will be wrapped
44 const size_t CTableDataSUC::c_BlockWidth(20);
45 const size_t CTableDataSUC::c_LineWidth(100);
46 
48  : m_Scope(scope), m_SUCResults(results)
49 {
50 }
51 
53 {
54 }
55 
56 // number of entries and order must correspond with CTableDataSUC::EColContents
57 static const string s_ColNames[] = {
58  "Block",
59  "Count",
60  "Line"
61 };
62 
63 
65 {
66  if (m_SUCResults->CountLines() == 0)
67  return ITableData::kString;
68 
69  switch(col){
70  case eCount:
71  return ITableData::kInt;
72 
73  default:
74  return ITableData::kString;
75  }
76  return ITableData::kNone;
77 }
78 
79 
80 bool CTableDataSUC::IsHtmlColumn(size_t col) const
81 {
82  return false;
83 }
84 
85 string CTableDataSUC::GetColumnLabel(size_t col) const
86 {
87  if (m_SUCResults->CountLines() == 0 && col == 0) {
88  return "Status";
89  }
90 
91  if (col < CTableDataSUC::eMaxColNum) {
92  return s_ColNames[col];
93  }
94 
95  return kEmptyStr;
96 }
97 
98 
100 {
101  return max(m_SUCResults->CountLines(), (size_t)1);
102 
103 }
104 
105 
107 {
108  return (size_t)CTableDataSUC::eMaxColNum;
109 }
110 
111 
112 void CTableDataSUC::GetStringValue(size_t row, size_t col, string& value) const
113 {
114  value.clear();
115 
116  if (m_SUCResults->CountLines() == 0) {
117  if (col == 0) {
118  value = "Sort Unique Count complete, no errors found!";
119  }
120  return;
121  }
122 
123  if(row+1 == c_MaxRows) {
124  value ="Warning: Only the first " + NStr::NumericToString(c_MaxRows) + " rows can be shown";
125  return;
126  }
127  if (row < GetRowsCount()) {
129 
130  switch(col){
131  case eBlock:
132  {{
134  value = CSUCBlock::GetBlockLabel(block_type);
135  }}
136  break;
137 
138  case eLine:
139  value = line->GetLine();
140  break;
141 
142  default:
143  break;
144  }
145  }
146 
147 }
148 
149 string CTableDataSUC::GetHtmlValue(size_t row, size_t col) const
150 {
151  list<string> values;
152  string sDelimiter("<br>");
153  if (row < GetRowsCount()) {
154 
156 
157  switch(col){
158 
159  case eBlock:
160  {{
162  string value = CSUCBlock::GetBlockLabel(block_type);
164  c_BlockWidth,
165  values);
166  }}
167  break;
168 
169  case eLine:
170  NStr::Wrap(line->GetLine(),
171  c_LineWidth,
172  values);
173  break;
174 
175  default:
176  break;
177  }
178  }
179  return NStr::Join(values, sDelimiter);
180 }
181 
182 
183 long CTableDataSUC::GetIntValue(size_t row, size_t col) const
184 {
185  long value(0);
186  if (row < GetRowsCount()) {
188 
189  switch(col){
190  case eCount:
191  value = (long)line->GetCount();
192  break;
193  }
194  }
195  return value;
196 }
197 
198 
200 {
201  return GetRowObject(row);
202 }
203 
204 
206 {
208  if (row < GetRowsCount()) {
209  //!! this is incorrect since there may be several objects
210  //!! differently scoped
211  value.scope = m_Scope;
212  value.object = x_GetRowData(row);
213  }
214  return value;
215 }
216 
217 
219 {
220  return m_SUCResults->GetLine(row);
221 }
222 
224 
static CRef< CScope > m_Scope
CConstRef –.
Definition: ncbiobj.hpp:1266
static const char * GetBlockLabel(objects::CFlatFileConfig::FGenbankBlocks block_type)
Definition: suc_data.cpp:183
CConstRef< CSUCLine > GetLine(size_t pos) const
Definition: suc_data.cpp:320
objects::CFlatFileConfig::FGenbankBlocks GetBlockType(size_t pos) const
Definition: suc_data.cpp:334
size_t CountLines() const
Definition: suc_data.cpp:293
CScope –.
Definition: scope.hpp:92
CRef< CSUCResults > m_SUCResults
virtual size_t GetColsCount() const
virtual size_t GetRowsCount() const
virtual ColumnType GetColumnType(size_t col) const
static const size_t c_LineWidth
virtual string GetHtmlValue(size_t, size_t) const
virtual void GetStringValue(size_t row, size_t col, string &value) const
virtual ~CTableDataSUC()
CTableDataSUC(CSUCResults *results, objects::CScope *scope)
virtual long GetIntValue(size_t row, size_t col) const
CConstRef< CSUCLine > x_GetRowData(size_t row) const
virtual SConstScopedObject GetRowObject(size_t row) const
CRef< objects::CScope > m_Scope
static const size_t c_BlockWidth
static const size_t c_MaxRows
virtual SConstScopedObject GetObjectValue(size_t row, size_t col) const
virtual bool IsHtmlColumn(size_t col) const
virtual string GetColumnLabel(size_t col) const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
Definition: ncbistr.hpp:2697
static void Wrap(const string &str, SIZE_TYPE width, IWrapDest &dest, TWrapFlags flags, const string *prefix, const string *prefix1)
Definition: ncbistr.cpp:5347
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
T max(T x_, T y_)
#define row(bind, expected)
Definition: string_bind.c:73
static const string s_ColNames[]
USING_SCOPE(objects)
Modified on Sat Jun 22 10:37:57 2024 by modify_doxy.py rev. 669887