[go: up one dir, main page]

File: blob.cpp

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 (94 lines) | stat: -rw-r--r-- 1,963 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
86
87
88
89
90
91
92
93
94
//
// 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)
//

#define SOCI_SOURCE
#include "soci/blob.h"
#include "soci/session.h"
#include "soci/soci-platform.h"

#include <cstddef>

using namespace soci;

blob::blob(session & s)
{
    initialize(s);
}

blob::~blob() = default;

bool blob::is_valid() const
{
    return static_cast<bool>(backEnd_);
}

void blob::initialize(session &session)
{
    initialize(session.make_blob_backend());
}

void blob::initialize(details::blob_backend *backend)
{
    backEnd_.reset(backend);
}

std::size_t blob::get_len()
{
    ensure_initialized();
    return backEnd_->get_len();
}

std::size_t blob::read(std::size_t offset, void *buf, std::size_t toRead)
{
    ensure_initialized();
    SOCI_ALLOW_DEPRECATED_BEGIN
    return backEnd_->read(offset, buf, toRead);
    SOCI_ALLOW_DEPRECATED_END
}

std::size_t blob::read_from_start(void * buf, std::size_t toRead,
    std::size_t offset)
{
    ensure_initialized();
    return backEnd_->read_from_start(buf, toRead, offset);
}

std::size_t blob::write(
    std::size_t offset, const void * buf, std::size_t toWrite)
{
    ensure_initialized();
    SOCI_ALLOW_DEPRECATED_BEGIN
    return backEnd_->write(offset, buf, toWrite);
    SOCI_ALLOW_DEPRECATED_END
}

std::size_t blob::write_from_start(const void * buf, std::size_t toWrite,
    std::size_t offset)
{
    ensure_initialized();
    return backEnd_->write_from_start(buf, toWrite, offset);
}

std::size_t blob::append(const void * buf, std::size_t toWrite)
{
    ensure_initialized();
    return backEnd_->append(buf, toWrite);
}

void blob::trim(std::size_t newLen)
{
    ensure_initialized();
    backEnd_->trim(newLen);
}

void blob::ensure_initialized()
{
    if (!is_valid())
    {
        throw soci_error("Attempted to access invalid blob");
    }
}