Wat
[potpourri.git] / include / core / common.h
blob2e2ba476f49c6e8ec7eb9a8476031d51c9fe1fa2
1 // Copyright 2008 Brian Caine
3 // This file is part of Potpourri.
5 // Potpourri is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Potpourri is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTIBILITY of FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Potpourri. If not, see <http://www.gnu.org/licenses/>.
19 // NOTES:
20 // This is a collection of odd portions of various functions
21 // shitty written, of course
23 #ifndef __COMMON_H
24 #define __COMMON_H
26 #include <vector>
27 #include <string>
28 #include "../Global.h"
29 #include <sstream>
31 const char path_separator = '/';
33 const std::string parent_dir = "..";
34 const std::string current_dir = ".";
36 const float PI = 3.14159;
38 const std::string url_regexp =
39 "([a-zA-Z+-.]*)://([a-zA-Z.&:0-9]*)([~a-zA-Z./%0-9?=-]*)";
41 const std::string hostless_protocols[] = {"file"};
43 struct ParsedPath
45 std::vector<std::string> split_path;
46 std::string raw_path;
48 std::string protocol;
49 std::string path;
50 std::string host;
53 enum DirectoryNesting
55 DN_FormerInLatter,
56 DN_LatterInFormer,
57 DN_Unrelated,
58 DN_Identical
61 template <typename T>
62 std::string toString(T input)
64 std::stringstream d;
65 d << input;
66 std::string result;
67 d >> result;
68 return result;
71 std::string joinPath(std::vector<std::string> path);
72 std::vector<std::string> splitPath(std::string path);
73 std::string simplifyPath(std::string orig);
74 DirectoryNesting compareDirectories(std::string patha, std::string pathb);
75 std::vector<std::string> pathDifference(std::string patha, std::string pathb);
76 bool isRelative(std::string path);
77 ParsedPath parsePath(std::string path);
79 bool isURL(std::string);
81 std::vector<std::string> splitString(std::string, std::string=" ");
83 // fuck radians
85 float toRadians(float);
86 float fromRadians(float);
88 int getticks();
89 void dosleep(int);
91 Pair<float> getOffset(Pair<float>, float);
93 #endif