界面数据结构转换存储

#ifndef _SQDATACHECK_H_
#define _SQDATACHECK_H_
#include "./inc/sq24tdata.h"
#include "globals.h"
namespace storetype {

    inline tSQ24Project & operator<<(tSQ24Project &to, const SQ24PCR_PRO_Para &from) {
                to.code = -1;
                to.name = from.SQ24_pcrname.toStdString();//项目名称
                to.type = from.SQ24_pcrexpertype;//项目类型
                to.ulsy = from.SQ24_pcrreagevolume;//反应体系
                if(!from.SQ24_fluorpass.empty()){
                    to.tage = new vector<tSQ24Tagentia *>();
                    for(auto it : from.SQ24_fluorpass){
                        auto tage = new tSQ24Tagentia();
                        to.tage->push_back(tage);
                        tage->name = it.tubename.toStdString();
                    }
                }
                else {
                    to.tage = nullptr;
                }
                return to;

    }
    inline const SQ24PCR_PRO_Para & operator>>(const SQ24PCR_PRO_Para &from,tSQ24Project &to){
                 to << from;
                 return from;
    }
    inline SQ24PCR_PRO_Para & operator<<(SQ24PCR_PRO_Para &to, const tSQ24Project &from) {
                to.SQ24_pcrname = from.name.c_str();//项目名称
                to.SQ24_pcrexpertype = SQ24EXPERTYPE(from.type);//项目类型
                to.SQ24_pcrreagevolume = from.ulsy;//反应体系
                to.SQ24_fluorpass.clear();
                if(from.tage){
                    for(auto it : *from.tage){
                        SQ24PCR_TESTTARGET target;
                        target.tubename = it->name.c_str();
                        to.SQ24_fluorpass.push_back(target);
                    }
                }
                return to;
    }
    inline const tSQ24Project & operator>>(const tSQ24Project & from,  SQ24PCR_PRO_Para & to){
                 to << from;
                 return from;
    }
    template<class T>
    class SQDataCheck {
        T _t;
    public:
        SQDataCheck() {}
        template<typename D>SQDataCheck(const D& d) {operator = (d);}
        template<typename D>inline T & operator =(const D & d) {return operator()(d);}
        inline operator T() {return _t;}
        template<typename D>inline T & operator()(const D & d) {_t << d;return _t;}
    };
    class SQDataConvert{
            int _version;
            template<class T>
            class SQDataCheck{
                T * _t;
                SQDataConvert & _cvt;
                SQDataCheck(T * t, SQDataConvert & cvt) :_t(t), _cvt(cvt) {}
            public:
                friend SQDataConvert;
                template<typename D> inline SQDataCheck(const D& d) { operator = (d); }
                template<typename D> inline T & operator =(const D & d) { return operator()(d); }
                inline operator T() { return *_t; }
                template<typename D>
                inline T & operator()(const D & d) {
                    switch (_cvt.version()) {
                    case 0:
                        break;
                    case 1:
                    default:
                        *_t << d;
                        break;
                    }
                    return *_t;
                }
            };
        public:
            SQDataConvert(int v):_version(v){}
            int version() const { return _version; }
            template<typename T> SQDataCheck<T> operator()(T& d) {
                return SQDataCheck<T>(&d, *this);
            }
            template<typename T> SQDataCheck<T> operator[](T& d) {
                return SQDataCheck<T>(&d, *this);
            }
            template<typename T> SQDataCheck<T> operator()(T* d){
                return SQDataCheck<T>(d, *this);
            }
            template<typename T> SQDataCheck<T> operator[](T* d) {
                return SQDataCheck<T>(d, *this);
            }
        };
    #define CVT1 SQDataConvert(1)
    #define CVT2 SQDataConvert(2)
}

#endif

 

界面数据结构转换存储

上一篇:idea设置Error和Warning提示颜色修改,去掉屎黄色背景色


下一篇:编写最简单的字符设备驱动