~ubuntu-branches/ubuntu/gutsy/soprano/gutsy

« back to all changes in this revision

Viewing changes to server/clientqueryresultiteratorbackend.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-10-12 14:43:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071012144348-yajzi51v4k23ahxf
Tags: 1.95.0~beta2-1ubuntu1
* Sync with Debian
* Add versioned build-dep on raptor

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of Soprano Project.
 
3
 *
 
4
 * Copyright (C) 2007 Sebastian Trueg <trueg@kde.org>
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Library General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Library General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Library General Public License
 
17
 * along with this library; see the file COPYING.LIB.  If not, write to
 
18
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
19
 * Boston, MA 02110-1301, USA.
 
20
 */
 
21
 
 
22
#include "clientqueryresultiteratorbackend.h"
 
23
#include "clientconnection.h"
 
24
#include "clientmodel.h"
 
25
 
 
26
#include <soprano/bindingset.h>
 
27
#include <soprano/statement.h>
 
28
 
 
29
 
 
30
Soprano::Client::ClientQueryResultIteratorBackend::ClientQueryResultIteratorBackend( int itId, ClientModel* client )
 
31
    : m_iteratorId( itId ),
 
32
      m_model( client )
 
33
{
 
34
}
 
35
 
 
36
 
 
37
Soprano::Client::ClientQueryResultIteratorBackend::~ClientQueryResultIteratorBackend()
 
38
{
 
39
    close();
 
40
}
 
41
 
 
42
 
 
43
bool Soprano::Client::ClientQueryResultIteratorBackend::next()
 
44
{
 
45
    if ( m_model ) {
 
46
        bool r = m_model->client()->iteratorNext( m_iteratorId );
 
47
        setError( m_model->client()->lastError() );
 
48
        return r;
 
49
    }
 
50
    else {
 
51
        setError( "Connection to server closed." );
 
52
        return false;
 
53
    }
 
54
}
 
55
 
 
56
 
 
57
Soprano::BindingSet Soprano::Client::ClientQueryResultIteratorBackend::current() const
 
58
{
 
59
    if ( m_model ) {
 
60
        BindingSet s = m_model->client()->queryIteratorCurrent( m_iteratorId );
 
61
        setError( m_model->client()->lastError() );
 
62
        return s;
 
63
    }
 
64
    else {
 
65
        setError( "Connection to server closed." );
 
66
        return BindingSet();
 
67
    }
 
68
}
 
69
 
 
70
 
 
71
void Soprano::Client::ClientQueryResultIteratorBackend::close()
 
72
{
 
73
    if ( m_model ) {
 
74
        m_model->closeIterator( m_iteratorId );
 
75
        setError( m_model->client()->lastError() );
 
76
    }
 
77
    else {
 
78
        setError( "Connection to server closed." );
 
79
    }
 
80
}
 
81
 
 
82
 
 
83
Soprano::Statement Soprano::Client::ClientQueryResultIteratorBackend::currentStatement() const
 
84
{
 
85
    if ( m_model ) {
 
86
        Statement s = m_model->client()->queryIteratorCurrentStatement( m_iteratorId );
 
87
        setError( m_model->client()->lastError() );
 
88
        return s;
 
89
    }
 
90
    else {
 
91
        setError( "Connection to server closed." );
 
92
        return Statement();
 
93
    }
 
94
}
 
95
 
 
96
 
 
97
Soprano::Node Soprano::Client::ClientQueryResultIteratorBackend::binding( const QString &name ) const
 
98
{
 
99
    // FIXME: use an extra method for performance
 
100
    return current()[name];
 
101
}
 
102
 
 
103
 
 
104
Soprano::Node Soprano::Client::ClientQueryResultIteratorBackend::binding( int offset ) const
 
105
{
 
106
    // FIXME: use an extra method for performance
 
107
    return current()[offset];
 
108
}
 
109
 
 
110
 
 
111
int Soprano::Client::ClientQueryResultIteratorBackend::bindingCount() const
 
112
{
 
113
    // FIXME: use an extra method for performance
 
114
    return current().count();
 
115
}
 
116
 
 
117
 
 
118
QStringList Soprano::Client::ClientQueryResultIteratorBackend::bindingNames() const
 
119
{
 
120
    // FIXME: use an extra method for performance
 
121
    return current().bindingNames();
 
122
}
 
123
 
 
124
 
 
125
bool Soprano::Client::ClientQueryResultIteratorBackend::isGraph() const
 
126
{
 
127
    if ( m_model ) {
 
128
        bool r = m_model->client()->queryIteratorType( m_iteratorId ) == 1;
 
129
        setError( m_model->client()->lastError() );
 
130
        return r;
 
131
    }
 
132
    else {
 
133
        setError( "Connection to server closed." );
 
134
        return false;
 
135
    }
 
136
}
 
137
 
 
138
 
 
139
bool Soprano::Client::ClientQueryResultIteratorBackend::isBinding() const
 
140
{
 
141
    if ( m_model ) {
 
142
        bool r = m_model->client()->queryIteratorType( m_iteratorId ) == 3;
 
143
        setError( m_model->client()->lastError() );
 
144
        return r;
 
145
    }
 
146
    else {
 
147
        setError( "Connection to server closed." );
 
148
        return false;
 
149
    }
 
150
}
 
151
 
 
152
 
 
153
bool Soprano::Client::ClientQueryResultIteratorBackend::isBool() const
 
154
{
 
155
    if ( m_model ) {
 
156
        bool r = m_model->client()->queryIteratorType( m_iteratorId ) == 2;
 
157
        setError( m_model->client()->lastError() );
 
158
        return r;
 
159
    }
 
160
    else {
 
161
        setError( "Connection to server closed." );
 
162
        return false;
 
163
    }
 
164
}
 
165
 
 
166
 
 
167
bool Soprano::Client::ClientQueryResultIteratorBackend::boolValue() const
 
168
{
 
169
    if ( m_model ) {
 
170
        bool r = m_model->client()->queryIteratorBoolValue( m_iteratorId );
 
171
        setError( m_model->lastError() );
 
172
        return r;
 
173
    }
 
174
    else {
 
175
        setError( "Connection to server closed." );
 
176
        return false;
 
177
    }
 
178
}