[go: up one dir, main page]

File: blob.h

package info (click to toggle)
soci 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,944 kB
  • sloc: ansic: 169,887; cpp: 54,198; javascript: 12,258; ada: 1,973; sh: 36; makefile: 12; xml: 2
file content (85 lines) | stat: -rw-r--r-- 2,122 bytes parent folder | download
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
//
// Copyright (C) 2004-2008 Maciej Sobczak, Stephen Hutton
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
//

#ifndef SOCI_BLOB_H_INCLUDED
#define SOCI_BLOB_H_INCLUDED

#include "soci/soci-platform.h"
// std
#include <cstddef>
#include <memory>

namespace soci
{
// basic blob operations

class session;

namespace details
{
class blob_backend;
} // namespace details

class SOCI_DECL blob
{
public:
    // Creates an invalid blob object
    blob() = default;
    explicit blob(session & s);
    ~blob();

    blob(blob &&other) = default;
    blob &operator=(blob &&other) = default;

    // Checks whether this blob is in a valid state
    bool is_valid() const;

    // (Re)initializes this blob
    void initialize(session &s);
    void initialize(details::blob_backend *backend);

    std::size_t get_len();

    // offset is backend-specific
    [[deprecated("Use read_from_start instead")]]
    std::size_t read(std::size_t offset, void * buf, std::size_t toRead);

    // Extracts data from this blob into the given buffer.
    // At most toRead bytes are extracted (and copied into buf).
    // The amount of actually read bytes is returned.
    //
    // Note: Using an offset > 0 on a blob whose size is less than
    // or equal to offset, will throw an exception.
    std::size_t read_from_start(void * buf, std::size_t toRead,
        std::size_t offset = 0);

    // offset is backend-specific
    [[deprecated("Use write_from_start instead")]]
    std::size_t write(std::size_t offset, const void * buf,
        std::size_t toWrite);

    // offset starts from 0
    std::size_t write_from_start(const void * buf, std::size_t toWrite,
        std::size_t offset = 0);

    std::size_t append(const void * buf, std::size_t toWrite);

    void trim(std::size_t newLen);

    details::blob_backend * get_backend() { return backEnd_.get(); }

private:
    SOCI_NOT_COPYABLE(blob)

    std::unique_ptr<details::blob_backend> backEnd_;

    void ensure_initialized();
};

} // namespace soci

#endif