aboutsummaryrefslogtreecommitdiff
path: root/src/stable/archive.h
blob: 2cd340c77eb71e6fc12333107d71cbe21e22f8ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright (C) 2007-2019 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#ifndef BU_ARCHIVE_BASE_H
#define BU_ARCHIVE_BASE_H

#include <stdint.h>
#include <unistd.h>

#include "bu/variant.h"
#include "bu/blob.h"

namespace Bu
{
    class Text;

    class Archive
    {
    public:
        Archive();
        virtual ~Archive();
        
        enum
        {
            load    =   true,
            save    =   false
        };
        
        virtual void close()=0;
//        virtual void write( const void *pData, size_t iLength )=0;
//        virtual void read( void *pData, size_t iLength )=0;
        virtual bool isLoading()=0;

        virtual void write(                 bool        rData )=0;
        virtual void write(       unsigned  char        rData )=0;
        virtual void write(                 char        rData )=0;
        virtual void write(       signed    char        rData )=0;
        virtual void write(       unsigned  short       rData )=0;
        virtual void write(       signed    short       rData )=0;
        virtual void write(       unsigned  int         rData )=0;
        virtual void write(       signed    int         rData )=0;
        virtual void write(       unsigned  long        rData )=0;
        virtual void write(       signed    long        rData )=0;
        virtual void write(       unsigned  long long   rData )=0;
        virtual void write(       signed    long long   rData )=0;
        virtual void write(                 float       rData )=0;
        virtual void write(                 double      rData )=0;
        virtual void write(                 long double rData )=0;
        virtual void write( const           Bu::Blob    &rData )=0;
        virtual void write( const           Bu::Text    &rData )=0;
        
        virtual void read(           bool        &rData )=0;
        virtual void read( unsigned  char        &rData )=0;
        virtual void read(           char        &rData )=0;
        virtual void read( signed    char        &rData )=0;
        virtual void read( unsigned  short       &rData )=0;
        virtual void read( signed    short       &rData )=0;
        virtual void read( unsigned  int         &rData )=0;
        virtual void read( signed    int         &rData )=0;
        virtual void read( unsigned  long        &rData )=0;
        virtual void read( signed    long        &rData )=0;
        virtual void read( unsigned  long long   &rData )=0;
        virtual void read( signed    long long   &rData )=0;
        virtual void read(           float       &rData )=0;
        virtual void read(           double      &rData )=0;
        virtual void read(           long double &rData )=0;
        virtual void read(           Bu::Blob    &rData )=0;
        virtual void read(           Bu::Text    &rData )=0;

        virtual void setProperty( const Bu::Blob &rKey,
                const Bu::Variant &rValue )=0;
        virtual Bu::Variant getProperty( const Bu::Blob &rKey ) const=0;
    };

    template<typename T> Archive &operator&&( Archive &ar, T &dat )
    {
        if( ar.isLoading() )
        {
            return ar >> dat;
        }
        else
        {
            return ar << dat;
        }
    }

    Archive &operator<<( Archive &ar, bool p );
    Archive &operator<<( Archive &ar, char p );
    Archive &operator<<( Archive &ar, signed char p );
    Archive &operator<<( Archive &ar, unsigned char p );
    Archive &operator<<( Archive &ar, signed short p );
    Archive &operator<<( Archive &ar, unsigned short p );
    Archive &operator<<( Archive &ar, signed int p );
    Archive &operator<<( Archive &ar, unsigned int p );
    Archive &operator<<( Archive &ar, signed long p );
    Archive &operator<<( Archive &ar, unsigned long p );
    Archive &operator<<( Archive &ar, signed long long p );
    Archive &operator<<( Archive &ar, unsigned long long p );
    Archive &operator<<( Archive &ar, float p );
    Archive &operator<<( Archive &ar, double p );
    Archive &operator<<( Archive &ar, long double p );
    Archive &operator<<( Archive &ar, const Bu::Blob &p );
    Archive &operator<<( Archive &ar, const Bu::Text &p );
    
    Archive &operator>>( Archive &ar, bool &p );
    Archive &operator>>( Archive &ar, char &p );
    Archive &operator>>( Archive &ar, signed char &p );
    Archive &operator>>( Archive &ar, unsigned char &p );
    Archive &operator>>( Archive &ar, signed short &p );
    Archive &operator>>( Archive &ar, unsigned short &p );
    Archive &operator>>( Archive &ar, signed int &p );
    Archive &operator>>( Archive &ar, unsigned int &p );
    Archive &operator>>( Archive &ar, signed long &p );
    Archive &operator>>( Archive &ar, unsigned long &p );
    Archive &operator>>( Archive &ar, signed long long &p );
    Archive &operator>>( Archive &ar, unsigned long long &p );
    Archive &operator>>( Archive &ar, float &p );
    Archive &operator>>( Archive &ar, double &p );
    Archive &operator>>( Archive &ar, long double &p );
    Archive &operator>>( Archive &ar, Bu::Blob &p );
    Archive &operator>>( Archive &ar, Bu::Text &p );
};

#endif