IsisDlm  Version 0.2
KeywordHandler.h
Go to the documentation of this file.
00001 
00002 //_Title KeywordHandler.h Definition of basic ISIS support structure
00003 //
00004 //_Descr ISIS3 file/functionality definition.
00005 //
00006 //_Hist Jul 24 2004 Kris Becker, USGS
00007 //_Version: $Id: KeywordHandler.h,v 1.4 2007/04/26 16:38:58 kbecker Exp $
00008 //_End
00010 
00011 #if !defined(KeywordHandler_h)
00012 #define KeywordHandler_h
00013 #include <string>
00014 #include <vector>
00015 
00016 #include <QString>
00017 #include <QList>
00018 #include <QStringList>
00019 #include <QVariant>
00020 #include <QMetaType>
00021 
00022 #include "Cube.h"
00023 #include "Pvl.h"
00024 #include "PvlKeyword.h"
00025 #include "IException.h"
00026 #include "IString.h"
00027 
00028 namespace ISISDLM {
00038 class PvlSpecs {
00039   public:
00040     typedef enum { Object, Group, Container, Keyword, None } PvlType;
00041     PvlSpecs();
00042     PvlSpecs(const QString &spec, const PvlType &ptype);
00043     ~PvlSpecs() { }
00044 
00045     QString name() const;
00046     PvlType type() const;
00047 
00048     void setType(const PvlType &ptype);
00049     bool hasQualifiers(Isis::PvlContainer &element) const;
00050 
00051   private:
00052     QString           m_spec;
00053     QString           m_name;
00054     PvlType           m_type;
00055     QList<Isis::PvlKeyword> m_qualifiers;
00056 
00057     void init(const QString &spec);
00058 };
00059 
00060 
00066 class KeywordHandler {
00067   public:
00068     typedef PvlSpecs::PvlType PvlType;
00069     KeywordHandler( );
00070     KeywordHandler(const QString &path, const PvlType &type = PvlSpecs::Keyword,
00071                    const bool &recurse = false);
00072     KeywordHandler(const std::string &path, const PvlType &type = PvlSpecs::Keyword,
00073                    const bool &recurse = false);
00074     ~KeywordHandler() { }
00075 
00076     void setRecursive();
00077     void setNoRecursive();
00078 
00079     Isis::PvlKeyword read(Isis::Pvl &pvl) const;
00080     static Isis::PvlKeyword read(const QString &path, Isis::Pvl &pvl);
00081 
00082 #if defined(FULL_IMPLEMENTATION)
00083     bool exists(const Pvl &pvl) const;
00084     bool write(const QStringList &values, Pvl &pvl) const;
00085     bool remove(Pvl &pvl) const;
00086 
00087     static bool exists(const QString &path, const Pvl &pvl, 
00088                        const PvlType &type = Keyword);
00089  
00090     static bool write(const QString &path, const QStringList &values, Pvl &pvl); 
00091     static bool remove(const QString &path, Pvl &pvl, 
00092                        const PvlType &ptype = Keyword);
00093     static bool create(const QString &path, PvlType &ptype, Pvl &pvl);
00094 #endif
00095 
00096   private:
00097     typedef QList<PvlSpecs> PvlElementList;
00098     QString         m_path;
00099     PvlElementList  m_pvlParts;
00100     bool            m_recursive;
00101 
00102     void init(const QString &path, const PvlType &type);
00103     QVariant find(Isis::PvlObject &pvl) const;
00104     QVariant findElement(const PvlElementList &plist, const QVariant &source) const;
00105     Isis::PvlKeyword *getKeyword(Isis::PvlContainer *pvl, const QString &name) const;
00106 
00107 
00108 };
00109 
00110 } // namespace ISISDLM
00111 
00112 // Add Pvl elements to QVariant type list
00113 Q_DECLARE_METATYPE(Isis::PvlKeyword *);
00114 Q_DECLARE_METATYPE(Isis::PvlContainer *);
00115 Q_DECLARE_METATYPE(Isis::PvlObject *);
00116 #endif