File: util.hh

package info (click to toggle)
lapackpp 2024.10.26-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,500 kB
  • sloc: cpp: 80,181; ansic: 27,660; python: 4,838; xml: 182; perl: 99; makefile: 53; sh: 23
file content (59 lines) | stat: -rw-r--r-- 1,805 bytes parent folder | download | duplicates (2)
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
// Copyright (c) 2017-2023, University of Tennessee. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause
// This program is free software: you can redistribute it and/or modify it under
// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.

#ifndef UTIL_H
#define UTIL_H

#include <stdio.h>
#include <stdexcept>

//------------------------------------------------------------------------------
void print_func_( const char* func )
{
    printf( "\n%s\n", func );
}

#ifdef __GNUC__
    #define print_func() print_func_( __PRETTY_FUNCTION__ )
#else
    #define print_func() print_func_( __func__ )
#endif

//------------------------------------------------------------------------------
// Parse command line options:
// s = single,         sets types[ 0 ]
// d = double,         sets types[ 1 ]
// c = complex,        sets types[ 2 ]
// z = double-complex, sets types[ 3 ]
// If no options, sets all types to true.
// Throws error for unknown options.
void parse_args( int argc, char** argv, bool types[ 4 ] )
{
    if (argc == 1) {
        types[ 0 ] = types[ 1 ] = types[ 2 ] = types[ 3 ] = true;
    }
    else {
        types[ 0 ] = types[ 1 ] = types[ 2 ] = types[ 3 ] = false;
    }
    for (int i = 1; i < argc; ++i) {
        std::string arg = argv[ i ];
        if (arg == "s")
            types[ 0 ] = true;
        else if (arg == "d")
            types[ 1 ] = true;
        else if (arg == "c")
            types[ 2 ] = true;
        else if (arg == "z")
            types[ 3 ] = true;
        else {
            throw std::runtime_error(
                "unknown option: \"" + arg + "\"\n"
                + "Usage: " + argv[ 0 ] + " [s] [d] [c] [z]\n"
                + "for single, double, complex, double-complex.\n" );
        }
    }
}

#endif // UTIL_H