Ilwis-Objects  1.0
GIS and Remote Sensing framework for data access and processing
 All Classes Functions Enumerations Pages
ilwisobject.h
1 #ifndef ILWISOBJECTIMPL_H
2 #define ILWISOBJECTIMPL_H
3 
4 #include <QSharedData>
5 #include <QDateTime>
6 #include <QUrl>
7 #include <QDebug>
8 #include "Kernel_global.h"
9 #include "locker.h"
10 #include "identity.h"
11 #include "resource.h"
12 #include "numericrange.h"
13 #include "juliantime.h"
14 #include "prepareoptions.h"
15 
16 
17 class QSqlRecord;
18 
19 namespace Ilwis {
20 
21 class IlwisObjectFactory;
22 class ConnectorInterface;
23 class Resource;
24 class IlwisObject;
25 struct PrepareOptions;
26 
27 typedef IlwisTypes (*IlwisTypeFunction)(const QString& resource);
28 
96 class KERNELSHARED_EXPORT IlwisObject : public QObject, public Identity
97 {
98  Q_OBJECT
99 
100  friend class IlwisObjectFactory; // needs to set validity of object
101  friend void addFactory(IlwisObjectFactory *);
102 
103 public:
109  enum ConnectorMode{cmINPUT=1, cmOUTPUT=2, cmEXTENDED=4};
110 
114  enum StoreMode{smMETADATA=1, smBINARYDATA=2};
115 
119  IlwisObject();
120 
128  IlwisObject(const Resource &source);
129 
130  virtual ~IlwisObject();
131 
136  virtual bool prepare();
137 
144  void setName(const QString& nm);
145 
152  void setCode(const QString &cd);
153 
159  QDateTime modifiedTime() const;
160 
161 
167  void setModifiedTime(const Time& time);
168 
174  Time createTime() const;
175 
181  void setCreateTime(const Time& time);
182 
188  virtual QString toString();
189 
200  virtual void setConnector(ConnectorInterface *connector, int mode=cmINPUT | cmOUTPUT);
201 
209  virtual bool isEqual(const Ilwis::IlwisObject *obj) const;
210 
217  virtual bool isValid() const;
218 
225  virtual bool isReadOnly() const;
226 
232  virtual void setReadOnly(bool yesno);
233 
238  virtual bool hasChanged() const;
239 
245  virtual void changed(bool yesno) ;
246 
252  virtual IlwisTypes ilwisType() const = 0;
253 
260  virtual bool prepare(const QString& def);
261 
269  bool fromInternal(const QSqlRecord& rec);
270 
276  bool isAnonymous() const;
277 
282  virtual Resource source(int mode=cmINPUT) const;
283 
288  virtual bool store(int mode=smMETADATA | smBINARYDATA);
289 
297  void connectTo(const QUrl &url, const QString &format, const QString &fnamespace, ConnectorMode cmode);
298 
299 
300  //TODO. Puzzeld, this method is not allowed as duplicate copies are illegal
301  virtual IlwisObject *clone() ;
302 
310  virtual bool merge(const IlwisObject* obj, int options=0);
311  bool isSystemObject() const;
312  bool isInternalObject() const;
313 
314  template<typename T> static T create(const QString& def){
315  T object;
316  object.prepare(def);
317  return object;
318  }
319 
320  template<typename T> static T create(quint64 id){
321  T object;
322  object.prepare(id);
323  return object;
324  }
325 
333  static IlwisObject *create(const Resource& source,const PrepareOptions& options=PrepareOptions());
334 
341  static IlwisTypes findType(const QString &source);
342 
350  static QString type2Name(IlwisTypes t);
351 
359  static IlwisTypes name2Type(const QString &name);
360 
365  static void addTypeFunction(IlwisTypeFunction);
366 
367  static IlwisTypes name2ExtendedType(const QString &dname);
368 
369 protected:
370  QScopedPointer<ConnectorInterface>& connector(int mode=cmINPUT | cmOUTPUT);
371  const QScopedPointer<ConnectorInterface> &connector(int mode=cmINPUT | cmOUTPUT) const;
372  bool setValid(bool yesno);
373  void copyTo(IlwisObject *obj);
374 
375  std::mutex _mutex;
376  std::mutex _loadforstore;
377 private:
378 
379  bool _valid;
380  bool _readOnly;
381  bool _changed;
382  Time _modifiedTime;
383  Time _createTime;
384  QScopedPointer<Ilwis::ConnectorInterface> _connector;
385  QScopedPointer<Ilwis::ConnectorInterface> _outConnector;
386  static QVector<IlwisTypeFunction> _typeFunctions;
387 
388 
389 };
390 
391 
392 }
393 
394 bool operator==(const Ilwis::IlwisObject& obj1, const Ilwis::IlwisObject& obj2);
395 #define IVARIANT(o) qVariantFromValue(o)
396 
397 
398 
399 
400 #endif // ILWISOBJECTIMPL_H