Skip to content

Instantly share code, notes, and snippets.

#pragma once
#include <vector>
#include <memory>
namespace fsm
{
class StateMachine;
var gulp = require('gulp');
var util = require('gulp-util');
var clean = require('gulp-clean');
var jshint = require('gulp-jshint');
var less = require('gulp-less');
var cssnano = require('gulp-cssnano');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
var browserify = require('browserify');
// This is how the implementation should work:
int main()
{
example_handler handler;
concrete_manager manager;
manager.add_handler(handler);
manager.poll_events();
// events are created and sent to the handler automagically!
}
/*
IDEAS
http://juanchopanzacpp.wordpress.com/2013/02/24/simple-observer-pattern-implementation-c11/
http://anki3d.org/cxx11-variadic-templates-part1/
http://stackoverflow.com/questions/11796121/implementing-the-visitor-pattern-using-c-templates
http://siondream.com/blog/tag/c11/
*/
#include <iostream>
@arvidsson
arvidsson / gist:9206410
Created February 25, 2014 10:23
C++ Listener Pattern Example
class Button : public Notifier
{
public:
void press()
{
notify();
}
};
class TextBox : public IListener
@arvidsson
arvidsson / gist:9206400
Created February 25, 2014 10:22
C++ Listener Pattern
#include <iostream>
#include <set>
#include <algorithm>
class IListener
{
public:
virtual void handleNotification() = 0;
};
@arvidsson
arvidsson / reverse_iterate.hpp
Last active June 22, 2017 13:26
Reverse iteration in C++11 range-based for loops.
// public domain
#ifndef INCLUDED_REVERSE_ITERATE_HPP
#define INCLUDED_REVERSE_ITERATE_HPP
/*
Template used for reverse iteration in C++11 range-based for loops.
std::vector<int> v = {1, 2, 3, 4, 5};
for (auto x : reverse_iterate(v))
@arvidsson
arvidsson / Singleton.hpp
Last active December 26, 2015 23:38
Singleton pattern template.
#ifndef INCLUDED_SINGLETON_HPP
#define INCLUDED_SINGLETON_HPP
/*
Singleton pattern template. Only allows one instance of the object to exist.
NOTE: Manual destruction must be done before program exit. Not thread-safe.
class Foo : public Singleton<Foo> {};
Foo &foo = Foo::getRef();
foo.bar();
@arvidsson
arvidsson / Multiton.hpp
Last active December 26, 2015 23:39
Multiton pattern template.
#ifndef INCLUDED_MULTITON_HPP
#define INCLUDED_MULTITON_HPP
#include <map>
#include <string>
/*
Multiton pattern template. It's similar to the singleton pattern, but
enables multiple instances through the use of keys.
NOTE: Manual destruction must be done before program exit. Not thread-safe.