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