DBus-1-TQt  1.0
tqdbusobjectpath.cpp
Go to the documentation of this file.
1 /* tqdbusobjectpath.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) : TQString(static_cast<const TQString&>(other))
31 {
32 }
33 
34 TQT_DBusObjectPath::TQT_DBusObjectPath(const TQString &other) : TQString(static_cast<const TQString&>(other))
35 {
36 }
37 
38 TQT_DBusObjectPath::TQT_DBusObjectPath(const TQT_DBusObjectPath &parentNode, const TQString &nodeName)
39  : TQString(static_cast<const TQString&>(parentNode))
40 {
41  if (parentNode.length() != 1)
42  {
43  append("/");
44  }
45  append(nodeName);
46 }
47 
49 {
50  return (validate(*this) == -1);
51 }
52 
54 {
55  if (length() == 1)
56  {
57  return TQT_DBusObjectPath();
58  }
59 
60  int index = findRev('/');
61  if (index == -1)
62  {
63  return TQT_DBusObjectPath();
64  }
65  else if (index == 0)
66  {
67  return left(1);
68  }
69 
70  return left(index);
71 }
72 
73 int TQT_DBusObjectPath::validate(const TQString &path)
74 {
75  if (path.isEmpty() || path[0] != '/')
76  {
77  return 0;
78  }
79 
80  // only root node allowed to end in slash
81  uint len = path.length();
82  if (path[len - 1] == '/' && len > 1)
83  {
84  return (len - 1);
85  }
86 
87  return -1;
88 }
Class for representing D-Bus object paths.
static int validate(const TQString &path)
Checks the given string for validity as a D-Bus object path.
TQT_DBusObjectPath()
Creates an empty and invalid object path.
TQT_DBusObjectPath parentNode() const
Returns the object path of this path's parent node.
bool isValid() const
Returns whether the current content is considered a valid object path.