OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimStringListProperty.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: Garrett Potts
7 //
8 //*************************************************************************
9 // $Id: ossimStringListProperty.cpp 19682 2011-05-31 14:21:20Z dburken $
10 //
11 #include <sstream>
12 #include <algorithm>
15 RTTI_DEF1(ossimStringListProperty, "ossimStringListProperty", ossimProperty);
16 
18  const std::vector<ossimString>& value)
19  :ossimProperty(name),
20  theValueList(value),
21  theUniqueFlag(false),
22  theOrderMattersFlag(false)
23 {
24 }
25 
27  :ossimProperty(rhs),
28  theValueList(rhs.theValueList),
29  theConstraintList(rhs.theConstraintList),
30  theUniqueFlag(rhs.theUniqueFlag),
31  theOrderMattersFlag(rhs.theOrderMattersFlag),
32  theMinNumberOfValues(rhs.theMinNumberOfValues),
33  theMaxNumberOfValues(rhs.theMaxNumberOfValues)
34 {
35 }
36 
38 {
39  return new ossimStringListProperty(*this);
40 }
41 
43 {
45 
46  const ossimStringListProperty *rhsPtr = dynamic_cast<const ossimStringListProperty*>(&rhs);
47  if(rhsPtr)
48  {
49  theValueList = rhsPtr->theValueList;
51  theUniqueFlag = rhsPtr->theUniqueFlag;
55  }
56 
57  return *this;
58 }
59 
61 {
62  ossimKeywordlist kwl;
63  std::istringstream in(value);
64  bool result = true;
65 
66  if(kwl.parseStream(in))
67  {
68  int idx = 0;
69  std::vector<ossimString> keys =
70  kwl.getSubstringKeyList( "^([0-9]*" );
71 
72  std::vector<int> theNumberList(keys.size());
73  for(idx = 0; idx < (int)theNumberList.size();++idx)
74  {
75  theNumberList[idx] = keys[idx].toInt();
76  }
77  std::sort(theNumberList.begin(), theNumberList.end());
79  for(idx = 0; idx < (int)theNumberList.size(); ++idx)
80  {
81  const char* temp = kwl.find(ossimString::toString(theNumberList[idx]));
82 
83  if(temp)
84  {
85  addValue(temp);
86  }
87  }
88  }
89  else
90  {
91  result = false;
92  }
93 
94  return result;
95 }
96 
98 {
99  ossimKeywordlist kwl;
100  int idx = 0;
101 
102  for(idx = 0; idx < (int)theValueList.size(); ++idx)
103  {
104  kwl.add(ossimString::toString(idx).c_str(),
105  theValueList[idx],
106  true);
107  }
108 
109  valueResult = kwl.toString();
110 }
111 
112 
114 {
115  theValueList.clear();
116 }
117 
119 {
120  if((idx >= 0)&&
121  (idx < (int)getNumberOfValues()))
122  {
123  return theValueList[idx];
124  }
125 
126  return ossimString("");;
127 }
128 
130  const ossimString& value)
131 {
132  bool result = true;
133 
134  if(canAddValue(value))
135  {
136  if((idx < (int)getNumberOfValues())&&
137  (idx >= 0))
138  {
139  theValueList[idx] = value;
140  }
141  }
142  else
143  {
144  result = false;
145  }
146  return result;
147 
148 }
149 
151 {
152  bool result = true;
153 
154  if(canAddValue(value))
155  {
156  theValueList.push_back(value);
157  }
158  else
159  {
160  result = false;
161  }
162 
163  return result;
164 }
165 
167 {
168  return (int)theValueList.size();
169 }
170 
172 {
173  return (ossim_uint32)theConstraintList.size();
174 }
175 
177 {
178  if(idx < theConstraintList.size())
179  {
180  return theConstraintList[(int)idx];
181  }
182 
183  return ossimString("");
184 }
185 
186 void ossimStringListProperty::setConstraints(const std::vector<ossimString>& constraints)
187 {
188  theConstraintList = constraints;
189 }
190 
192 {
193  return (theConstraintList.size()>0);
194 }
195 
197 {
198  theUniqueFlag = flag;
199 }
200 
202 {
203  theOrderMattersFlag = flag;
204 }
205 
207  int maxNumber)
208 {
209  theMinNumberOfValues = minNumber;
210  theMaxNumberOfValues = maxNumber;
211 }
212 
214  int& maxNumber)const
215 {
216  minNumber = theMinNumberOfValues;
217  maxNumber = theMaxNumberOfValues;
218 }
219 
221 {
222  return (std::find(theConstraintList.begin(),
223  theConstraintList.end(),
224  value)!=theConstraintList.end());
225 }
226 
228 {
229  return (std::find(theValueList.begin(),
230  theValueList.end(),
231  value)!=theConstraintList.end());
232 }
233 
235 {
236  bool result = true;
237 
238  if(hasConstraints())
239  {
240  if(findValueInConstraintList(value))
241  {
242  if(theUniqueFlag)
243  {
244  if(findValueInValueList(value))
245  {
246  result = false;
247  }
248  }
249  }
250  else
251  {
252  result = false;
253  }
254  }
255 
256  return result;
257 }
ossim_uint32 getNumberOfContraints() const
ossimStringListProperty(const ossimString &name=ossimString(""), const std::vector< ossimString > &value=std::vector< ossimString >())
ossimString getConstraintAt(ossim_uint32 idx) const
bool findValueInValueList(const ossimString &value) const
bool setValueAt(int idx, const ossimString &value)
Represents serializable keyword/value map.
void setNumberOfValuesBounds(int minNumber, int maxNumber)
virtual const ossimProperty & assign(const ossimProperty &rhs)
const char * find(const char *key) const
static ossimString toString(bool aValue)
Numeric to string methods.
std::vector< ossimString > theValueList
virtual const ossimProperty & assign(const ossimProperty &rhs)
void getNumberofValuesBounds(int &minNumber, int &maxNumber) const
virtual bool setValue(const ossimString &value)
virtual ossimString valueToString() const
bool addValue(const ossimString &value)
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
bool canAddValue(const ossimString &value) const
void setConstraints(const std::vector< ossimString > &constraints)
RTTI_DEF1(ossimStringListProperty, "ossimStringListProperty", ossimProperty)
unsigned int ossim_uint32
ossim_uint32 getNumberOfValues() const
std::vector< ossimString > getSubstringKeyList(const ossimString &regularExpression) const
ossimString getValueAt(int idx) const
virtual bool parseStream(ossim::istream &is, bool ignoreBinaryChars)
deprecated method
virtual ossimString toString() const
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
bool findValueInConstraintList(const ossimString &value) const
std::vector< ossimString > theConstraintList