usb: getting string descriptors, minor improvements
[quarnos.git] / manes / cds / component_name.cpp
blob9cbe39492bf09a852df578cec01a4cbc515edf2b
1 /* Quarn OS / Manes
3 * Component name class implementation
5 * Copyright (C) 2008-2009 Pawel Dziepak
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.
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.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "component_name.h"
25 using namespace manes::cds;
27 component_name::component_name(const component_name &x) :
28 type_index(x.type_index),
29 text_name(x.text_name) {
30 if (x.type_name)
31 type_name = new component_name(*x.type_name);
34 const component_name &component_name::get_type() const {
35 return *type_name;
38 unsigned int component_name::get_index() const {
39 return type_index;
42 string component_name::get_name() const {
43 return text_name;
46 bool component_name::operator==(const component_name &x) const {
47 if (!x.type_name && type_name)
48 return false;
49 if (x.type_name && !type_name)
50 return false;
52 if (!x.type_name && !type_name && x.text_name == text_name)
53 return true;
54 if (*x.type_name == *type_name && x.text_name == text_name)
55 return true;
56 return false;
59 component_name component_name::from_path(const string &tpath) {
60 char *path = new char[strlen(tpath) + 1];
61 strcpy(path, tpath);
63 int i = 1, j = 1;
65 char *dep_res = (char*)0;
66 char *main_res = (char*)0;
67 char *specific_name = (char*)0;
68 int num = 0;
70 main_res = &path[1];
71 while(1) {
72 if (!path[i]) {
73 main_res = &(path[j]);
74 break;
76 if (path[i] == ',') {
77 path[i] = 0;
78 i++;
79 if (string::is_digit(path[i]))
80 for (; path[i] && path[i] != '/'; i++)
81 num = num * 10 + path[i] - '0';
82 else
83 specific_name = &path[i];
84 } else if (path[i] == '/') {
85 path[i] = 0;
86 dep_res = &(path[j]);
87 i++;
88 j = i;
90 for (; path[i] && path[i] != ',' && path[i] != '/'; i++);
91 if (!path[i])
92 break;
95 component_name cname;
97 cname.type_name = new component_name;
98 cname.type_name->text_name = main_res;
99 if (strcmp(main_res, "type")) {
100 cname.type_name->type_name = new component_name;
101 cname.type_name->type_name->text_name = "type";
103 if (specific_name)
104 cname.text_name = (string)specific_name;
105 else
106 cname.text_name = "";
107 cname.type_index = num;
109 return cname;
112 component_name component_name::from_index(const string &tname, unsigned int i) {
113 component_name cname;
115 cname.type_name = new component_name;
116 cname.type_name->text_name = tname;
117 cname.type_name->type_name = new component_name;
118 cname.type_name->type_name->text_name = "type";
120 cname.type_index = i;
122 return cname;
125 component_name::component_name() : text_name("") {}
127 void component_name::serialize(ods::object_stream &ostr) {
131 void component_name::deserialize(ods::object_stream &ostr) {
135 const component_name component_name::invalid;