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

Go to the SVN repository for this file.

1 /* $Id: userfield_stringlist_validator.cpp 38247 2017-04-18 19:27:40Z filippov $
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 
36 
37 #include <serial/objectinfo.hpp>
38 
40 #include "string_list_ctrl.hpp"
41 
44 
45 /*
46  * CSerialStringListValidator
47  */
48 
49 
51  : m_User(user), m_FieldName(fieldName)
52 {
53 }
54 
55 
57  : wxValidator(), m_User(val.m_User), m_FieldName(val.m_FieldName)
58 {
59 }
60 
61 
63 {
64  CStringListCtrl *control = (CStringListCtrl*)m_validatorWindow;
65  control->Clear();
66 
67  size_t maxStringsCount = control->GetMaxStringsCount();
68 
69  if (m_User.IsSetData()) {
70  ITERATE (CUser_object::TData, field, m_User.GetData()) {
71  if ((*field)->IsSetData()
72  && (*field)->IsSetLabel() && (*field)->GetLabel().IsStr()
73  && NStr::EqualCase((*field)->GetLabel().GetStr(), m_FieldName)) {
74  if ((*field)->GetData().IsStr()) {
75  control->AddString((*field)->GetData().GetStr());
76  if (--maxStringsCount == 0)
77  break;
78  } else if ((*field)->GetData().IsStrs()) {
79  ITERATE(CUser_field::TData::TStrs, str, (*field)->GetData().GetStrs()) {
80  control->AddString(*str);
81  --maxStringsCount;
82  }
83  }
84  }
85  }
86  }
87 
88  if (maxStringsCount > 0)
89  control->AddString("");
90 
91  control->FitInside();
92 
93  return true;
94 }
95 
97 {
98  CUser_field& field = m_User.SetField(m_FieldName);
99  field.ResetData();
100 
101  CStringListCtrl *control = (CStringListCtrl *)m_validatorWindow;
102  CStringListCtrl::CConstIterator it(*control);
103 
104  int num_values = 0;
105  if (it) {
106  for (; it; ++it) {
107  string value = it.GetValue();
109  if (!value.empty()) {
110  field.SetData().SetStrs().push_back(value);
111  num_values++;
112  }
113  }
114  }
115  field.SetNum(num_values);
116  if (num_values == 0) {
117  NON_CONST_ITERATE (CUser_object::TData, field, m_User.SetData()) {
118  if ((*field)->IsSetLabel() && (*field)->GetLabel().IsStr()
119  && NStr::EqualCase((*field)->GetLabel().GetStr(), m_FieldName)) {
120  m_User.SetData().erase(field);
121  break;
122  }
123  }
124  }
125  return true;
126 }
127 
bool AddString(const string &value)
size_t GetMaxStringsCount() const
CUserFieldStringListValidator(objects::CUser_object &user, const string &fieldName)
static const char * str(char *buf, int n)
Definition: stats.c:84
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3201
static bool EqualCase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-sensitive equality of a substring with another string.
Definition: ncbistr.hpp:5325
void SetNum(TNum value)
Assign a value to Num data member.
void SetData(TData &value)
Assign a value to Data data member.
vector< CStringUTF8 > TStrs
void ResetData(void)
Reset Data data member.
vector< CRef< CUser_field > > TData
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
USING_SCOPE(objects)
Modified on Thu Apr 11 15:02:23 2024 by modify_doxy.py rev. 669887