File: utils.cc

package info (click to toggle)
mia 2.4.7-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 16,828 kB
  • sloc: cpp: 162,686; python: 1,317; sh: 315; xml: 127; makefile: 36; csh: 24; ansic: 9
file content (86 lines) | stat: -rw-r--r-- 1,885 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* -*- mia-c++  -*-
 *
 * This file is part of MIA - a toolbox for medical image analysis
 * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
 *
 * MIA is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MIA; if not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#ifdef WIN32
#include <direct.h>
#define getcwd _getcwd
#define chdir _chdir
#endif

#include <limits.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <errno.h>
#include <iostream>
#include <stdexcept>
#include <iomanip>

// MIA specific
#include <mia/core/utils.hh>
#include <mia/core/msgstream.hh>

// WIN32 and HURD don't define this
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif

NS_MIA_BEGIN

CCWDSaver::CCWDSaver():
       cwd(new char[PATH_MAX])
{
       if (!getcwd(cwd, PATH_MAX)) {
              delete[] cwd;
              throw strerror(errno);
       }
}

CCWDSaver::~CCWDSaver()
{
       if (chdir(cwd) == -1) {
              cverr() << "CCWDSaver::~CCWDSaver():" << strerror(errno) << "\n";
       }

       delete[] cwd;
}


#ifndef _GNU_SOURCE
// there should be an intrinsic (at least on intel)
void EXPORT_CORE sincosf(float x, float *s, float *c)
{
       *s = sinf(x);
       *c = cosf(x);
}

void EXPORT_CORE sincos(double x, double *s, double *c)
{
       *s = sin(x);
       *c = cos(x);
}
#endif

NS_MIA_END