• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 25918451630

15 May 2026 12:43PM UTC coverage: 60.929% (+2.1%) from 58.859%
25918451630

push

github

turleypol
added dynamic property which returns a pointer of the object instead of
a copy like the current imp.
needed to be able to eg store a vector

43 of 61 new or added lines in 2 files covered. (70.49%)

14455 existing lines in 345 files now uncovered.

44695 of 73356 relevant lines covered (60.93%)

449621.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.23
/pol-core/clib/Program/ProgramMain.cpp
1
#include "ProgramMain.h"
2

3
#include <stdlib.h>
4

5
#include <boost/stacktrace.hpp>
6

7
#include "../Debugging/ExceptionParser.h"
8
#include "../logfacility.h"
9
#include "ProgramConfig.h"
10
#include "pol_global_config.h"
11

12
#ifdef ENABLE_BENCHMARK
13
#include <benchmark/benchmark.h>
14
#endif
15

16
#ifdef _WIN32
17
#define WIN32_LEAN_AND_MEAN
18
#include "../Header_Windows.h"
19
#include <crtdbg.h>
20
#include <psapi.h>
21
#include <windows.h>  // for GetModuleFileName
22

23
#pragma comment( lib, "psapi.lib" )  // 32bit is a bit dumb..
24
#else
25
#endif
26
#include <clocale>
27
#include <cstdlib>
28
#include <exception>
29
#include <iostream>
30
#include <stdexcept>
31
#include <string>
32

33

