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