Skip to content

Instantly share code, notes, and snippets.

@cgdangelo
Created March 20, 2018 17:48
Show Gist options
  • Save cgdangelo/06015dc663fdff3b012358a6d683a324 to your computer and use it in GitHub Desktop.
Save cgdangelo/06015dc663fdff3b012358a6d683a324 to your computer and use it in GitHub Desktop.
#include "Event.h"
namespace simfantasy {
namespace events {
Event::Event(Simulation *simulation) : simulation(simulation) {}
}
}
#ifndef SIMFANTASY_EVENT_H
#define SIMFANTASY_EVENT_H
#include <chrono>
#include "Simulation.h"
namespace simfantasy {
namespace events {
using std::chrono::high_resolution_clock;
using simfantasy::simulator::Simulation;
class Event {
public:
explicit Event(Simulation *simulation);
inline high_resolution_clock::time_point timestamp() const {
return timestamp_;
}
inline void Unschedule() {
unscheduled_ = true;
}
inline bool unscheduled() const {
return unscheduled_;
}
private:
Simulation *simulation;
high_resolution_clock::time_point timestamp_;
bool unscheduled_;
};
}
}
#endif //SIMFANTASY_EVENT_H
#include "Simulation.h"
namespace simfantasy {
namespace simulator {
inline bool event_cmp(const Event *lhs, const Event *rhs) {
return lhs->timestamp() > rhs->timestamp();
}
Simulation::Simulation() : events(event_queue(event_cmp)) {}
void Simulation::Run() {
start_time_ = current_time_ = high_resolution_clock::now();
}
}
}
#ifndef SIMFANTASY_SIMULATION_H
#define SIMFANTASY_SIMULATION_H
#include <chrono>
#include <queue>
#include <functional>
#include "Event.h"
namespace simfantasy {
namespace simulator {
using std::chrono::high_resolution_clock;
using std::priority_queue;
using std::deque;
using std::function;
using simfantasy::events::Event;
using event_queue = priority_queue<Event *, deque<Event *>, function<bool(Event *, Event *)>>;
class Simulation {
public:
Simulation();
void Run();
private:
high_resolution_clock::time_point current_time_;
event_queue events;
high_resolution_clock::time_point start_time_;
};
}
}
#endif //SIMFANTASY_SIMULATION_H
@cgdangelo
Copy link
Author

[ 25%] Building CXX object CMakeFiles/SimFantasy.dir/main.cc.obj
[ 50%] Building CXX object CMakeFiles/SimFantasy.dir/Simulation.cc.obj
[ 75%] Building CXX object CMakeFiles/SimFantasy.dir/Event.cc.obj
In file included from C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.h:8:0,
                 from C:\Users\cgdangelo\CLionProjects\SimFantasy\main.cc:1:
C:\Users\cgdangelo\CLionProjects\SimFantasy\Event.h:11:19: error: 'simfantasy::simulator' has not been declared
 using simfantasy::simulator::Simulation;
                   ^~~~~~~~~
C:\Users\cgdangelo\CLionProjects\SimFantasy\Event.h:15:29: error: expected ')' before '*' token
   explicit Event(Simulation *simulation);
                             ^
C:\Users\cgdangelo\CLionProjects\SimFantasy\Event.h:30:3: error: 'Simulation' does not name a type
   Simulation *simulation;
   ^~~~~~~~~~
In file included from C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.h:8:0,
                 from C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.cc:1:
C:\Users\cgdangelo\CLionProjects\SimFantasy\Event.h:11:19: error: 'simfantasy::simulator' has not been declared
 using simfantasy::simulator::Simulation;
                   ^~~~~~~~~
C:\Users\cgdangelo\CLionProjects\SimFantasy\Event.h:15:29: error: expected ')' before '*' token
   explicit Event(Simulation *simulation);
                             ^
C:\Users\cgdangelo\CLionProjects\SimFantasy\Event.h:30:3: error: 'Simulation' does not name a type
   Simulation *simulation;
   ^~~~~~~~~~
mingw32-make.exe[2]: *** [CMakeFiles\SimFantasy.dir\build.make:62: CMakeFiles/SimFantasy.dir/main.cc.obj] Error 1
mingw32-make.exe[2]: *** Waiting for unfinished jobs....
mingw32-make.exe[2]: *** [CMakeFiles\SimFantasy.dir\build.make:86: CMakeFiles/SimFantasy.dir/Simulation.cc.obj] Error 1
In file included from C:\Users\cgdangelo\CLionProjects\SimFantasy\Event.h:6:0,
                 from C:\Users\cgdangelo\CLionProjects\SimFantasy\Event.cc:1:
C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.h:17:19: error: 'simfantasy::events' has not been declared
 using simfantasy::events::Event;
                   ^~~~~~
C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.h:18:36: error: 'Event' was not declared in this scope
 using event_queue = priority_queue<Event *, deque<Event *>, function<bool(Event *, Event *)>>;
                                    ^~~~~
C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.h:18:51: error: 'Event' was not declared in this scope
 using event_queue = priority_queue<Event *, deque<Event *>, function<bool(Event *, Event *)>>;
                                                   ^~~~~
C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.h:18:58: error: template argument 1 is invalid
 using event_queue = priority_queue<Event *, deque<Event *>, function<bool(Event *, Event *)>>;
                                                          ^
C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.h:18:58: error: template argument 2 is invalid
C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.h:18:75: error: 'Event' was not declared in this scope
 using event_queue = priority_queue<Event *, deque<Event *>, function<bool(Event *, Event *)>>;
                                                                           ^~~~~
C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.h:18:84: error: 'Event' was not declared in this scope
 using event_queue = priority_queue<Event *, deque<Event *>, function<bool(Event *, Event *)>>;
                                                                                    ^~~~~
C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.h:18:91: error: expression list treated as compound expression in functional cast [-fpermissive]
 using event_queue = priority_queue<Event *, deque<Event *>, function<bool(Event *, Event *)>>;
                                                                                           ^
C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.h:18:92: error: template argument 1 is invalid
 using event_queue = priority_queue<Event *, deque<Event *>, function<bool(Event *, Event *)>>;
                                                                                            ^~
C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.h:18:61: error: template argument 1 is invalid
 using event_queue = priority_queue<Event *, deque<Event *>, function<bool(Event *, Event *)>>;
                                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.h:18:61: error: template argument 2 is invalid
C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.h:18:61: error: template argument 3 is invalid
C:\Users\cgdangelo\CLionProjects\SimFantasy\Simulation.h:28:3: error: 'event_queue' does not name a type
   event_queue events;
   ^~~~~~~~~~~
mingw32-make.exe[2]: *** [CMakeFiles\SimFantasy.dir\build.make:110: CMakeFiles/SimFantasy.dir/Event.cc.obj] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:67: CMakeFiles/SimFantasy.dir/all] Error 2
mingw32-make.exe: *** [Makefile:83: all] Error 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment