File: application.h

package info (click to toggle)
embree 3.13.5%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 27,924 kB
  • sloc: cpp: 180,815; xml: 3,877; ansic: 2,957; python: 1,466; sh: 502; makefile: 229; csh: 42
file content (127 lines) | stat: -rw-r--r-- 3,818 bytes parent folder | download
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "../default.h"

namespace embree
{
  void waitForKeyPressedUnderWindows();
  
  struct CommandLineParser
  {
    enum Verbosity {
      NORMAL = 0,
      SILENT
    };
    
    CommandLineParser(Verbosity verbosity = NORMAL) : verbosity(verbosity) {}

    /* virtual interface for command line option processing */
    struct CommandLineOption : public RefCount 
    {
      CommandLineOption (const std::string& description) 
        : description(description) {}

      virtual void parse(Ref<ParseStream> cin, const FileName& path) = 0;
      
      std::string description;
    };

    /* helper class to provide parsing function via lambda function */
    template<typename F>
    struct CommandLineOptionClosure : public CommandLineOption
    {
      CommandLineOptionClosure (std::string description, const F& f) 
        : CommandLineOption(description), f(f) {}
      
      virtual void parse(Ref<ParseStream> cin, const FileName& path) {
        f(cin,path);
      }
      
      F f;
    };

    /* registers a command line option */
    template<typename F>
      void registerOption(const std::string& name, const F& f, const std::string& description) 
    {
      Ref<CommandLineOption> closure = new CommandLineOptionClosure<F>(description,f);
      commandLineOptionList.push_back(closure);
      commandLineOptionMap[name] = closure;
    }

    /* registers an alias for a command line option */
    void registerOptionAlias(const std::string& name, const std::string& alternativeName); 
    
    /* command line parsing */
    void parseCommandLine(int argc, char** argv);
    void parseCommandLine(Ref<ParseStream> cin, const FileName& path);

    /* prints help for all supported command line options */
    void printCommandLineHelp();

    /* command line options database */
    std::vector<         Ref<CommandLineOption> > commandLineOptionList;
    std::map<std::string,Ref<CommandLineOption> > commandLineOptionMap;
    
    Verbosity verbosity;
  };
 
  class Application
  {
  public:
    enum Features { FEATURE_RTCORE = 1, FEATURE_STREAM = 2 };

    Application (int features);
    virtual ~Application();

    static Application* instance;
    
    /* print log message */
    void log(int verbose, const std::string& str);
    
    template<typename F>
    void registerOption(const std::string& name, const F& f, const std::string& description) {
      commandLineParser.registerOption<F>(name, f, description);
    }
    
    /* registers an alias for a command line option */
    void registerOptionAlias(const std::string& name, const std::string& alternativeName) {
      commandLineParser.registerOptionAlias(name, alternativeName);
    }
    
    /* command line parsing */
    void parseCommandLine(int argc, char** argv) {
      commandLineParser.parseCommandLine(argc, argv);
    }

    void parseCommandLine(Ref<ParseStream> cin, const FileName& path) {
      commandLineParser.parseCommandLine(cin, path);
    }

    /* prints help for all supported command line options */
    void printCommandLineHelp() {
      commandLineParser.printCommandLineHelp();
    }
 
  public:

    /* virtual main function, contains all tutorial logic */
    virtual int main(int argc, char** argv) = 0;

  public:
    std::string rtcore;      // embree configuration
    int verbosity;           // verbosity of output
    
    CommandLineParser commandLineParser;

  public:
    bool log_delta;       // whether to print delta stats
    double start_time;       // start time of application
    double last_time;        // last log time of application
    ssize_t last_virtual_memory; // last virtual memory usage
    ssize_t last_resident_memory; // last resident memory usage
  };
}