Skip to content

Instantly share code, notes, and snippets.

@apathyboy
Created December 1, 2010 23:05
Show Gist options
  • Save apathyboy/724412 to your computer and use it in GitHub Desktop.
Save apathyboy/724412 to your computer and use it in GitHub Desktop.
Just a few ideas regarding events, no comments really however, just check out the main function and go from there. should compile as is in vc2010 in a new empty project.
/** This is a test application to explore ideas about an improved event
* implementation.
*
* \author Eric Barr <eric.barr@anhstudios.com>
*/
#include <cstdint>
#include <iostream>
#include <memory>
#include <string>
namespace anh {
class byte_buffer {
};
class hash_string {
public:
hash_string(const char* string)
: hash_(string) {}
const std::string& str() const { return hash_; }
private:
std::string hash_;
};
namespace event_dispatcher {
template<class T>
class basic_event : public T {
public:
basic_event()
: type_string_(T::type()) {}
basic_event(const anh::hash_string& type_string )
: type_string_(type_string) {}
const anh::hash_string& type() { return type_string_; }
private:
anh::hash_string type_string_;
};
struct null_data {};
typedef basic_event<null_data> simple_event;
} // event_dispatcher
} // anh
std::ostream& operator<<(std::ostream& os, const anh::hash_string& hash) {
os << hash.str();
return os;
}
namespace swg {
namespace protocol {
namespace messages {
class burst_run_end_data {
public:
burst_run_end_data()
: player_id_(0)
, start_time_(0)
, duration_(0) {}
const anh::hash_string& type() const { static anh::hash_string type("burst_run_end"); return type; }
uint64_t player_id() const { return player_id_; }
void player_id(uint64_t player_id) { player_id_ = player_id; }
uint64_t start_time() const { return start_time_; }
void start_time(uint64_t start_time) { start_time_ = start_time; }
uint64_t duration() const { return duration_; }
void duration(uint64_t duration) { duration_ = duration; }
private:
uint64_t player_id_;
uint64_t start_time_;
uint64_t duration_;
};
class burst_run_cooldown_data {};
}
typedef anh::event_dispatcher::basic_event<messages::burst_run_end_data> burst_run_end_event;
}} // swg::protocol::messages
using namespace anh::event_dispatcher;
using namespace swg::protocol;
using std::cout;
int main() {
simple_event my_event("my_simple_event");
cout << "event type [" << my_event.type() << "]\n";
burst_run_end_event burst_event;
burst_event.duration(16);
cout << "event type [" << burst_event.type() << "]\n";
cout << "event type [" << burst_event.duration() << "]\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment