Remote Call Framework 3.3
QCore.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2022, Delta V Software. All rights reserved.
6 // https://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF under GPL terms.
12 //
13 // Version: 3.3
14 // Contact: support <at> deltavsoft.com
15 //
16 //******************************************************************************
17 
18 #ifndef INCLUDE_SF_QCORE_HPP
19 #define INCLUDE_SF_QCORE_HPP
20 
21 #include <QByteArray>
22 #include <QDataStream>
23 #include <QDateTime>
24 #include <QPair>
25 #include <QUrl>
26 
27 #include <boost/config.hpp>
28 
29 #include <SF/Archive.hpp>
30 #include <SF/Stream.hpp>
31 
32 #include <SF/QByteArray.hpp>
33 #include <SF/QString.hpp>
34 #include <SF/QList.hpp>
35 #include <SF/QStringList.hpp>
36 #include <SF/QMap.hpp>
37 
38 
39 namespace SF {
40 
41  inline void serializeQDataStream(SF::Archive & ar, QDataStream & qds)
42  {
43  if (ar.isRead())
44  {
45  if (qds.device()->isWritable()) // QIODevice::WriteOnly
46  {
47  //qds.resetStatus();
48  QByteArray qba;
49  serializeQByteArray(ar, qba);
50  if (qba.size()) {
51  qds.writeRawData(qba.data(), qba.size());
52  }
53  }
54  }
55  else if (ar.isWrite())
56  {
57  QIODevice * dev = qds.device();
58  if (dev->isReadable()) // QIODevice::ReadOnly
59  {
60  std::uint32_t count = dev->bytesAvailable();
61  if (count == 0)
62  {
63  ar & count;
64  }
65  else
66  {
67  serializeQByteArray(ar, dev->readAll());
68  }
69  //while (1)
70  //{
71  // if (qds.atEnd()) break;
72  // std::uint32_t count = 0;
73  // char * buf = 0;
74  // qds.readBytes(buf, count);
75  // ar & count;
76  // if (buf && count) ar.getOstream()->writeRaw(buf, count);
77  // if (buf) delete[] buf;
78  //}
79  }
80  }
81  }
82 
83  // QDateTime
84  inline void serialize(SF::Archive & ar, QDateTime & qdt)
85  {
86  if (ar.isRead())
87  {
88  std::int64_t utc_time;
89  serializeFundamental(ar, utc_time);
90  qdt.setMSecsSinceEpoch(utc_time);
91  }
92  else if (ar.isWrite())
93  {
94  std::int64_t utc_time = qdt.toMSecsSinceEpoch();
95  serializeFundamental(ar, utc_time);
96  }
97  }
98 
99  // QPair
100  template<typename T, typename U>
101  inline void serialize_vc6(Archive &ar, QPair<T,U> &t, const unsigned int)
102  {
103  ar & t.first & t.second;
104  }
105 
106  // QUrl
107  inline void serialize(SF::Archive & ar, QUrl & qobj)
108  {
109  SERIALIZE_QT_OBJECT
110  }
111 
112 
113 } // namespace SF
114 
115 #endif // ! INCLUDE_SF_QCORE_HPP
Represents an archive, in which serialized objects are stored.
Definition: Archive.hpp:31
Definition: ByteBuffer.hpp:188
bool isWrite() const
Returns true if this archive is being written to.
bool isRead() const
Returns true if this archive is being read from.