Isis 3 Programmer Reference
ID.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7
8#include "ID.h"
9#include "IException.h"
10#include "Message.h"
11#include "IString.h"
12#include <iostream>
13using namespace std;
14namespace Isis {
15
22 ID::ID(const QString &name, int basenum) {
23 p_current = basenum;
24 p_namebase = name;
25 if(!p_namebase.contains("?")) {
26 QString msg = "No replacement set in string [" + p_namebase + "]";
27 throw IException(IException::User, msg, _FILEINFO_);
28 }
29 p_numStart = ((int) p_namebase.indexOf("?", 0));
30 int endPos = (int)p_namebase.lastIndexOf("?");
31 p_numLength = (endPos - p_numStart) + 1;
32 QString sub = p_namebase.mid(p_numStart, p_numLength);
33 for(int i = 0; i < (int)sub.length(); i++) {
34 if(sub[i] != '?') {
35 QString msg = "IString [" + p_namebase + "] contains more than one replacement set";
36 throw IException(IException::User, msg, _FILEINFO_);
37 }
38 }
39 p_namebase.remove(p_numStart, p_numLength);
40 }
41
46 }
47
53 QString ID::Next() {
54 IString num(p_current);
55 if((int)num.size() > p_numLength) {
56 QString replacement = "?";
57 while((int)replacement.size() < p_numLength) {
58 replacement += "?";
59 }
60 QString original = p_namebase;
61 original.insert(p_numStart, replacement);
62 QString msg = "Maximum number reached for string [" + original + "]";
63 throw IException(IException::User, msg, _FILEINFO_);
64 }
65 while((int)num.size() < p_numLength) {
66 num = "0" + num;
67 }
68 p_current++;
69 QString temp = p_namebase;
70 return temp.insert((p_numStart), num.c_str());
71 }
72
73}
ID(const QString &name, int basenum=1)
Creates an ID object.
Definition ID.cpp:22
QString Next()
Returns the next ID in the sequence.
Definition ID.cpp:53
~ID()
Deconstructor.
Definition ID.cpp:45
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
Adds specific functionality to C++ strings.
Definition IString.h:165
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
Namespace for the standard library.