Isis 3 Programmer Reference
ObservationNumberList.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "ObservationNumberList.h"
8
9#include "FileName.h"
10#include "IException.h"
11#include "Pvl.h"
12#include "SerialNumberList.h"
13
14using namespace std;
15namespace Isis {
16
26 ObservationNumberList::ObservationNumberList(const QString &listfile, bool checkTarget) :
27 SerialNumberList(listfile, checkTarget) {
28 init(this);
29 }
30
31
41
42
52
53 if (snlist->size() == 0) {
54 QString msg = "Serial number list is empty";
55 throw IException(IException::User, msg, _FILEINFO_);
56 }
57
58 map<QString, int> observationMap;
59 QString observationNumber;
60 int currentIndex = 0;
61 int observationIndex;
62
63 // Fill the temporary map to generate observation sets
64 for (int isn = 0; isn < snlist->size(); isn++) {
65 observationNumber = snlist->observationNumber(isn);
66
67 if (observationMap.find(observationNumber) == observationMap.end()) {
68 observationMap.insert(pair<QString, int>(observationNumber, currentIndex));
69 observationIndex = currentIndex++;
70 }
71 else {
72 observationIndex = observationMap.find(observationNumber)->second;
73 }
74
75 add(isn, observationIndex, observationNumber);
76 }
77 m_numberObservations = currentIndex;
78 }
79
80
86
87
96
97 if (snlist->size() == 0) {
98 QString msg = "Cannot remove, serial number list is empty";
99 throw IException(IException::User, msg, _FILEINFO_);
100 }
101
102 m_sets.clear();
103 m_indexMap.clear();
104
105 map<QString, int> observationMap;
106 QString observationNumber;
107 int currentIndex = 0;
108 int observationIndex;
109
110 // Fill the temporary map to generate observation sets
111 for (int isn = 0; isn < this->size(); isn++) {
112 if ( (snlist->hasSerialNumber(this->serialNumber(isn))) ) {
113 continue;
114 }
115
117
118 if (observationMap.find(observationNumber) == observationMap.end()) {
119 observationMap.insert(pair<QString, int>(observationNumber, currentIndex));
120 observationIndex = currentIndex++;
121 }
122 else {
123 observationIndex = observationMap.find(observationNumber)->second;
124 }
125
126 add(isn, observationIndex, observationNumber);
127 }
128 m_numberObservations = currentIndex;
129 }
130
131
137 void ObservationNumberList::remove(const QString &listfile) {
138 SerialNumberList snlist(listfile);
139 remove(&snlist);
140 }
141
142
154 void ObservationNumberList::add(const int isn, const int observationIndex,
155 QString observationNumber) {
156
157 ObservationSet nextset;
158 nextset.serialNumberIndex = isn;
159 nextset.observationNumberIndex = observationIndex;
160 nextset.observationNumber = observationNumber;
161
162 m_sets.push_back(nextset);
163 m_indexMap.insert(pair<int, int>(isn, observationIndex));
164 }
165
166
175
176
186 for (unsigned index = 0; index < m_pairs.size(); index++) {
187 if (m_pairs[index].observationNumber == on) {
188 return true;
189 }
190 }
191 return false;
192 }
193
194
205 // if (serialNumberIndex >= 0 && serialNumberIndex < (int) m_indexMap.size()) {
206 if (serialNumberIndex >= 0) {
207 return m_indexMap.find(serialNumberIndex)->second;
208 }
209 else {
210 QString msg = "Serial Number Index [" + toString(serialNumberIndex) + "] is invalid";
211 throw IException(IException::Programmer, msg, _FILEINFO_);
212 }
213 }
214
215
226 QString ObservationNumberList::observationNumber(const QString &filename) {
227 if (m_fileMap.find(FileName(filename).expanded()) == m_fileMap.end()) {
228 QString msg = "Requested filename [" + FileName(filename).expanded() + "] ";
229 msg += "does not exist in the list";
230 throw IException(IException::Programmer, msg, _FILEINFO_);
231 }
232 int index = fileNameIndex(filename);
233 return m_pairs[index].observationNumber;
234 }
235
236
247 if (index >= 0 && index < (int) m_pairs.size()) {
248 return m_pairs[index].observationNumber;
249 }
250 else {
251 QString msg = "Index [" + toString(index) + "] is invalid";
252 throw IException(IException::Programmer, msg, _FILEINFO_);
253 }
254 }
255
256
267 vector<QString> ObservationNumberList::possibleFileNames(const QString &on) {
268 vector<QString> filenames;
269 for (unsigned index = 0; index < m_pairs.size(); index++) {
270 if (m_pairs[index].observationNumber == on) {
271 filenames.push_back(m_pairs[index].filename);
272 }
273 }
274 if (filenames.size() > 0) {
275 return filenames;
276 }
277 else {
278 QString msg = "Requested observation number [" + on + "] ";
279 msg += "does not exist in the list";
280 throw IException(IException::Programmer, msg, _FILEINFO_);
281 }
282 }
283
284}
File name manipulation and expansion.
Definition FileName.h:100
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition FileName.cpp:196
Isis exception class.
Definition IException.h:91
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
std::vector< ObservationSet > m_sets
List of observation sets.
int observationSize() const
How many unique observations are in the list?
void init(SerialNumberList *snlist)
Initiates the ObservationNumberList.
bool hasObservationNumber(const QString &on)
Determines whether or not the requested observation number exists in the list.
std::vector< QString > possibleFileNames(const QString &on)
Return possible filenames given an observation number.
ObservationNumberList(const QString &list, bool checkTarget=true)
Creates an ObservationNumberList from a filename.
void remove(SerialNumberList *snlist)
Removes all of the listed serial numbers from the observation.
QString observationNumber(const QString &filename)
Return an observation number given a filename.
void add(int isn, const int observationIndex, QString observationNumber)
Adds a new serial number index / observation number index / observation number to the SerialNumberLis...
int observationNumberMapIndex(const int serialNumberIndex)
Return a observation index given a serial number index.
int m_numberObservations
Count of observations in the observation number list.
std::multimap< int, int > m_indexMap
Maps serial number index to observation number index.
Serial Number list generator.
std::map< QString, int > m_fileMap
Maps filenames to their positions in the list.
int size() const
How many serial number / filename combos are in the list.
int serialNumberIndex(const QString &sn)
Return a list index given a serial number.
int fileNameIndex(const QString &filename)
Return a list index given a filename.
std::vector< Pair > m_pairs
List of serial number Pair entities.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
Namespace for the standard library.
An observation consiting of a serial number index to the ObservationNumberList, an observation number...