LCOV - code coverage report
Current view: top level - core/serialization - qtTypes.h (source / functions) Hit Total Coverage
Test: Tide Lines: 18 54 33.3 %
Date: 2017-09-13 06:27:51 Functions: 12 22 54.5 %

          Line data    Source code
       1             : /*********************************************************************/
       2             : /* Copyright (c) 2013-2016, EPFL/Blue Brain Project                  */
       3             : /*                     Raphael Dumusc <raphael.dumusc@epfl.ch>       */
       4             : /*                     Daniel Nachbaur <daniel.nachbaur@epfl.ch>     */
       5             : /* All rights reserved.                                              */
       6             : /*                                                                   */
       7             : /* Redistribution and use in source and binary forms, with or        */
       8             : /* without modification, are permitted provided that the following   */
       9             : /* conditions are met:                                               */
      10             : /*                                                                   */
      11             : /*   1. Redistributions of source code must retain the above         */
      12             : /*      copyright notice, this list of conditions and the following  */
      13             : /*      disclaimer.                                                  */
      14             : /*                                                                   */
      15             : /*   2. Redistributions in binary form must reproduce the above      */
      16             : /*      copyright notice, this list of conditions and the following  */
      17             : /*      disclaimer in the documentation and/or other materials       */
      18             : /*      provided with the distribution.                              */
      19             : /*                                                                   */
      20             : /*    THIS  SOFTWARE IS PROVIDED  BY THE  UNIVERSITY OF  TEXAS AT    */
      21             : /*    AUSTIN  ``AS IS''  AND ANY  EXPRESS OR  IMPLIED WARRANTIES,    */
      22             : /*    INCLUDING, BUT  NOT LIMITED  TO, THE IMPLIED  WARRANTIES OF    */
      23             : /*    MERCHANTABILITY  AND FITNESS FOR  A PARTICULAR  PURPOSE ARE    */
      24             : /*    DISCLAIMED.  IN  NO EVENT SHALL THE UNIVERSITY  OF TEXAS AT    */
      25             : /*    AUSTIN OR CONTRIBUTORS BE  LIABLE FOR ANY DIRECT, INDIRECT,    */
      26             : /*    INCIDENTAL,  SPECIAL, EXEMPLARY,  OR  CONSEQUENTIAL DAMAGES    */
      27             : /*    (INCLUDING, BUT  NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE    */
      28             : /*    GOODS  OR  SERVICES; LOSS  OF  USE,  DATA,  OR PROFITS;  OR    */
      29             : /*    BUSINESS INTERRUPTION) HOWEVER CAUSED  AND ON ANY THEORY OF    */
      30             : /*    LIABILITY, WHETHER  IN CONTRACT, STRICT  LIABILITY, OR TORT    */
      31             : /*    (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY OUT    */
      32             : /*    OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF ADVISED  OF  THE    */
      33             : /*    POSSIBILITY OF SUCH DAMAGE.                                    */
      34             : /*                                                                   */
      35             : /* The views and conclusions contained in the software and           */
      36             : /* documentation are those of the authors and should not be          */
      37             : /* interpreted as representing official policies, either expressed   */
      38             : /* or implied, of Ecole polytechnique federale de Lausanne.          */
      39             : /*********************************************************************/
      40             : 
      41             : #ifndef SERIALIZATION_QTTYPES_H
      42             : #define SERIALIZATION_QTTYPES_H
      43             : 
      44             : #include <QColor>
      45             : #include <QImage>
      46             : #include <QRectF>
      47             : #include <QString>
      48             : #include <QUuid>
      49             : 
      50             : #include <boost/serialization/array.hpp>
      51             : #include <boost/serialization/nvp.hpp>
      52             : #include <boost/serialization/split_free.hpp>
      53             : 
      54             : namespace boost
      55             : {
      56             : namespace serialization
      57             : {
      58             : template <class Archive>
      59           0 : void serialize(Archive& ar, QColor& color, const unsigned int)
      60             : {
      61             :     // clang-format off
      62             :     unsigned char t;
      63           0 :     t = color.red(); ar & t; color.setRed(t);
      64           0 :     t = color.green(); ar & t; color.setGreen(t);
      65           0 :     t = color.blue(); ar & t; color.setBlue(t);
      66           0 :     t = color.alpha(); ar & t; color.setAlpha(t);
      67             :     // clang-format on
      68           0 : }
      69             : 
      70             : template <class Archive>
      71          30 : void save(Archive& ar, const QString& s, const unsigned int)
      72             : {
      73          60 :     std::string stdStr = s.toStdString();
      74          30 :     ar << make_nvp("value", stdStr);
      75          30 : }
      76             : 
      77             : template <class Archive>
      78          31 : void load(Archive& ar, QString& s, const unsigned int)
      79             : {
      80          62 :     std::string stdStr;
      81          31 :     ar >> make_nvp("value", stdStr);
      82          31 :     s = QString::fromStdString(stdStr);
      83          31 : }
      84             : 
      85             : template <class Archive>
      86          61 : void serialize(Archive& ar, QString& s, const unsigned int version)
      87             : {
      88          61 :     split_free(ar, s, version);
      89          61 : }
      90             : 
      91             : template <class Archive>
      92           0 : void serialize(Archive& ar, QUuid& uuid, const unsigned int /*version*/)
      93             : {
      94             :     // clang-format off
      95           0 :     ar & make_nvp("data1", uuid.data1);
      96           0 :     ar & make_nvp("data2", uuid.data2);
      97           0 :     ar & make_nvp("data3", uuid.data3);
      98           0 :     ar & make_nvp("data40", uuid.data4[0]);
      99           0 :     ar & make_nvp("data41", uuid.data4[1]);
     100           0 :     ar & make_nvp("data42", uuid.data4[2]);
     101           0 :     ar & make_nvp("data43", uuid.data4[3]);
     102           0 :     ar & make_nvp("data44", uuid.data4[4]);
     103           0 :     ar & make_nvp("data45", uuid.data4[5]);
     104           0 :     ar & make_nvp("data46", uuid.data4[6]);
     105           0 :     ar & make_nvp("data47", uuid.data4[7]);
     106             :     // clang-format on
     107           0 : }
     108             : 
     109             : template <class Archive>
     110           0 : void serialize(Archive& ar, QPointF& point, const unsigned int)
     111             : {
     112             :     // clang-format off
     113           0 :     ar & make_nvp("x", point.rx());
     114           0 :     ar & make_nvp("y", point.ry());
     115             :     // clang-format on
     116           0 : }
     117             : 
     118             : template <class Archive>
     119           0 : void serialize(Archive& ar, QSize& size, const unsigned int)
     120             : {
     121             :     // clang-format off
     122           0 :     ar & make_nvp("w", size.rwidth());
     123           0 :     ar & make_nvp("h", size.rheight());
     124             :     // clang-format on
     125           0 : }
     126             : 
     127             : template <class Archive>
     128          54 : void serialize(Archive& ar, QRectF& rect, const unsigned int)
     129             : {
     130             :     qreal t;
     131             :     // clang-format off
     132          54 :     t = rect.x(); ar & make_nvp("x", t); rect.setX(t);
     133          54 :     t = rect.y(); ar & make_nvp("y", t); rect.setY(t);
     134          54 :     t = rect.width(); ar & make_nvp("w", t); rect.setWidth(t);
     135          54 :     t = rect.height(); ar & make_nvp("h", t); rect.setHeight(t);
     136             :     // clang-format on
     137          54 : }
     138             : 
     139             : template <class Archive>
     140           0 : void serialize(Archive& ar, QImage& image, const unsigned int)
     141             : {
     142             :     // clang-format off
     143           0 :     auto size = image.size();
     144           0 :     ar & make_nvp("size", size);
     145             : 
     146           0 :     auto format = image.format();
     147           0 :     ar & make_nvp("format", format);
     148             : 
     149             :     if (Archive::is_loading::value)
     150           0 :         image = QImage{size, format};
     151             : 
     152           0 :     const size_t count = image.width() * image.height() * 4;
     153           0 :     ar & make_nvp("data", make_array(image.bits(), count));
     154             :     // clang-format on
     155           0 : }
     156             : }
     157             : }
     158             : 
     159             : #endif

Generated by: LCOV version 1.11