Tizen 2.1 base
[framework/security/security-server.git] / ace / dao / BaseAttribute.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  *
18  *
19  * @file       BaseAttribute.cpp
20  * @author     Lukasz Marek (l.marek@samsung.com)
21  * @version    0.1
22  * @brief
23  */
24
25 #include <sstream>
26 #include <string>
27
28 #include <ace-dao-ro/BaseAttribute.h>
29
30 namespace AceDB {
31
32 const char* BaseAttribute::typeToString(Type type)
33 {
34     const char * ret = NULL;
35     switch (type) {
36     case Type::Resource:
37         ret = "resource";
38         break;
39     case Type::Subject:
40         ret = "subject";
41         break;
42     case Type::Environment:
43         ret = "environment";
44         break;
45     default:
46         ret = "unknown type";
47         break;
48     }
49
50     return ret;
51 }
52
53 std::string BaseAttribute::toString() const
54 {
55     std::string ret;
56     const char * SEPARATOR = ";";
57
58     ret.append(m_name);
59     ret.append(SEPARATOR);
60     ret.append(typeToString(m_typeId));
61     ret.append(SEPARATOR);
62     if (m_undetermindState) {
63         ret.append("true");
64     } else {
65         ret.append("false");
66     }
67     ret.append(SEPARATOR);
68     for (std::list<std::string>::const_iterator it = value.begin();
69          it != value.end();
70          ++it) {
71         std::stringstream num;
72         num << it->size();
73         ret.append(num.str());
74         ret.append(SEPARATOR);
75         ret.append(*it);
76         ret.append(SEPARATOR);
77     }
78
79     return ret;
80 }
81
82 }