ArnLib  4.0.x
Active Registry Network
ArnBasicItem.hpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2022 Michael Wiklund.
2 // All rights reserved.
3 // Contact: arnlib@wiklunden.se
4 //
5 // This file is part of the ArnLib - Active Registry Network.
6 // Parts of ArnLib depend on Qt and/or other libraries that have their own
7 // licenses. Usage of these other libraries is subject to their respective
8 // license agreements.
9 //
10 // GNU Lesser General Public License Usage
11 // This file may be used under the terms of the GNU Lesser General Public
12 // License version 2.1 as published by the Free Software Foundation and
13 // appearing in the file LICENSE_LGPL.txt included in the packaging of this
14 // file. In addition, as a special exception, you may use the rights described
15 // in the Nokia Qt LGPL Exception version 1.1, included in the file
16 // LGPL_EXCEPTION.txt in this package.
17 //
18 // GNU General Public License Usage
19 // Alternatively, this file may be used under the terms of the GNU General Public
20 // License version 3.0 as published by the Free Software Foundation and appearing
21 // in the file LICENSE_GPL.txt included in the packaging of this file.
22 //
23 // Other Usage
24 // Alternatively, this file may be used in accordance with the terms and conditions
25 // contained in a signed written agreement between you and Michael Wiklund.
26 //
27 // This program is distributed in the hope that it will be useful, but WITHOUT ANY
28 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
29 // PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
30 //
31 
32 #ifndef ARNBASICITEM_HPP
33 #define ARNBASICITEM_HPP
34 
35 #include "ArnLib_global.hpp"
36 #include "ArnCoreItem.hpp"
37 #include "ArnLinkHandle.hpp"
38 #include "ArnError.hpp"
39 #include "Arn.hpp"
40 #include "MQFlags.hpp"
41 #include <QString>
42 #include <QByteArray>
43 #include <QVariant>
44 #include <QAtomicInt>
45 #include <QObject>
46 
47 class ArnBasicItemPrivate;
48 class ArnLink;
49 class ArnEvent;
50 
51 
53 class ArnBasicItemEventHandler : public QObject
54 {
55  Q_OBJECT
56 
57 public:
58  explicit ArnBasicItemEventHandler( QObject* parent = 0);
59  virtual ~ArnBasicItemEventHandler();
60 
61  static void defaultEvent( QEvent* ev);
62 
63 protected:
64  virtual void customEvent( QEvent* ev);
65 };
67 
68 
70 
121 {
122  Q_DECLARE_PRIVATE(ArnBasicItem)
123  friend class ArnBasicItemEventHandler;
124 
125 public:
127 
129  ArnBasicItem();
130 
131  virtual ~ArnBasicItem();
132 
134 
137  bool open( const QString& path);
138 
140  void close();
141 
143 
149  void destroyLink( bool isGlobal = true);
150 
152 
156  void destroyLinkLocal()
157  { destroyLink( false);}
158 
160 
162  bool isOpen() const;
163 
165 
168  QString path( Arn::NameF nameF = Arn::NameF::EmptyOk) const;
169 
171 
174  QString name( Arn::NameF nameF) const;
175 
177 
184  void setReference( void* reference);
185 
187 
190  void* reference() const;
191 
193 
198  uint itemId() const;
199 
201 
207  uint linkId() const;
208 
210 
212  int refCount() const;
213 
216  bool isFolder() const;
217 
222  bool isProvider() const;
223 
225 
227  Arn::DataType type() const;
228 
230 
232  void setIgnoreSameValue( bool isIgnore = true);
233 
237  bool isIgnoreSameValue() const;
238 
240 
248  void addMode( Arn::ObjectMode mode);
249 
254  Arn::ObjectMode getMode() const;
255 
259  Arn::ObjectSyncMode syncMode() const;
260 
262 
266  ArnBasicItem& setBiDirMode();
267 
273  bool isBiDirMode() const;
274 
276 
280  ArnBasicItem& setPipeMode();
281 
287  bool isPipeMode() const;
288 
290 
295  ArnBasicItem& setSaveMode();
296 
302  bool isSaveMode() const;
303 
305 
307  void setAtomicOpProvider();
308 
312  bool isAtomicOpProvider() const;
313 
315 
319  ArnBasicItem& setMaster();
320 
325  bool isMaster() const;
326 
328 
331  ArnBasicItem& setAutoDestroy();
332 
336  bool isAutoDestroy() const;
337 
339 
346  void arnImport( const QByteArray& data, int ignoreSame = Arn::SameValue::DefaultAction);
347 
351  QByteArray arnExport() const;
352 
357  int toInt( bool* isOk = arnNullptr) const;
358 
363  double toDouble( bool* isOk = arnNullptr) const;
364 
369  ARNREAL toReal( bool* isOk = arnNullptr) const;
370 
375  QString toString( bool* isOk = arnNullptr) const;
376 
381  QByteArray toByteArray( bool* isOk = arnNullptr) const;
382 
387  QVariant toVariant( bool* isOk = arnNullptr) const;
388 
394  bool toBool( bool* isOk = arnNullptr) const;
395 
401  uint toUInt( bool* isOk = arnNullptr) const;
402 
408  qint64 toInt64( bool* isOk = arnNullptr) const;
409 
415  quint64 toUInt64( bool* isOk = arnNullptr) const;
416 
417  ArnBasicItem& operator=( const ArnBasicItem& other);
418  ArnBasicItem& operator=( int val);
419  ArnBasicItem& operator=( ARNREAL val);
420  ArnBasicItem& operator=( const QString& val);
421  ArnBasicItem& operator=( const QByteArray& val);
422  ArnBasicItem& operator=( const QVariant& val);
423  ArnBasicItem& operator=( const char* val);
424  ArnBasicItem& operator=( uint val);
425  ArnBasicItem& operator=( qint64 val);
426  ArnBasicItem& operator=( quint64 val);
427 
428  ArnBasicItem& operator+=( int val);
429  ArnBasicItem& operator+=( ARNREAL val);
430 
431  void setValue( const ArnBasicItem& other, int ignoreSame = Arn::SameValue::DefaultAction);
432 
434 
438  void setValue( int value, int ignoreSame = Arn::SameValue::DefaultAction);
439 
441 
445  void setValue( ARNREAL value, int ignoreSame = Arn::SameValue::DefaultAction);
446 
448 
452  void setValue( bool value, int ignoreSame = Arn::SameValue::DefaultAction);
453 
455 
459  void setValue( const QString& value, int ignoreSame = Arn::SameValue::DefaultAction);
460 
462 
466  void setValue( const QByteArray& value, int ignoreSame = Arn::SameValue::DefaultAction);
467 
469 
473  void setValue( const QVariant& value, int ignoreSame = Arn::SameValue::DefaultAction);
474 
476 
480  void setValue( const char* value, int ignoreSame = Arn::SameValue::DefaultAction);
481 
483 
488  void setValue( uint value, int ignoreSame = Arn::SameValue::DefaultAction);
489 
491 
496  void setValue( qint64 value, int ignoreSame = Arn::SameValue::DefaultAction);
497 
499 
504  void setValue( quint64 value, int ignoreSame = Arn::SameValue::DefaultAction);
505 
507 
515  void setBits( int mask, int value, int ignoreSame = Arn::SameValue::DefaultAction);
516 
518 
523  void addValue( int value);
524 
526 
531  void addValue( ARNREAL value);
532 
534 
540  QThread* thread() const;
541 
543 
548  void setEventHandler( QObject* eventHandler);
549 
551 
555  QObject* eventHandler() const;
556 
558 
565  void setUncrossed( bool isUncrossed = true);
566 
568 
574  bool isUncrossed() const;
575 
577 
580  bool isAssigning() const;
581 
583  bool sendArnEventLink( ArnEvent* ev);
584  void sendArnEventItem( ArnEvent* ev, bool isAlienThread, bool isLocked = false);
585  quint32 localUpdateCount() const;
586 
587 protected:
588  virtual void arnEvent( QEvent* ev, bool isAlienThread);
589 
591  bool openWithFlags( const QString& path, Arn::LinkFlags linkFlags);
594  void setForceKeep( bool fk = true);
597  bool isForceKeep() const;
598  Arn::ObjectMode getMode( ArnLink* link) const;
599  void addSyncMode( Arn::ObjectSyncMode syncMode, bool linkShare);
600  void resetOnlyEcho();
601  void addIsOnlyEcho( quint32 sendId);
602  bool isOnlyEcho() const;
603  uint retireType();
604  void setValue( const QByteArray& value, int ignoreSame, ArnLinkHandle& handleData);
605  void setValue( const QVariant& value, int ignoreSame, ArnLinkHandle& handleData);
606  void arnImport( const QByteArray& data, int ignoreSame, ArnLinkHandle& handleData);
607  QStringList childItemsMain() const;
608  void errorLog( const QString& errText, ArnError err = ArnError::Undef, void* reference = arnNullptr) const;
609 
610  ArnBasicItem( ArnBasicItemPrivate& dd);
612 
613 private:
614  void init();
615  void setupOpenItem( bool isFolder);
616  ArnBasicItemEventHandler* getThreadEventHandler();
617 
618  ArnLink* _link;
619 };
620 
621 #endif // ARNBASICITEM_HPP
Data type of an Arn Data Object
Definition: Arn.hpp:74
Path: "/@/test" ==> "//test", Item: "@" ==> "".
Definition: Arn.hpp:189
Core base class for the inherited ArnItem classes.
Definition: ArnCoreItem.hpp:56
Assigning same value gives default action set in ArnM or ArnItem.
Definition: Arn.hpp:68
QThread * thread() const
Get the thread affinity of this ArnCoreItem.
Definition: ArnCoreItem.cpp:69
#define ARNREAL
Definition: Arn.hpp:44
#define ARNLIBSHARED_EXPORT
Base class handle for an Arn Data Object.