[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/nepomuk/core
From:       Vishesh Handa <handa.vish () gmail ! com>
Date:       2010-08-24 19:05:10
Message-ID: 20100824190510.67DFEAC857 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1167486 by vhanda:

Nepomuk Variant - Add convenience toNode and toNodeList member functions.


 M  +41 -0     variant.cpp  
 M  +14 -0     variant.h  


--- trunk/KDE/kdelibs/nepomuk/core/variant.cpp #1167485:1167486
@@ -20,6 +20,7 @@
 
 #include "variant.h"
 #include "resource.h"
+#include "tools.h"
 
 #include <soprano/literalvalue.h>
 #include <soprano/node.h>
@@ -1259,6 +1260,46 @@
 }
 
 
+Soprano::Node Nepomuk::Variant::toNode() const
+{
+    if( isList() )
+        return Soprano::Node();
+        
+    if( isResource() )
+        return Soprano::Node( toUrl() );
+    else
+        return Soprano::Node( Soprano::LiteralValue( variant() ) );
+}
+
+QList<Soprano::Node> Nepomuk::Variant::toNodeList() const
+{
+    QList<Soprano::Node> valueNodes;
+    
+    // one Resource
+    if( isResource() ) {
+        valueNodes.append( toUrl() );
+    }
+    
+    // many Resources
+    else if( isResourceList() ) {
+        const QList<QUrl>& l = toUrlList();
+        for( QList<QUrl>::const_iterator resIt = l.constBegin(); resIt != l.constEnd(); ++resIt ) {
+            valueNodes.append( *resIt );
+        }
+    }
+    
+    // many literals
+    else if( isList() ) {
+        valueNodes = Nepomuk::valuesToRDFNodes( *this );
+    }
+    
+    // one literal
+    else {
+        valueNodes.append( Nepomuk::valueToRDFNode( *this ) );
+    }
+}
+
+
 bool Nepomuk::Variant::isList() const
 {
     return( isIntList() ||
--- trunk/KDE/kdelibs/nepomuk/core/variant.h #1167485:1167486
@@ -346,6 +346,20 @@
         QList<Variant> toVariantList() const;
 
         /**
+         * Convert a Variant to a Node.
+         *
+         * \since 4.6
+         */
+        Soprano::Node toNode() const;
+
+        /**
+         * Convert a Variant to a a list of Nodes.
+         *
+         * \since 4.6
+         */
+        QList<Soprano::Node> toNodeList() const;
+        
+        /**
          * Create a Variant object by parsing string \a value based on \a type.
          * If \a type is unknown a simple string Variant object is returned
          * containing the plain string \a value.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic