~kubuntu-members/korundum/4.11

« back to all changes in this revision

Viewing changes to nepomuk/nepomukhandlers.cpp

  • Committer: Ian Monroe
  • Date: 2010-11-21 15:55:01 UTC
  • Revision ID: git-v1:c37670e4e3c59f5eb2ba112f5341a5e706217f6f
Split up Smoke into Qt and KDE directories. 
Move libsmoke stuff into the generator directory
Split up Ruby into qtruby and korundum directories

svn path=/trunk/KDE/kdebindings/ruby/; revision=1199320

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
                          nepomukhandlers.cpp  -  Nepomuk specific marshallers
3
 
                             -------------------
4
 
    begin                : Thurs May 29 2008
5
 
    copyright            : (C) 2008 by Richard Dale
6
 
    email                : Richard_Dale@tipitina.demon.co.uk
7
 
 ***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
 *                                                                         *
11
 
 *   This program is free software; you can redistribute it and/or modify  *
12
 
 *   it under the terms of the GNU General Public License as published by  *
13
 
 *   the Free Software Foundation; either version 2 of the License, or     *
14
 
 *   (at your option) any later version.                                   *
15
 
 *                                                                         *
16
 
 ***************************************************************************/
17
 
 
18
 
#include <ruby.h>
19
 
 
20
 
#include <QtCore/qhash.h>
21
 
#include <QtCore/qurl.h>
22
 
 
23
 
#include <smoke/qtcore_smoke.h>
24
 
#include <qtruby.h>
25
 
#include <smokeruby.h>
26
 
#include <marshall_macros.h>
27
 
 
28
 
#include <nepomuk/class.h>
29
 
#include <nepomuk/property.h>
30
 
#include <nepomuk/resource.h>
31
 
#include <nepomuk/tag.h>
32
 
#include <nepomuk/variant.h>
33
 
 
34
 
void marshall_QHashQUrlNepomukVariant(Marshall *m) {
35
 
    switch(m->action()) {
36
 
    case Marshall::FromVALUE:
37
 
    {
38
 
        VALUE hash = *(m->var());
39
 
        if (TYPE(hash) != T_HASH) {
40
 
            m->item().s_voidp = 0;
41
 
            break;
42
 
        }
43
 
        
44
 
        QHash<QUrl, Nepomuk::Variant> * map = new QHash<QUrl, Nepomuk::Variant>;
45
 
        
46
 
        // Convert the ruby hash to an array of key/value arrays
47
 
        VALUE temp = rb_funcall(hash, rb_intern("to_a"), 0);
48
 
 
49
 
        for (long i = 0; i < RARRAY_LEN(temp); i++) {
50
 
            VALUE key = rb_ary_entry(rb_ary_entry(temp, i), 0);
51
 
            VALUE value = rb_ary_entry(rb_ary_entry(temp, i), 1);
52
 
            
53
 
            smokeruby_object *k = value_obj_info(key);
54
 
            smokeruby_object *v = value_obj_info(value);
55
 
            (*map)[(QUrl)*(QUrl*)k->ptr] = (Nepomuk::Variant)*(Nepomuk::Variant*)v->ptr;
56
 
        }
57
 
        
58
 
        m->item().s_voidp = map;
59
 
        m->next();
60
 
        
61
 
        if (m->cleanup()) {
62
 
            delete map;
63
 
        }
64
 
    }
65
 
    break;
66
 
 
67
 
    case Marshall::ToVALUE:
68
 
    {
69
 
        QHash<QUrl, Nepomuk::Variant> *map = (QHash<QUrl, Nepomuk::Variant>*)m->item().s_voidp;
70
 
        if (map == 0) {
71
 
            *(m->var()) = Qnil;
72
 
            break;
73
 
        }
74
 
        
75
 
        VALUE hv = rb_hash_new();
76
 
            
77
 
        QHash<QUrl, Nepomuk::Variant>::Iterator it;
78
 
        for (it = map->begin(); it != map->end(); ++it) {
79
 
            void * keyPtr = new QUrl(it.key());
80
 
            VALUE key = getPointerObject(keyPtr);
81
 
 
82
 
            if (key == Qnil) {
83
 
                smokeruby_object  * k = alloc_smokeruby_object( true, 
84
 
                                                                qtcore_Smoke, 
85
 
                                                                qtcore_Smoke->idClass("QUrl").index, 
86
 
                                                                keyPtr );
87
 
                key = set_obj_info("Qt::Url", k);
88
 
            }
89
 
 
90
 
            void * valuePtr = new Nepomuk::Variant(it.value());
91
 
            VALUE value = getPointerObject(valuePtr);
92
 
                
93
 
            if (value == Qnil) {
94
 
                smokeruby_object  * v = alloc_smokeruby_object( true, 
95
 
                                                                m->smoke(), 
96
 
                                                                m->smoke()->idClass("Nepomuk::Variant").index, 
97
 
                                                                valuePtr );
98
 
                value = set_obj_info("Nepomuk::Variant", v);
99
 
            }
100
 
            
101
 
            rb_hash_aset(hv, key, value);
102
 
        }
103
 
        
104
 
        *(m->var()) = hv;
105
 
        m->next();
106
 
        
107
 
        if (m->cleanup()) {
108
 
            delete map;
109
 
        }
110
 
    }
111
 
    break;
112
 
 
113
 
    default:
114
 
        m->unsupported();
115
 
        break;
116
 
    }
117
 
}
118
 
 
119
 
DEF_VALUELIST_MARSHALLER( NepomukResourceList, QList<Nepomuk::Resource>, Nepomuk::Resource )
120
 
DEF_VALUELIST_MARSHALLER( NepomukTagList, QList<Nepomuk::Tag>, Nepomuk::Tag )
121
 
DEF_VALUELIST_MARSHALLER( NepomukTypesClassList, QList<Nepomuk::Types::Class>, Nepomuk::Types::Class )
122
 
DEF_VALUELIST_MARSHALLER( NepomukTypesPropertyList, QList<Nepomuk::Types::Property>, Nepomuk::Types::Property )
123
 
 
124
 
TypeHandler Nepomuk_handlers[] = {
125
 
    { "QList<Nepomuk::Resource>", marshall_NepomukResourceList },
126
 
    { "QList<Nepomuk::Resource>&", marshall_NepomukResourceList },
127
 
    { "QList<Nepomuk::Tag>", marshall_NepomukTagList },
128
 
    { "QList<Nepomuk::Tag>&", marshall_NepomukTagList },
129
 
    { "QList<Nepomuk::Types::Class>", marshall_NepomukTypesClassList },
130
 
    { "QList<Nepomuk::Types::Class>&", marshall_NepomukTypesClassList },
131
 
    { "QList<Nepomuk::Types::Property>", marshall_NepomukTypesPropertyList },
132
 
    { "QList<Nepomuk::Types::Property>&", marshall_NepomukTypesPropertyList },
133
 
    { "QHash<QUrl,Nepomuk::Variant>", marshall_QHashQUrlNepomukVariant },
134
 
    { 0, 0 }
135
 
};
136
 
 
137
 
// kate: space-indent on; indent-width 4; replace-tabs on; mixed-indent off;