|
DBus-1-TQt
1.0
|
00001 /* tqdbusobjectpath.cpp DBUS object path data type 00002 * 00003 * Copyright (C) 2007 Kevin Krammer <kevin.krammer@gmx.at> 00004 * 00005 * Licensed under the Academic Free License version 2.1 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 00020 * USA. 00021 * 00022 */ 00023 00024 #include "tqdbusobjectpath.h" 00025 00026 TQT_DBusObjectPath::TQT_DBusObjectPath() : TQString() 00027 { 00028 } 00029 00030 TQT_DBusObjectPath::TQT_DBusObjectPath(const TQT_DBusObjectPath &other) : TQString(static_cast<const TQString&>(other)) 00031 { 00032 } 00033 00034 TQT_DBusObjectPath::TQT_DBusObjectPath(const TQString &other) : TQString(static_cast<const TQString&>(other)) 00035 { 00036 } 00037 00038 TQT_DBusObjectPath::TQT_DBusObjectPath(const TQT_DBusObjectPath &parentNode, const TQString &nodeName) 00039 : TQString(static_cast<const TQString&>(parentNode)) 00040 { 00041 if (parentNode.length() != 1) 00042 { 00043 append("/"); 00044 } 00045 append(nodeName); 00046 } 00047 00048 bool TQT_DBusObjectPath::isValid() const 00049 { 00050 return (validate(*this) == -1); 00051 } 00052 00053 TQT_DBusObjectPath TQT_DBusObjectPath::parentNode() const 00054 { 00055 if (length() == 1) 00056 { 00057 return TQT_DBusObjectPath(); 00058 } 00059 00060 int index = findRev('/'); 00061 if (index == -1) 00062 { 00063 return TQT_DBusObjectPath(); 00064 } 00065 else if (index == 0) 00066 { 00067 return left(1); 00068 } 00069 00070 return left(index); 00071 } 00072 00073 int TQT_DBusObjectPath::validate(const TQString &path) 00074 { 00075 if (path.isEmpty() || path[0] != '/') 00076 { 00077 return 0; 00078 } 00079 00080 // only root node allowed to end in slash 00081 uint len = path.length(); 00082 if (path[len - 1] == '/' && len > 1) 00083 { 00084 return (len - 1); 00085 } 00086 00087 return -1; 00088 }