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

Go to the SVN repository for this file.

1 /* $Id: cmd_table_assign_column.cpp 32112 2015-01-02 14:35:27Z kuznets $
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: Roman Katargin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
32 
35 
37 {
38  size_t rows = m_TableData->GetRowsCount();
39 
40  if (m_Col >= 0 && m_Col < (int)m_TableData->GetColsCount() && m_TableData->AllowEdit(m_Col)) {
41 
42  m_SaveValues.clear();
43  switch(m_TableData->GetColumnType(m_Col)) {
44  case ITableData::kInt:
45  {{
46  long newVal = 0;
47  if (!m_Value.Convert(&newVal))
48  return;
49 
50  for (size_t row = 0; row < rows; ++row) {
51  long saveValue = m_TableData->GetIntValue(row, m_Col);
52  m_SaveValues.push_back(wxVariant(saveValue));
53  m_TableData->SetIntValue(row, m_Col, newVal);
54 
55  }
56  }}
57  break;
58  case ITableData::kReal:
59  {{
60  double newVal = 0;
61  if (!m_Value.Convert(&newVal))
62  return;
63 
64  for (size_t row = 0; row < rows; ++row) {
65  double saveValue = m_TableData->GetRealValue(row, m_Col);
66  m_SaveValues.push_back(wxVariant(saveValue));
67  m_TableData->SetRealValue(row, m_Col, newVal);
68 
69  }
70  }}
71  break;
74  {{
75  wxString newVal;
76  if (!m_Value.Convert(&newVal))
77  return;
78 
79  string newValUTF8(newVal.ToUTF8());
80  string saveValue;
81  for (size_t row = 0; row < rows; ++row) {
82  m_TableData->GetStringValue(row, m_Col, saveValue);
83  m_SaveValues.push_back(wxVariant(wxString::FromUTF8(saveValue.c_str())));
84  if (m_Op == eAppend)
85  m_TableData->SetStringValue(row, m_Col, saveValue + newValUTF8);
86  else if (m_Op == ePrepend)
87  m_TableData->SetStringValue(row, m_Col, newValUTF8 + saveValue);
88  else
89  m_TableData->SetStringValue(row, m_Col, newValUTF8);
90  }
91  }}
92  break;
93 
94  default:
95  break;
96  }
97  }
98 }
99 
101 {
102  size_t rows = m_TableData->GetRowsCount();
103  if (m_SaveValues.size() != rows)
104  return;
105 
106  if (m_Col >= 0 && m_Col < (int)m_TableData->GetColsCount() && m_TableData->AllowEdit(m_Col)) {
107 
108  switch(m_TableData->GetColumnType(m_Col)) {
109  case ITableData::kInt:
110  {{
111  for (size_t row = 0; row < rows; ++row) {
112  long saveValue = 0;
113  if (m_SaveValues[row].Convert(&saveValue)) {
114  m_TableData->SetIntValue(row, m_Col, saveValue);
115  }
116  }
117  }}
118  break;
119  case ITableData::kReal:
120  {{
121  for (size_t row = 0; row < rows; ++row) {
122  double saveValue = 0;
123  if (m_SaveValues[row].Convert(&saveValue)) {
124  m_TableData->SetRealValue(row, m_Col, saveValue);
125  }
126  }
127  }}
128  break;
130  case ITableData::kString:
131  {{
132  for (size_t row = 0; row < rows; ++row) {
133  wxString saveValue;
134  if (m_SaveValues[row].Convert(&saveValue)) {
135  string saveValUTF8(saveValue.ToUTF8());
136  m_TableData->SetStringValue(row, m_Col, saveValUTF8);
137  }
138  }
139  }}
140  break;
141 
142  default:
143  break;
144  }
145  }
146  m_SaveValues.clear();
147 }
148 
150 {
151  return "Change column value";
152 }
153 
vector< wxVariant > m_SaveValues
CIRef< ITableData > m_TableData
virtual void Execute()
Do the editing action.
virtual void Unexecute()
Undo (opposite to Execute())
USING_SCOPE(objects)
#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 row(bind, expected)
Definition: string_bind.c:73
const value_slice::CValueConvert< value_slice::SRunTimeCP, FROM > Convert(const FROM &value)
Modified on Sun Apr 14 05:25:43 2024 by modify_doxy.py rev. 669887