Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkRdfNode.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkRdfNode.h"
18 
19 #include <stdio.h>
20 #include <ostream>
21 #include <ctype.h>
22 #include <stdarg.h>
23 
24 #include <redland.h>
25 
26 namespace mitk {
27 
29  : m_Type(NOTHING)
30  {
31  }
32 
34  : m_Type(URI), m_Value(uri.ToString())
35  {
36  }
37 
38  RdfNode::RdfNode(std::string text)
39  : m_Type(LITERAL), m_Value(text)
40  {
41  }
42 
43  RdfNode::RdfNode(std::string text, RdfUri dataType)
44  : m_Type(LITERAL), m_Value(text), m_Datatype(dataType)
45  {
46  }
47 
49  {
50  }
51 
53  {
54  m_Type = type;
55  }
56 
58  {
59  m_Datatype = dataType;
60  }
61 
62  void RdfNode::SetValue(std::string value)
63  {
64  m_Value = value;
65  }
66 
68  {
69  return m_Type;
70  }
71 
73  {
74  return m_Datatype;
75  }
76 
77  std::string RdfNode::GetValue() const
78  {
79  return m_Value;
80  }
81 
82  bool RdfNode::operator==(const RdfNode &u) const
83  {
84  if (this->m_Type != u.m_Type) return false;
85  if (this->m_Value.compare(u.m_Value) != 0) return false;
86  if (this->m_Datatype != u.m_Datatype) return false;
87  return true;
88  }
89 
90  bool RdfNode::operator!=(const RdfNode &u) const
91  {
92  return !operator==(u);
93  }
94 
95  // Define outstream of a Node
96  std::ostream & operator<<(std::ostream &out, const RdfNode &n)
97  {
98  switch (n.GetType()) {
99  case RdfNode::NOTHING:
100  out << "[]";
101  break;
102  case RdfNode::URI:
103  if (n.GetValue() == "") {
104  out << "[empty-uri]";
105  } else {
106  out << "<" << n.GetValue() << ">";
107  }
108  break;
109  case RdfNode::LITERAL:
110  out << "\"" << n.GetValue() << "\"";
111  if (n.GetDatatype() != RdfUri()) out << "^^" << n.GetDatatype();
112  break;
113  case RdfNode::BLANK:
114  out << "[blank " << n.GetValue() << "]";
115  break;
116  }
117  return out;
118  }
119 }
bool operator!=(const RdfNode &u) const
Definition: mitkRdfNode.cpp:90
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)
virtual ~RdfNode()
Definition: mitkRdfNode.cpp:48
DataCollection - Class to facilitate loading/accessing structured data.
std::string GetValue() const
Definition: mitkRdfNode.cpp:77
RdfUri GetDatatype() const
Definition: mitkRdfNode.cpp:72
Type GetType() const
Definition: mitkRdfNode.cpp:67
void SetDatatype(RdfUri dataType)
Definition: mitkRdfNode.cpp:57
void SetValue(std::string value)
Definition: mitkRdfNode.cpp:62
void SetType(Type type)
Definition: mitkRdfNode.cpp:52
bool operator==(const RdfNode &u) const
Definition: mitkRdfNode.cpp:82