wsdlpull svntrunk
Qname.h
Go to the documentation of this file.
1/*
2 * wsdlpull - A C++ parser for WSDL (Web services description language)
3 * Copyright (C) 2005-2007 Vivek Krishna
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 *
20 */
21#ifndef _QNAMEH
22#define _QNAMEH
23#include <string>
24#include <iostream>
25#ifdef HAVE_CONFIG_H //
26#include <config.h>
27#endif
28#include "wsdlpull_export.h"
29
31{
32 public:
33 Qname (const std::string & name);
34 Qname (const Qname & qn);
35 Qname ();
36 std::string getLocalName (void)const;
37 std::string getPrefix (void) const;
38 std::string getNamespace (void)const;
39 void setNamespace (std::string uri);
40 bool operator== (const Qname & qn)const;
41 void operator= (const std::string & name);
42 friend std::ostream & operator<<(std::ostream & os,const Qname& qn);
43 private:
44 void parse (const std::string & name);
45 std::string namespaceUri, localname, prefix;
46};
47
48inline
49Qname::Qname (const std::string & name)
50{
51 parse (name);
52}
53
54inline
55Qname::Qname (const Qname & qn)
56{
57 localname = qn.localname;
58 prefix = qn.prefix;
59 namespaceUri = qn.namespaceUri;
60}
61
62inline
64{
65}
66
67inline
68void
69Qname::operator= (const std::string & name)
70{
71 parse (name);
72}
73
74inline
75std::string
77{
78 return localname;
79}
80
81inline
82std::string
83Qname::getPrefix (void) const
84{
85 return prefix;
86}
87
88inline
89std::string
91{
92 return namespaceUri;
93}
94
95inline
96void
97Qname::setNamespace (std::string uri)
98{
99 namespaceUri = uri;
100}
101
102inline
103bool
104Qname::operator== (const Qname & qn)const
105{
106 if (qn.getNamespace () == namespaceUri && qn.getLocalName () == localname)
107 return true;
108 else
109 return false;
110}
111
112inline
113void
114Qname::parse (const std::string & name)
115{
116 int cut = -1;
117 if (name.empty ())
118 return;
119 cut = name.find (":");
120 if (cut == -1 || cut == 0)
121 localname = name;
122
123 else
124
125 {
126 localname = name.substr (cut + 1);
127 prefix = name.substr (0, cut);
128 }
129 cut = localname.find ("[]");
130 if (cut > 0)
131 localname = localname.substr (0, cut);
132}
133
134inline
135std::ostream &
136operator<<(std::ostream & os,const Qname& qn)
137{
138 os<<qn.getPrefix()<<"{"<<qn.getNamespace()<<"}:"<<qn.getLocalName();
139 return os;
140}
141#endif /* */
std::ostream & operator<<(std::ostream &os, const Qname &qn)
Definition: Qname.h:136
Definition: Qname.h:31
std::string getLocalName(void) const
Definition: Qname.h:76
void setNamespace(std::string uri)
Definition: Qname.h:97
std::string getPrefix(void) const
Definition: Qname.h:83
bool operator==(const Qname &qn) const
Definition: Qname.h:104
void operator=(const std::string &name)
Definition: Qname.h:69
Qname()
Definition: Qname.h:63
std::string getNamespace(void) const
Definition: Qname.h:90
#define WSDLPULL_EXPORT