summaryrefslogtreecommitdiff
path: root/include/Utility/Utility.h
blob: 062e422bb7eec7534d9ee757a69e53db4dae3173 (plain)
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
#ifndef UTILITIES_H_
#define UTILITIES_H_

#include "General.h"
#include "Version.h"

/**********************************************************************
* COPYRIGHT 2020 MULTI-TECH SYSTEMS, INC.
*
* ALL RIGHTS RESERVED BY AND FOR THE EXCLUSIVE BENEFIT OF
* MULTI-TECH SYSTEMS, INC.
*
* MULTI-TECH SYSTEMS, INC. - CONFIDENTIAL AND PROPRIETARY
* INFORMATION AND/OR TRADE SECRET.
*
* NOTICE: ALL CODE, PROGRAM, INFORMATION, SCRIPT, INSTRUCTION,
* DATA, AND COMMENT HEREIN IS AND SHALL REMAIN THE CONFIDENTIAL
* INFORMATION AND PROPERTY OF MULTI-TECH SYSTEMS, INC.
* USE AND DISCLOSURE THEREOF, EXCEPT AS STRICTLY AUTHORIZED IN A
* WRITTEN AGREEMENT SIGNED BY MULTI-TECH SYSTEMS, INC. IS PROHIBITED.
*
***********************************************************************/

inline bool fileExists(std::string file) {
    struct stat buffer;
    return (stat (file.c_str(), &buffer) == 0) ? true : false;
}

inline std::string toCamelCase(const char * d_name)  {
    std::string camelString = strdup(d_name);
    std::string tempString = "";
    for (size_t x = 0; x < camelString.length(); x++){
        if (camelString[x] == '-' || camelString[x] == '_'){
            tempString = camelString.substr(x + 1, 1);
            transform(tempString.begin(), tempString.end(), tempString.begin(), toupper);
            camelString.erase(x, 2);
            camelString.insert(x, tempString);
        }
    }
    return camelString;
}

inline void exitHandler(int code) {
    if (code != 0) {
        std::cout << "exiting with " << std::to_string(code);
    }
    exit(code);
}

inline mode_t fileType(std::string file) {
    struct stat buf;
    stat (file.c_str(), &buf);
    return buf.st_mode & S_IFMT;
}

#endif /* UTILITIES_H_ */