Isis 3 Programmer Reference
ID.cpp
1 
19 #include "ID.h"
20 #include "IException.h"
21 #include "Message.h"
22 #include "IString.h"
23 #include <iostream>
24 using namespace std;
25 namespace Isis {
26 
33  ID::ID(const QString &name, int basenum) {
34  p_current = basenum;
35  p_namebase = name;
36  if(!p_namebase.contains("?")) {
37  QString msg = "No replacement set in string [" + p_namebase + "]";
38  throw IException(IException::User, msg, _FILEINFO_);
39  }
40  p_numStart = ((int) p_namebase.indexOf("?", 0));
41  int endPos = (int)p_namebase.lastIndexOf("?");
42  p_numLength = (endPos - p_numStart) + 1;
43  QString sub = p_namebase.mid(p_numStart, p_numLength);
44  for(int i = 0; i < (int)sub.length(); i++) {
45  if(sub[i] != '?') {
46  QString msg = "IString [" + p_namebase + "] contains more than one replacement set";
47  throw IException(IException::User, msg, _FILEINFO_);
48  }
49  }
50  p_namebase.remove(p_numStart, p_numLength);
51  }
52 
56  ID::~ID() {
57  }
58 
64  QString ID::Next() {
65  IString num(p_current);
66  if((int)num.size() > p_numLength) {
67  QString replacement = "?";
68  while((int)replacement.size() < p_numLength) {
69  replacement += "?";
70  }
71  QString original = p_namebase;
72  original.insert(p_numStart, replacement);
73  QString msg = "Maximum number reached for string [" + original + "]";
74  throw IException(IException::User, msg, _FILEINFO_);
75  }
76  while((int)num.size() < p_numLength) {
77  num = "0" + num;
78  }
79  p_current++;
80  QString temp = p_namebase;
81  return temp.insert((p_numStart), num.c_str());
82  }
83 
84 }
Namespace for the standard library.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
Isis exception class.
Definition: IException.h:107
Adds specific functionality to C++ strings.
Definition: IString.h:181
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31