OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimLookUpTable.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: David Burken (dburken@imagelinks.com)
6 //
7 // Description:
8 //
9 // Contains class declaration for
10 //*******************************************************************
11 // $Id: ossimLookUpTable.cpp 19448 2011-04-26 15:15:07Z dburken $
12 
13 #include <iostream>
14 using namespace std;
15 
18 
19 ossimLookUpTable::ossimLookUpTable(const std::initializer_list<ossimString>& stringInitializer)
20 {
21  ossim_uint32 idx = 0;
22  for(auto value:stringInitializer)
23  {
24  theTable.push_back(ossimKeyValueMap(idx, value));
25  ++idx;
26  }
27 }
28 //*******************************************************************
29 // Protected Constructor:
30 //*******************************************************************
32  :
33  theTable(table_size)
34 {}
35 
37 {
38 }
39 
40 //*******************************************************************
41 // Public Method:
42 //*******************************************************************
44 {
45  for (ossim_uint32 i=0; i<theTable.size(); ++i)
46  {
47  if (theTable[i].theKey == entry_number)
48  {
49  return theTable[i].theValue;
50  }
51  }
52 
53  return ossimString(); // Entry number not found.
54 }
55 
56 //*******************************************************************
57 // Public Method:
58 //*******************************************************************
60 {
61  if (table_index < theTable.size())
62  {
63  return theTable[table_index].theValue;
64  }
65 
66  return ossimString(); // Index out of range.
67 }
68 
70 {
71  return getEntryString(entry_number);
72 }
73 
74 //*******************************************************************
75 // Public Method:
76 //*******************************************************************
78  const char* prefix) const
79 {
80  ossimString s = kwl.find(prefix, getKeyword());
81  return s;
82 }
83 
84 //*******************************************************************
85 // Public Method:
86 //*******************************************************************
88  bool case_insensitive) const
89 {
90  // Filter out trivial solution of NULL string:
91  ossimString s1 = entry_string;
92  if (!s1.empty())
93  {
94  s1 = s1.trim();
95  for (ossim_uint32 i=0; i<theTable.size(); i++)
96  {
97  ossimString s2 = theTable[i].theValue;
98 
99  if (case_insensitive == true)
100  {
101  s1.downcase();
102  s2.downcase();
103  }
104 
105  if (s1 == s2)
106  {
107  return theTable[i].theKey;
108  }
109  }
110  }
111 
112  return ossimLookUpTable::NOT_FOUND; // Entry number not found.
113 }
114 
115 //*******************************************************************
116 // Public Method:
117 //*******************************************************************
119  const char* prefix,
120  bool case_insensitive) const
121 {
122  const char* lookup = kwl.find(prefix, getKeyword());
123 
124  if (lookup)
125  {
126  return getEntryNumber(lookup, case_insensitive);
127  }
128 
129  return ossimLookUpTable::NOT_FOUND; // Entry number not found.
130 }
131 
133 {
134  return (ossim_uint32)theTable.size();
135 }
136 
138 {
139  return ossimKeyword();
140 }
141 
143 {
144  ossim_uint32 tableSize = getTableSize();
145  ossim_uint32 i = 0;
146 
147  for(i = 0; i < tableSize; ++i)
148  {
149  out << theTable[0].theValue << std::endl;
150  }
151 }
std::vector< ossimKeyValueMap > theTable
Represents serializable keyword/value map.
const char * find(const char *key) const
virtual ossimString getEntryString(ossim_int32 entry_number) const
virtual ~ossimLookUpTable()
virtual ossimKeyword getKeyword() const
virtual ossimString getTableIndexString(ossim_uint32 table_index) const
virtual ossimString operator[](ossim_int32 entry_number) const
virtual ossim_int32 getEntryNumber(const char *entry_string, bool case_insensitive=true) const
void dumpValues(std::ostream &out) const
unsigned int ossim_uint32
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
virtual ossim_uint32 getTableSize() const
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
bool empty() const
Definition: ossimString.h:411
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
int ossim_int32