Isis Developer Reference
Resource.h
Go to the documentation of this file.
1 #ifndef Resource_h
2 #define Resource_h
3 
8 /* SPDX-License-Identifier: CC0-1.0 */
9 
10 // Qt library
11 #include <QExplicitlySharedDataPointer>
12 #include <QMap>
13 #include <QMetaType>
14 #include <QSharedData>
15 #include <QString>
16 #include <QVariant>
17 
18 #include "GisGeometry.h" // SharedGisGeometry type
19 #include "PvlFlatMap.h"
20 
21 namespace Isis {
22 
23  class PvlContainer;
24  class PvlKeyword;
25  class PvlObject;
26 
54  class Resource {
55 
56  public:
57  Resource();
58  Resource(const QString &name);
59  Resource(const QString &name, const PvlFlatMap &profile);
60  Resource(const QString &name, const PvlContainer &profile);
61  Resource(const Resource &other);
62  virtual ~Resource();
63 
64  QString name() const;
65  void setName(const QString &identity);
66  bool isEqual(const Resource &other) const;
67 
68  bool exists(const QString &keywordName) const;
69  int count(const QString &keywordName) const;
70  bool isNull(const QString &keywordName, const int keywordIndex = 0) const;
71 
72  const PvlFlatMap &keys() const;
73  QString value(const QString &keywordName, const int &keywordIndex = 0) const;
74  QString value(const QString &keywordName, const QString &defValue,
75  const int &keywordIndex = 0) const;
76  PvlKeyword keyword(const QString &keywordName) const;
77 
78  void add(const QString &keywordName, const QString &keywordValue);
79  void add(const PvlKeyword &keyword);
80  void add(const PvlFlatMap &keys);
81  void append(const QString &keywordName, const QString &keywordValue);
82 
83  int erase(const QString &keywordName);
84 
85  void add(GisGeometry *geom);
86  void add(SharedGisGeometry &geom);
87 
88  bool hasGeometry() const;
89  bool hasValidGeometry() const;
91 
92  void activate();
93  bool isActive() const;
94  void discard();
95  bool isDiscarded() const;
96 
97  bool hasAsset(const QString &assetName) const;
98  void addAsset(const QString &assetName, QVariant &assetValue);
99  QVariant asset(const QString &assetName) const;
100  int removeAsset(const QString &assetName);
101  int clearAssets();
102 
103  virtual Resource *copy() const;
104  virtual Resource *clone(const QString &name,
105  const bool &withAssets=false) const;
106 
107  virtual PvlObject toPvl(const QString &pvlName = "Resource") const;
108 
109  protected:
110  Resource(const Resource &other, const bool deepcopy);
111 
112  private:
115 
123  class ResourceData : public QSharedData {
124  public:
125  ResourceData() : m_name("Resource"), m_keys(),
126  m_assets(), m_geom(0) { }
127  ResourceData(const ResourceData &other) : QSharedData(other),
128  m_name(other.m_name),
129  m_keys(other.m_keys),
130  m_assets(other.m_assets),
131  m_geom(other.m_geom) { }
132  ResourceData(const QString &name) : QSharedData(),
133  m_name(name),
134  m_keys(),
135  m_assets(),
136  m_geom(0) { }
137  ResourceData(const QString &name, const PvlFlatMap &profile) :
138  QSharedData(),
139  m_name(name),
140  m_keys(profile),
141  m_assets(),
142  m_geom(0) { }
143 
144  QString m_name;
146  PvlFlatMap m_keys;
150  VariantList m_assets;
153  SharedGisGeometry m_geom;
155  };
156 
157  // Member variables
159  QExplicitlySharedDataPointer<ResourceData> m_data;
160  bool m_discard;
163  };
164 
167 
170 
171 
172 } // Namespace Isis
173 
174 // Declarations so they can be stored as QVariants (assets)
177 
178 #endif
179 
Isis::Resource::activate
void activate()
Activate a resource.
Definition: Resource.cpp:411
Isis::Resource::isActive
bool isActive() const
Accessor method to determine whether this Resource is to be discarded.
Definition: Resource.cpp:421
Isis::Resource::keys
const PvlFlatMap & keys() const
Accessor method for the PVL keywords associated with this Resource.
Definition: Resource.cpp:198
Isis::Resource::addAsset
void addAsset(const QString &assetName, QVariant &assetValue)
Inserts an asset with the given name and value into this Resource's VariantList.
Definition: Resource.cpp:463
Isis::PvlObject
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:61
Isis::Resource::exists
bool exists(const QString &keywordName) const
Determines whether a PVL keyword with the given name is in this Resource.
Definition: Resource.cpp:155
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
QSharedData
QList< SharedResource >
Isis::Resource::discard
void discard()
Discard a resource.
Definition: Resource.cpp:429
Isis::PvlFlatMap
Provides a flat map of PvlKeywords.
Definition: PvlFlatMap.h:218
Isis::Resource::count
int count(const QString &keywordName) const
Counts the number of values the PVL keyword with the given name has, if it exists in this Resource.
Definition: Resource.cpp:169
Isis::PvlFlatMap::ConstPvlFlatMapIterator
QMap< QString, PvlKeyword >::const_iterator ConstPvlFlatMapIterator
A const iterator for the underling QMap that PvlFlatMap is built on.
Definition: PvlFlatMap.h:222
Isis::Resource::clone
virtual Resource * clone(const QString &name, const bool &withAssets=false) const
Clone this resource for additional specialized use.
Definition: Resource.cpp:548
PvlFlatMap.h
Isis::Resource::isDiscarded
bool isDiscarded() const
Accessor method to determine whether this Resource is to be discarded.
Definition: Resource.cpp:439
Resource.h
QSharedPointer< GisGeometry >
Isis::Resource::value
QString value(const QString &keywordName, const int &keywordIndex=0) const
Gets the value of the PVL keyword with the given name at the given index.
Definition: Resource.cpp:224
Isis::Resource::~Resource
virtual ~Resource()
Destroys the Resource object.
Definition: Resource.cpp:105
Isis::Resource::hasGeometry
bool hasGeometry() const
This method is used to determine whether the GIS geometry has been set for this Resource.
Definition: Resource.cpp:378
Isis::Resource::setName
void setName(const QString &identity)
A mutator to set the Resource's name.
Definition: Resource.cpp:124
Isis::Resource::isEqual
bool isEqual(const Resource &other) const
Checks for equality of another Resource.
Definition: Resource.cpp:142
Isis::Resource::removeAsset
int removeAsset(const QString &assetName)
Removes all of the assets in this Resource that are mapped to the given name.
Definition: Resource.cpp:477
Isis::GisGeometry
Encapsulation class provides support for GEOS-C API.
Definition: GisGeometry.h:50
Isis::Resource::clearAssets
int clearAssets()
Clears the assets from this Resource's VariantList.
Definition: Resource.cpp:487
Isis::Resource::name
QString name() const
Accessor for a string containing the Resource's name.
Definition: Resource.cpp:114
GisGeometry.h
_FILEINFO_
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:24
Isis::Resource::add
void add(const QString &keywordName, const QString &keywordValue)
Adds a PVL keyword with the given name and value to this Resource.
Definition: Resource.cpp:286
Isis::Resource::asset
QVariant asset(const QString &assetName) const
Retrieves the value of the asset in this Resource that is mapped to the given name.
Definition: Resource.cpp:504
Isis::Resource::Resource
Resource()
Default constructor for a Resource object.
Definition: Resource.cpp:31
Isis::ResourceList
QList< SharedResource > ResourceList
Defintion of a ResourceList, a list of SharedResource types.
Definition: Resource.h:169
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::SharedGisGeometry
QSharedPointer< GisGeometry > SharedGisGeometry
Definition for a SharedGisGeometry, a shared pointer to a GisGeometry.
Definition: GisGeometry.h:125
Isis::Resource
This class provides a resource of PVL keywords for Strategy classes.
Definition: Resource.h:54
PvlContainer.h
Isis::Resource::keyword
PvlKeyword keyword(const QString &keywordName) const
Gets the PvlKeyword object with the given name, if it exists in this Resource.
Definition: Resource.cpp:270
IException.h
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
std
Namespace for the standard library.
Isis::Resource::append
void append(const QString &keywordName, const QString &keywordValue)
Appends the given value to the PVL keyword with the given name.
Definition: Resource.cpp:327
PvlKeyword.h
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(Isis::SharedResource)
Isis::SharedResource
QSharedPointer< Resource > SharedResource
Defintion of a SharedResource, a shared pointer to a Resource object.
Definition: Resource.h:166
PvlObject.h
Isis::Resource::erase
int erase(const QString &keywordName)
Removes all of the PVL keywords in this Resource that are associated with the given name.
Definition: Resource.cpp:341
QMap< QString, QVariant >
Isis::PvlContainer
Contains more than one keyword-value pair.
Definition: PvlContainer.h:49
Isis::Resource::hasAsset
bool hasAsset(const QString &assetName) const
This method is used to determine whether an asset with the given name is in this Resource.
Definition: Resource.cpp:452
Isis::Resource::geometry
SharedGisGeometry geometry() const
Accessor method for this Resource's GIS geometry.
Definition: Resource.cpp:403
Isis::Resource::isNull
bool isNull(const QString &keywordName, const int keywordIndex=0) const
Determines whether the PVL keyword with the given name at the given index is null.
Definition: Resource.cpp:187
Isis::Resource::copy
virtual Resource * copy() const
Copy this resource for distinct management of its status.
Definition: Resource.cpp:526
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::Resource::toPvl
virtual PvlObject toPvl(const QString &pvlName="Resource") const
Transfer all keywords in map to a PvlObject.
Definition: Resource.cpp:566
Isis::Resource::hasValidGeometry
bool hasValidGeometry() const
This method is used to determine whether a valid GIS geometry has been set for this Resource.
Definition: Resource.cpp:389