tizen beta release
[platform/framework/web/wrt-plugins-common.git] / src / modules / API / Filesystem / IPath.h
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 #ifndef WRTDEVICEAPIS_FILESYSTEM_IPATH_H_
17 #define WRTDEVICEAPIS_FILESYSTEM_IPATH_H_
18
19 #include <string>
20 #include <dpl/shared_ptr.h>
21
22 namespace WrtDeviceApis {
23 namespace Filesystem {
24 namespace Api{
25
26 class IPath;
27 typedef DPL::SharedPtr<IPath> IPathPtr;
28
29 class IPath
30 {
31   public:
32     typedef char SeparatorType;
33
34   public:
35     /**
36      * Creates path object from specified string.
37      * @param str Path string.
38      * @return Path.
39      * @throw InvalidArgumentException If supplied string is not a valid path.
40      * @throw PlatformException If error in platform occurs.
41      * @remarks Ownership passed to the caller.
42      */
43     static IPathPtr create(const std::string& str);
44
45     /**
46      * Gets separator used by current platform.
47      * @return Path separator.
48      */
49     static SeparatorType getSeparator();
50
51   public:
52     virtual ~IPath() = 0;
53
54     /**
55      * Gets full path.
56      * @return Full path.
57      */
58     virtual std::string getFullPath() const = 0;
59
60     /**
61      * Gets base path (full path w/o name).
62      * @return Base path
63      */
64     virtual std::string getPath() const = 0;
65
66     /**
67      * Gets the last part of path.
68      * @return Path's name.
69      * @return Last part is typically name of a directory or file.
70      */
71     virtual std::string getName() const = 0;
72
73     /**
74      * Appends path specified as string to current path.
75      * @param path Path to append.
76      * @return Current path object.
77      */
78     virtual IPathPtr append(const std::string& path) = 0;
79
80     /**
81      * Appends path specified as path object to current path.
82      * @param path Path to append.
83      * @return Current path object.
84      */
85     virtual IPathPtr append(const IPathPtr& path) = 0;
86
87     /**
88      * Checks if path is abolute.
89      * @return True if absolute, false if relative.
90      */
91     virtual bool isAbsolute() const = 0;
92
93     /**
94      * Clones this object.
95      * @return Independent copy.
96      */
97     virtual IPathPtr clone() const = 0;
98 };
99
100 inline const IPathPtr operator+(const IPath& lhs,
101         const IPath& rhs)
102 {
103     return IPath::create(lhs.getFullPath())->append(rhs.getFullPath());
104 }
105
106 inline const IPathPtr operator+(const IPath& lhs,
107         const std::string& rhs)
108 {
109     return IPath::create(lhs.getFullPath())->append(rhs);
110 }
111
112 inline const IPathPtr operator+(const std::string& lhs,
113         const IPath& rhs)
114 {
115     return IPath::create(lhs)->append(rhs.getFullPath());
116 }
117
118 inline bool operator==(const IPath& lhs, const IPath& rhs)
119 {
120     return (lhs.getFullPath() == rhs.getFullPath());
121 }
122
123 inline bool operator==(const IPath& lhs, const std::string& rhs)
124 {
125     return (lhs.getFullPath() == rhs);
126 }
127
128 inline bool operator==(const std::string& lhs, const IPath& rhs)
129 {
130     return (lhs == rhs.getFullPath());
131 }
132
133 inline bool operator!=(const IPath& lhs, const IPath& rhs)
134 {
135     return (lhs.getFullPath() != rhs.getFullPath());
136 }
137
138 inline bool operator!=(const IPath& lhs, const std::string& rhs)
139 {
140     return (lhs.getFullPath() != rhs);
141 }
142
143 inline bool operator!=(const std::string& lhs, const IPath& rhs)
144 {
145     return (lhs != rhs.getFullPath());
146 }
147
148 } // API
149 } // Filesystem
150 } // WrtDeviceApis
151
152 #endif // WRTDEVICEAPIS_FILESYSTEM_IPATH_H_