Debian Codegraph @

Common.h

raw symbols SCIP
1 /***************************************************************************
2 * This file is part of Robocut. *
3 * Copyright (C) 2010 Tim Hutt <[email protected]> *
4 * *
5 * This program 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. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
20
21 #pragma once
22
23 /// Result Class
24
25 #include <string>
26 #include <sstream>
27 #include <cstdio>
28 #include <vector>
29 #include <cstdlib>
30
31 using stdcxx . . $ std/::vectorcxx . . $ vector#;
32 using stdcxx . . $ std/::stringcxx . . $ std/string#;
33
34 typedef stringcxx . . $ std/__cxx11/basic_string#::size_typecxx . . $ std/__cxx11/basic_string#size_type# stringposcxx . . $ stringpos#;
35
36 /// Error Handling
37
38 class Errorcxx . . $ Error#
39 {
40 public:
41 explicit Errorcxx . . $ Error#Error(b45ddcbc8423892c).(bool S) : scxx . . $ Error#s.(S) { }
42 explicit Errorcxx . . $ Error#Error(85c52e162fed56f9).(const char* C) : scxx . . $ Error#s.(false), mcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).(C) { }
43 Errorcxx . . $ Error#Error(9c546c94e5fcce4e).(const stringcxx . . $ string#& msg) : scxx . . $ Error#s.(false), mcxx . . $ Error#m.(msg) { }
44 operatorcxx . . $ Error#`operator bool`(c9857a73d68e59ba). bool() { return scxx . . $ Error#s.; } // TODO: Use bool hack from boost so int i = Error(); doesn't work.
45 stringcxx . . $ string# messagecxx . . $ Error#message(efd28698952f529a).() { if (mcxx . . $ Error#m..emptycxx . . $ std/__cxx11/basic_string#empty(50ce9a9e25b4a850).()) returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "Unspecified Error"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; return mcxx . . $ Error#m.; }
46
47 private:
48 bool scxx . . $ Error#s.;
49 stringcxx . . $ string# mcxx . . $ Error#m.;
50 };
51
52 const Errorcxx . . $ Error# Successcxx . . $ Error#Error(b45ddcbc8423892c).(true);
53 const Errorcxx . . $ Error# Failurecxx . . $ Failure.(false);
54
55 // Integer to string.
56 inline stringcxx . . $ string# ItoScxx . . $ ItoS(7eb93f795f0defb3).(int I)
57 {
58 stdcxx . . $ std/::stringstreamcxx . . $ std/stringstream# Scxx . . $ std/__cxx11/basic_stringstream#basic_stringstream(49f6e7a06ebc5aa8).;
59 S <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). I;
60 return Scxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f)..strcxx . . $ std/__cxx11/basic_stringstream#str(d33e1a6fd36255f7).();
61 }
62
63 // Unsigned integer to string.
64 inline stringcxx . . $ string# UItoScxx . . $ UItoS(8297fed3afd4179b).(unsigned int I)
65 {
66 stdcxx . . $ std/::stringstreamcxx . . $ std/stringstream# Scxx . . $ std/__cxx11/basic_stringstream#basic_stringstream(49f6e7a06ebc5aa8).;
67 S <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). I;
68 return Scxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f)..strcxx . . $ std/__cxx11/basic_stringstream#str(d33e1a6fd36255f7).();
69 }
70
71 // Unsigned long long to string.
72 inline stringcxx . . $ string# ULLtoScxx . . $ ULLtoS(f8fc710d898c6ac4).(unsigned long long I)
73 {
74 char out[128];
75 sprintf(out, "%lld", I);
76 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). outcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
77 }
78
79 // String to integer, returns Fail on fail.
80 inline int StoIcxx . . $ StoI(7b1020165ab78f0a).(const stringcxx . . $ string#& S, int Fail = 0)
81 {
82 char* EP;
83 const char* P = S.c_strcxx . . $ std/__cxx11/basic_string#c_str(1016ee5406d91ab9).();
84 int R = strtol(P, &EP, 0);
85 if (EP == P)
86 return Fail;
87 return R;
88 }
89
90 // String to unsigned integer, returns Fail on fail.
91 inline unsigned int StoUIcxx . . $ StoUI(197c4a11fa172136).(const stringcxx . . $ string#& S, unsigned int Fail = 0)
92 {
93 char* EP;
94 const char* P = S.c_strcxx . . $ std/__cxx11/basic_string#c_str(1016ee5406d91ab9).();
95 int R = strtoul(P, &EP, 0);
96 if (EP == P)
97 return Fail;
98 return R;
99 }
100
101 // String to unsigned integer, returns Fail on fail.
102 inline unsigned int StoULLcxx . . $ StoULL(95ca3321da3e1f81).(const stringcxx . . $ string#& S, unsigned long long Fail = 0)
103 {
104 char* EP;
105 const char* P = S.c_strcxx . . $ std/__cxx11/basic_string#c_str(1016ee5406d91ab9).();
106 int R = strtoull(P, &EP, 0);
107 if (EP == P)
108 return Fail;
109 return R;
110 }
111
112 // Get an environmental variable.
113 inline stringcxx . . $ string# GetEnvcxx . . $ GetEnv(fd626fc03107dd24).(const stringcxx . . $ string#& Var)
114 {
115 char* V = getenv(Var.c_strcxx . . $ std/__cxx11/basic_string#c_str(1016ee5406d91ab9).());
116 if (!V)
117 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). ""cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
118 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). Vcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
119 }