testing
[gnucap-felix.git] / src / l_lib.h
blob7fdddbb745a5d6683c8075b5bd14fd02a5d47408
1 /*$Id: l_lib.h,v 1.3 2010-08-16 12:23:30 felix Exp $ -*- C++ -*-
2 * Copyright (C) 2001 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
22 //testing=script 2006.07.13
23 #ifndef L_LIB_H
24 #define L_LIB_H
25 #include "md.h"
26 #define HAVE_GETENV_DEFAULTS
27 // #include "u_parameter.h"
28 /*--------------------------------------------------------------------------*/
29 char* trim(char*);
30 INTERFACE bool Umatch(const std::string&, const std::string&);
31 INTERFACE bool wmatch(const std::string& s1,const std::string& s2);
33 //template doesnt work?
34 INTERFACE std::string to_string(std::string);
35 INTERFACE std::string to_string(int);
36 INTERFACE std::string to_string(unsigned long int);
37 INTERFACE std::string to_string(long int);
38 INTERFACE std::string to_string(unsigned);
39 INTERFACE std::string to_string(double);
40 INTERFACE std::string to_string(long double);
42 //FIXME: template?
43 INTERFACE std::string to_string(std::vector<double>);
44 INTERFACE std::string to_string(std::list<double>);
46 INTERFACE char* ftos(double,int,int,int);
47 /*--------------------------------------------------------------------------*/
48 //ftos stuff
49 enum { /* formatting bit-fields */
50 ftos_DEFAULT = 0, /* default formatting, with letters */
51 ftos_EXP = 1, /* use 'e' notation, almost like printf */
52 ftos_SIGN = 2, /* always include sign */
53 ftos_FILL = 4 /* fill in trailing zeros */
55 /*--------------------------------------------------------------------------*/
56 // wrappers for old standard C lpbrary
57 namespace OS {
58 inline void system(const std::string& s) {itested();
59 ::system(s.c_str());
62 inline void chdir(const std::string& s) {itested();
63 ::chdir(s.c_str());
66 inline void remove(const std::string& s) {itested();
67 ::remove(s.c_str());
70 inline bool access_ok(const std::string& file, int mode) {
71 return (::access(file.c_str(), mode) == 0/*file_ok*/);
74 inline std::string getcwd() {itested();
75 char buf[BUFLEN+1];
76 char* cwd = ::getcwd(buf,BUFLEN);
77 if (cwd) {itested();
78 return cwd;
79 }else{untested();
80 return "";
84 inline std::string getenv(const std::string& s) {
85 char* ev = ::getenv(s.c_str());
86 if (ev) {
87 return ev;
88 }else{itested();
89 return "";
93 template<class T>
94 T getenv(const std::string&, T def);
96 template<class T>
97 inline T getenv(const std::string& s, T def) {
98 char* ev = ::getenv(s.c_str());
99 if(!ev){
100 return def;
101 }else{
102 return T(ev);
106 template<>
107 inline bool getenv(const std::string& s, bool def) {
108 char* ev = ::getenv(s.c_str());
109 if(!ev){ untested();
110 return def;
111 } else { untested();
112 return strcmp(ev,"no") && strcmp(ev,"0");
116 /*--------------------------------------------------------------------------*/
117 /*--------------------------------------------------------------------------*/
118 #endif
119 // vim:ts=8:sw=2:noet: