GeopsyCore/MetaDataFactory.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of GeopsyCore.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created: 2010-05-03
00022 **  Authors:
00023 **    Marc Wathelet (LGIT, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef METADATAFACTORY_H
00028 #define METADATAFACTORY_H
00029 
00030 #include <QGpCoreTools.h>
00031 
00032 #include "MetaData.h"
00033 #include "MetaDataIndex.h"
00034 #include "GeopsyCoreDLLExport.h"
00035 
00036 namespace GeopsyCore {
00037 
00038   class MetaData;
00039 
00040 #define READONLY_STANDARD_METADATA \
00041     case MetaDataFactory::ID: \
00042     case MetaDataFactory::NSamples: \
00043     case MetaDataFactory::Type: \
00044     case MetaDataFactory::FileNumber: \
00045     case MetaDataFactory::NumberInFile: \
00046     case MetaDataFactory::FileName: \
00047     case MetaDataFactory::FileFormat: \
00048     case MetaDataFactory::MaximumAmplitude: \
00049     case MetaDataFactory::AverageAmplitude: \
00050     case MetaDataFactory::IsOriginalFile: \
00051     case MetaDataFactory::Pointer: \
00052     case MetaDataFactory::SampleSize: \
00053     case MetaDataFactory::CountPerUnit: \
00054     case MetaDataFactory::UnitPerCount: \
00055     case MetaDataFactory::HeaderModified: \
00056     case MetaDataFactory::ShortFileName: \
00057     case MetaDataFactory::SourceReceiverDistance: \
00058     case MetaDataFactory::SourceReceiverAzimuth: \
00059     case MetaDataFactory::SourceReceiverRoughAzimuth: \
00060     case MetaDataFactory::Dummy: \
00061     case MetaDataFactory::DataCount:
00062 
00063   #define REGISTER_METADATA(_className_, _tagName_) \
00064     XMLREGISTER_HEAD(MetaDataFactory, XMLClassCreator, _className_, _tagName_) \
00065     XMLREGISTER_TAIL(_className_)
00066 
00067   #define SYNONYM_METADATA(_synName_, _tagName_) \
00068     XMLSYNONYM(MetaDataFactory, _synName_, _tagName_)
00069 
00070   class GEOPSYCORE_EXPORT MetaDataFactory : public XMLClassFactory
00071   {
00072   public:
00073     enum StandardData {
00074       ID=0,
00075       T0,
00076       DeltaT,
00077       NSamples,
00078       ReceiverX,
00079       ReceiverY,
00080       ReceiverZ,
00081       SourceX,
00082       SourceY,
00083       SourceZ,
00084       Name,
00085       Type,
00086       FileNumber,
00087       NumberInFile,
00088       TimeReference,
00089       FileName,
00090       Duration,
00091       EndTime,
00092       Component,
00093       MaximumAmplitude,
00094       AverageAmplitude,
00095       IsOriginalFile,
00096       SamplingFrequency,
00097       Pointer,
00098       CountPerVolt,
00099       VoltPerCount,
00100       VoltPerUnit,
00101       UnitPerVolt,
00102       CountPerUnit,
00103       UnitPerCount,
00104       AmplitudeUnit,
00105       SampleSize,
00106       HeaderModified,
00107       SourceReceiverDistance,
00108       SourceReceiverAzimuth,
00109       SourceReceiverRoughAzimuth, // Used for sort criteria else same as Azimuth
00110       ShortFileName,
00111       FileFormat,
00112       Dummy,
00113       DataCount // This item should be the last standard one (= number of data)
00114     };
00115 
00116     MetaDataFactory();
00117 
00118     MetaDataIndex index(const QString& name) const;
00119     QString name(const MetaDataIndex& index) const;
00120     QString baseName(const MetaDataIndex& index) const;
00121     QString title(const MetaDataIndex& index) const;
00122     bool isReadOnly(const MetaDataIndex& index) const;
00123     bool isStored(const MetaDataIndex& index) const;
00124     int count(const MetaDataIndex& index) const;
00125 
00126     inline MetaData * create(int id) const;
00127     inline MetaData * create(const QString& tag) const;
00128 
00129     QList<MetaDataIndex> registeredData() const;
00130     QStringList registeredNames() const;
00131 
00132     static void init();
00133     static MetaDataFactory * instance() {init(); return _self;}
00134     int registerClass(const QString& tag, XMLClassCreator * creator);
00135 
00136     void registerScriptTypes(QScriptEngine * engine) const;
00137     void addScriptProperties(SignalHeaderObject * sig) const;
00138   private:
00139     static QString standardName(StandardData id);
00140 
00141     QMap<QString, MetaDataIndex> _names;
00142 
00143     static MetaDataFactory * _self;
00144   };
00145 
00146   inline MetaData * MetaDataFactory::create(int id) const
00147   {
00148     return  static_cast<MetaData *>(XMLClassFactory::create(id));
00149   }
00150 
00151   inline MetaData * MetaDataFactory::create(const QString& tag) const
00152   {
00153     return  static_cast<MetaData *>(XMLClassFactory::create(tag));
00154   }
00155 
00156 } // namespace GeopsyCore
00157 
00158 #endif // METADATAFACTORY_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines