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
) {
31 type_name
= new component_name(*x
.type_name
);
34 const component_name
&component_name::get_type() const {
38 unsigned int component_name::get_index() const {
42 string
component_name::get_name() const {
46 bool component_name::operator==(const component_name
&x
) const {
47 if (!x
.type_name
&& type_name
)
49 if (x
.type_name
&& !type_name
)
52 if (!x
.type_name
&& !type_name
&& x
.text_name
== text_name
)
54 if (*x
.type_name
== *type_name
&& x
.text_name
== text_name
)
59 component_name
component_name::from_path(const string
&tpath
) {
60 char *path
= new char[strlen(tpath
) + 1];
65 char *dep_res
= (char*)0;
66 char *main_res
= (char*)0;
67 char *specific_name
= (char*)0;
73 main_res
= &(path
[j
]);
79 if (string::is_digit(path
[i
]))
80 for (; path
[i
] && path
[i
] != '/'; i
++)
81 num
= num
* 10 + path
[i
] - '0';
83 specific_name
= &path
[i
];
84 } else if (path
[i
] == '/') {
90 for (; path
[i
] && path
[i
] != ',' && path
[i
] != '/'; i
++);
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";
104 cname
.text_name
= (string
)specific_name
;
106 cname
.text_name
= "";
107 cname
.type_index
= num
;
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
;
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
;