DBus-1-TQt  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tqdbusobjectpath.cpp
Go to the documentation of this file.
1 /* qdbusobjectpath.cpp DBUS object path data type
2  *
3  * Copyright (C) 2007 Kevin Krammer <kevin.krammer@gmx.at>
4  *
5  * Licensed under the Academic Free License version 2.1
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20  * USA.
21  *
22  */
23 
24 #include "tqdbusobjectpath.h"
25 
27 {
28 }
29 
30 TQT_DBusObjectPath::TQT_DBusObjectPath(const TQT_DBusObjectPath& other) : TQCString(static_cast<const TQCString&>(other))
31 {
32 }
33 
34 TQT_DBusObjectPath::TQT_DBusObjectPath(const TQCString& other) : TQCString(static_cast<const TQCString&>(other))
35 {
36 }
37 
39  const TQCString& nodeName)
40  : TQCString(static_cast<const TQCString&>(parentNode))
41 {
42  if (parentNode.length() != 1) append("/");
43 
44  append(nodeName);
45 }
46 
48 {
49  return (validate(*this) == -1);
50 }
51 
53 {
54  if (length() == 1) return TQT_DBusObjectPath();
55 
56  int index = findRev('/');
57 
58  if (index == -1) return TQT_DBusObjectPath();
59 
60  if (index == 0) return left(1);
61 
62  return left(index);
63 }
64 
65 int TQT_DBusObjectPath::validate(const TQCString& path)
66 {
67  if (path.isEmpty()) return 0;
68 
69  if (path[0] != '/') return 0;
70 
71  // TODO add additional checks
72 
73  uint len = path.length();
74 
75  // only root node allowed to end in slash
76  if (path[len - 1] == '/' && len > 1) return (len - 1);
77 
78  return -1;
79 }
Class for representing D-Bus object paths.
TQT_DBusObjectPath parentNode() const
Returns the object path of this path's parent node.
static int validate(const TQCString &path)
Checks the given string for validity as a D-Bus object path.
TQT_DBusObjectPath()
Creates an empty and invalid object path.
bool isValid() const
Returns whether the current content is considered a valid object path.