34
namespace Pol::Clib
35
{
36
using namespace std;
37

38

39
// last resort: print backtrace on terminate
UNCOV
40
void terminate_handler()
×
41
{
42
  try
43
  {
UNCOV
44
    std::cerr << "Terminate failure:\n" << boost::stacktrace::stacktrace() << std::endl;
×
45
  }
UNCOV
46
  catch ( ... )
×
47
  {
UNCOV
48
  }
×
49
  std::abort();
×
50
}
51

52
///////////////////////////////////////////////////////////////////////////////
53

54
ProgramMain::ProgramMain() = default;
4,959✔
UNCOV
55
ProgramMain::~ProgramMain() = default;
×
56
///////////////////////////////////////////////////////////////////////////////
57

58
void ProgramMain::start( int argc, char* argv[] )
4,959✔
59
{
60
  using namespace Pol;
61
  Clib::Logging::LogFacility logger;
4,959✔
62
  Clib::Logging::initLogging( &logger );
4,959✔
63
  Clib::ExceptionParser::initGlobalExceptionCatching();
4,959✔
64
  std::set_terminate( &terminate_handler );
4,959✔
65

66
  std::setlocale( LC_TIME, "" );
4,959✔
67
  std::setlocale( LC_CTYPE, "en_US.UTF-8" );  // unicode aware strings, unsure if english is enough,
4,959✔
68
                                              // or if it needs to be a user defined value
69

70
  int exitcode = 0;
4,959✔
71

72
  try
73
  {
74
// FIXME: 2008 Upgrades needed here? Make sure this still valid on 2008
75
#if defined( _WIN32 ) && defined( _DEBUG ) && _MSC_VER >= 1300
76
    // on VS.NET, disable obnoxious heap checking
77
    int flags = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
78
    flags &= 0x0000FFFF;  // set heap check frequency to 0
79
    _CrtSetDbgFlag( flags );
80
#endif
81

82
    /**********************************************
83
     * store program arguments
84
     **********************************************/
85
    m_programArguments.clear();
4,959✔
86
    for ( int i = 0; i < argc; i++ )
27,261✔
87
    {
88
      m_programArguments.emplace_back( argv[i] );
22,302✔
89
    }
90

91
    /**********************************************
92
     * determine and store the executable name
93
     **********************************************/
94
    std::string binaryPath = argv[0];
4,959✔
95
#ifdef WINDOWS
96
    char modulePath[_MAX_PATH];
97
    if ( GetModuleFileName( nullptr, modulePath, sizeof modulePath ) )
98
      binaryPath = modulePath;
99
#endif
100
    PROG_CONFIG::configureProgramEnvironment( binaryPath );
4,959✔
101

102
#ifdef ENABLE_BENCHMARK
103
    benchmark::Initialize( &argc, argv );
104
#endif
105

106
    /**********************************************
107
     * MAIN
108
     **********************************************/
109
    exitcode = main();
4,959✔
110
  }
4,959✔
111
  catch ( const char* msg )
309✔
112
  {
UNCOV
113
    ERROR_PRINTLN( "Execution aborted due to: {}", msg );
×
114
    exitcode = 1;
×
115
  }
×
116
  catch ( std::string& str )
×
117
  {
UNCOV
118
    ERROR_PRINTLN( "Execution aborted due to: {}", str );
×
119
    exitcode = 1;
×
120
  }  // egcs has some trouble realizing 'exception' should catch
×
121
  catch ( std::runtime_error& re )  // runtime_errors, so...
309✔
122
  {
123
    ERROR_PRINTLN( "Execution aborted due to: {}", re.what() );
309✔
124
    exitcode = 1;
309✔
125
  }
309✔
UNCOV
126
  catch ( std::exception& ex )
×
127
  {
UNCOV
128
    ERROR_PRINTLN( "Execution aborted due to: {}", ex.what() );
×
129
    exitcode = 1;
×
130
  }
×
131
  catch ( int xn )
×
132
  {
133
    // Something that throws an integer is responsible for printing
134
    // its own error message.
135
    // "throw 3" is meant as an alternative to exit(3).
UNCOV
136
    exitcode = xn;
×
137
  }
×
138
#ifndef _WIN32
UNCOV
139
  catch ( ... )
×
140
  {
UNCOV
141
    ERROR_PRINTLN( "Execution aborted due to generic exception." );
×
142
    exitcode = 2;
×
143
  }
×
144
#endif
145
  Clib::Logging::global_logger->wait_for_empty_queue();
4,959✔
146

147
  exit( exitcode );
4,959✔
UNCOV
148
}
×
149

150
const std::vector<std::string>& ProgramMain::programArgs() const
14,968✔
151
{
152
  return m_programArguments;
14,968✔
153
}
154

155
bool ProgramMain::programArgsFind( const std::string& filter, std::string* rest ) const
7,943✔
156
{
157
  const std::vector<std::string>& binArgs = programArgs();
7,943✔
158
  for ( size_t i = 1; i < binArgs.size(); i++ )
19,853✔
159
  {
160
    const std::string& param = binArgs[i];
13,896✔
161
    switch ( param[0] )
13,896✔
162
    {
163
    case '/':
7,941✔
164
    case '-':
165
      if ( param.substr( 1, filter.size() ) == filter )
7,941✔
166
      {
167
        if ( rest != nullptr )
1,986✔
UNCOV
168
          *rest = param.substr( 1 + filter.size(), param.size() - ( 1 + filter.size() ) );
×
169
        return true;
1,986✔
170
      }
171
      break;
5,955✔
172
    default:
5,955✔
173
      break;
5,955✔
174
    }
175
  }
176
  return false;
5,957✔
177
}
178

179
std::string ProgramMain::programArgsFindEquals( const std::string& filter,
84✔
180
                                                std::string defaultVal ) const
181
{
182
  const std::vector<std::string>& binArgs = programArgs();
84✔
183
  for ( size_t i = 1; i < binArgs.size(); i++ )
361✔
184
  {
185
    const std::string& param = binArgs[i];
325✔
186
    if ( param.substr( 0, filter.size() ) == filter )
325✔
187
      return param.substr( filter.size(), param.size() - ( filter.size() ) );
48✔
188
  }
189
  return defaultVal;
36✔
190
}
191

192
int ProgramMain::programArgsFindEquals( const std::string& filter, int defaultVal,
58✔
193
                                        bool hexVal ) const
194
{
195
  std::string val = programArgsFindEquals( filter, "" );
58✔
196
  if ( val.empty() )
58✔
197
    return defaultVal;
36✔
198
  return strtoul( val.c_str(), nullptr, hexVal ? 16 : 10 );
22✔
199
}
58✔
200
}  // namespace Pol::Clib
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc