summaryrefslogtreecommitdiffhomepage
path: root/include/CompilerKit/Detail/Config.h
blob: eeb653d02e85abe7dc6fe8edf475989c0265c414 (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
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (See accompanying
// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0)
// Official repository: https://github.com/ne-foss-org/nectar

#ifndef __COMPILERKIT_CONFIG_H__
#define __COMPILERKIT_CONFIG_H__

/// =========================================================== ///
/// @file detail/Config.h
/// @author Amlal El Mahrouss
/// @brief Basic defines and types for CompilerKit.
/// =========================================================== ///

#include <CompilerKit/Detail/PreConfig.h>
#include <ocl/tproc.hpp>

namespace CompilerKit {
inline static constexpr int kBaseYear = 1900;
    using STLString                       = std::string;
    using RopeString = ocl::tproc::crope;

inline STLString current_date() noexcept {
  auto time_data   = time(nullptr);
  auto time_struct = gmtime(&time_data);

  STLString fmt = std::to_string(kBaseYear + time_struct->tm_year);

  fmt += "-";
  fmt += std::to_string(time_struct->tm_mon + 1);
  fmt += "-";
  fmt += std::to_string(time_struct->tm_mday);

  return fmt;
}

inline bool to_str(char* str, Int32 limit, Int32 base) noexcept {
  if (limit == 0) return false;

  Int32 copy_limit = limit;
  Int32 cnt        = 0;
  Int32 ret        = base;

  while (limit != 1) {
    ret      = ret % 10;
    str[cnt] = ret;

    ++cnt;
    --limit;
    --ret;
  }

  str[copy_limit] = '\0';
  return true;
}

inline bool install_signal(Int32 signal, void (*handler)(int)) noexcept {
  if (handler == nullptr) return false;

  if (::signal(signal, handler) == SIG_ERR) {
    return false;
  }

  return true;
}
}  // namespace CompilerKit

#endif  // __COMPILERKIT_CONFIG_H__