The Sparta Modeling Framework
Loading...
Searching...
No Matches
main.cpp
1// <main.cpp> -*- C++ -*-
2
3
4#include <iostream>
5
6#include "SkeletonSimulator.hpp" // Core model skeleton simulator
7
8#include "sparta/parsers/ConfigEmitterYAML.hpp"
11#include "sparta/sparta.hpp"
12
13// User-friendly usage that correspond with
14// sparta::app::CommandLineSimulator options
15const char USAGE[] =
16 "Usage:\n"
17 " [--num-producers <count>] # Default is 1\n" // The number of producers in the skeleton
18 " [-v]\n"
19 " [-h] <data file1> <data file2> ...\n"
20 "\n";
21
22constexpr char VERSION_VARNAME[] = "version"; // Name of option to show version
23constexpr char DATA_FILE_VARNAME[] = "data-file"; // Name of data file given at the end of command line
24constexpr char DATA_FILE_OPTIONS[] = "data-file"; // Data file options, which are flag independent
25
26int main(int argc, char **argv)
27{
28 std::vector<std::string> datafiles;
29
31 DEFAULTS.auto_summary_default = "on";
32
33 // try/catch block to ensure proper destruction of the cls/sim classes in
34 // the event of an error
35 try{
36 // Helper class for parsing command line arguments, setting up
37 // the simulator, and running the simulator. All of the things
38 // done by this classs can be done manually if desired. Use
39 // the source for the CommandLineSimulator class as a starting
40 // point
41 sparta::app::CommandLineSimulator cls(USAGE, DEFAULTS);
42 auto & app_opts = cls.getApplicationOptions();
43 app_opts.add_options()
44 (VERSION_VARNAME,
45 "produce version message",
46 "produce version message") // Brief
47 ("verbose,v", "Be noisy.", "Be very, very noisy")
48 (DATA_FILE_OPTIONS,
49 sparta::app::named_value<std::vector<std::string>>("DATAFILES", &datafiles),
50 "Specifies the data files to look at") // example, not used
51 ;
52
53 // Add any positional command-line options -- skeleton
54 po::positional_options_description& pos_opts = cls.getPositionalOptions();
55 pos_opts.add(DATA_FILE_VARNAME, -1); // skeleton, look for the <data file> at the end
56
57 // Parse command line options and configure simulator
58 int err_code = 0;
59 if(!cls.parse(argc, argv, err_code)){
60 return err_code; // Any errors already printed to cerr
61 }
62
63 for(auto & i : datafiles) {
64 std::cout << "Got this data file: " << i << std::endl;
65 }
66
67 bool be_noisy = false;
68 auto& vm = cls.getVariablesMap();
69 if(vm.count("verbose")){
70 be_noisy = true;
71 }
72
73 // Create the simulator object for population -- does not
74 // instantiate nor run it.
75 sparta::Scheduler scheduler;
76 SkeletonSimulator sim(scheduler, be_noisy);
77
78 cls.populateSimulation(&sim);
79 cls.runSimulator(&sim);
80 cls.postProcess(&sim);
81
82 }catch(...){
83 // Could still handle or log the exception here
84 throw;
85 }
86
87 return 0;
88}
Class for creating a simulator based on command-line arguments.
Wrapper for boost program_options option_description that allows multiple levels of detail.
SkeletonSimulator which builds the model and configures it.
A class that lets you schedule events now and in the future.
Command line simulator front-end class with argument parsing Works in conjunction with sparta::app::S...
Optional default values for the simulator which can be customized and provided by anyone instantiatin...