USGS

Isis 3.0 Object Programmers' Reference

Home

Strategy.h
Go to the documentation of this file.
1 #ifndef Strategy_h
2 #define Strategy_h
3 
27 // Qt library
28 #include <QList>
29 #include <QPair>
30 #include <QScopedPointer>
31 #include <QSharedPointer>
32 #include <QString>
33 
34 // SharedResource and ResourceList typedefs
35 #include "Resource.h"
36 #include "PvlObject.h"
37 
38 class QStringList;
39 
40 namespace Isis {
41 
42  class GisGeometry;
43  class Progress;
44 
45 
102  class Strategy {
103 
104  public:
105  Strategy();
106  Strategy(const PvlObject &definition, const ResourceList &globals);
107  virtual ~Strategy();
108 
109  QString name() const;
110  QString type() const;
111  QString description() const;
112 
113  // Not intended to be reimplemented but available for direct calls
114  int apply(ResourceList &resources);
115  int apply(SharedResource &resource);
116 
117  // Inheriting strategies must reimplement either one or both of these
118  virtual int apply(ResourceList &resources, const ResourceList &globals);
119  virtual int apply(SharedResource &resource, const ResourceList &globals);
120 
121  unsigned int totalProcessed() const;
122 
123  protected:
125  typedef QSharedPointer<PvlObject> SharedPvlObject;
126 
127  // For default constructions
128  Strategy(const QString &name, const QString &type);
129 
130  void setName(const QString &name);
131  void setType(const QString &type);
132 
135  const ResourceList &globals) const;
136  const PvlObject &getDefinition() const;
138 
139 
140  void setApplyToDiscarded();
141  bool isApplyToDiscarded() const;
142  void setDoNotApplyToDiscarded(); // default
143 
144  int applyToResources(ResourceList &resources, const ResourceList &globals);
145  unsigned int processed();
146  void resetProcessed();
147 
148  int countActive(const ResourceList &resources) const;
149  int countDiscarded(const ResourceList &resources) const;
151  const QString &name) const;
152 
153  QString findReplacement(const QString &target, const ResourceList &globals,
154  const int &index = 0,
155  const QString &defValue = "") const;
156  QStringList qualifiers(const QString &keyspec,
157  const QString &delimiter = "::") const;
158  QString scanAndReplace(const QString &input, const QString &target,
159  const QString &replacement) const;
160  QString translateKeywordArgs(const QString &value,
161  const ResourceList &globals,
162  const QString &defValue = "") const;
163  QString processArgs(const QString &value, const QStringList &argKeys,
164  const ResourceList &globals,
165  const QString &defValue = "") const;
166 
167  void propagateKeys(SharedResource &source, SharedResource &target) const;
168  SharedResource composite(SharedResource &resourceA, SharedResource &resourceB,
169  const QPair<QString, QString> &keySuffix = qMakePair(QString("A"),QString("B"))) const;
170  bool importGeometry(SharedResource &resource,
171  const ResourceList &globals) const;
172 
173  ResourceList activeList(ResourceList &resources) const;
174  void activateList(ResourceList &resources) const;
175  void deactivateList(ResourceList &resources) const;
176  ResourceList copyList(const ResourceList &resources) const;
177  ResourceList cloneList(const ResourceList &resources,
178  const bool &withAssets = false) const;
179 
181  const ResourceList &globals);
182  bool isDebug() const;
183 
184  bool doShowProgress() const;
185  bool initProgress(const int &nsteps = 0, const QString &text = "");
186 
187  static void queryCallback(void *item, void *userdata);
188 
189  QStringList getObjectList(const PvlObject &object) const;
190 
191  template <class STRATEGYLIST, class STRATEGYFACTORY>
192  STRATEGYLIST LoadMinerStrategies(const QString &minerName,
193  const ResourceList &globals) const {
194  STRATEGYFACTORY *factory = STRATEGYFACTORY::instance();
195 
196  STRATEGYLIST miner;
197  QString config = translateKeywordArgs(minerName+"ConfigFile", globals);
198  if ( !config.isEmpty() ) {
199  miner = factory->buildRun(config, globals);
200  }
201  else if ( getDefinition().hasObject(minerName+"Miner") ) {
202  miner = factory->buildRun(getDefinition().findObject(minerName+"Miner"),
203  globals);
204  }
205 
206  return (miner);
207  }
208 
209  private:
221  QString m_name;
225  QString m_type;
229  unsigned int m_total;
236  bool m_debug;
239  QScopedPointer<Progress> m_progress;
240 
241  };
242 
244  typedef QSharedPointer<Strategy> SharedStrategy;
245 
248 
249 } // Namespace Isis
250 
252 
253 #endif
254