Skip to content

Instantly share code, notes, and snippets.

@ivankra
Created June 16, 2011 00:17
Show Gist options
  • Save ivankra/1028443 to your computer and use it in GitHub Desktop.
Save ivankra/1028443 to your computer and use it in GitHub Desktop.
ekobug.cc
#include <stdio.h>
#include <string.h>
namespace NStl {
template <class _Tp> struct __stlport_class {};
template <class _Tp, class _Allocator> struct _Alloc_traits {
typedef typename _Allocator::template rebind<_Tp> _Rebind_type;
typedef typename _Rebind_type::other allocator_type;
};
template <class _Tp> class allocator : public __stlport_class<allocator<_Tp> > {
public:
typedef _Tp value_type;
template <class _Tp1> struct rebind {
typedef allocator<_Tp1> other;
};
};
template <class _Value, class _Tp, class _MaybeReboundAlloc> class _STLP_alloc_proxy : public _MaybeReboundAlloc {
public:
_Value _M_data;
};
template <class _CharT, class _IntT> class __char_traits_base {};
template <class _CharT> class char_traits : public __char_traits_base<_CharT, _CharT> {};
template <class _CharT, class _Traits = char_traits<_CharT>, class _Alloc = allocator<_CharT> > class basic_string;
typedef basic_string<char, char_traits<char>, allocator<char> > string;
template <class _Tp, class _Alloc> class _String_base {
public:
enum { _DEFAULT_SIZE = 16 };
typedef typename _Alloc_traits<_Tp, _Alloc>::allocator_type allocator_type;
typedef _STLP_alloc_proxy<_Tp*, _Tp, allocator_type> _AllocProxy;
protected:
union _Buffers {
_Tp* _M_dynamic_buf;
_Tp _M_static_buf[_DEFAULT_SIZE];
} _M_buffers;
protected:
bool _M_using_static_buf() const {
return (_M_end_of_storage._M_data == _M_buffers._M_static_buf + _DEFAULT_SIZE);
}
_Tp const* _M_Start() const {
return _M_using_static_buf() ? _M_buffers._M_static_buf : _M_buffers._M_dynamic_buf;
}
_Tp* _M_finish;
_AllocProxy _M_end_of_storage;
};
template <class _CharT, class _Traits, class _Alloc> class basic_string : protected _String_base<_CharT,_Alloc> {
protected:
typedef _String_base<_CharT,_Alloc> _Base;
typedef basic_string<_CharT, _Traits, _Alloc> _Self;
public:
typedef typename _Base::allocator_type allocator_type;
basic_string(const _Self&);
basic_string(const _CharT* __s, const allocator_type& __a = allocator_type()) {
strcpy(this->_M_buffers._M_static_buf, __s);
this->_M_end_of_storage._M_data = this->_M_buffers._M_static_buf + 16;
}
public:
const _CharT* c_str() const { return this->_M_Start(); }
};
}
using NStl::string;
struct FsmCodeGen {
int out;
virtual ~FsmCodeGen() {}
virtual int &STATIC_VAR(string type, string name) = 0;
};
struct CCodeGen : virtual public FsmCodeGen {
virtual int &STATIC_VAR(string type, string name);
};
int &CCodeGen::STATIC_VAR(string type, string name) {
printf("type=%s name=%s\n", type.c_str(), name.c_str());
return out;
}
int main() {
FsmCodeGen *g = new CCodeGen();
g->STATIC_VAR("int", "start");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment