#ifndef REFLECTION_H #define REFLECTION_H ///////////////////////////////////////////////////////////////////// // reflection.h - Getting started with reflection mechanism // // // // Language: Visual Studio 2005 C++ // // Platform: Dell Dimension 9150, Windows XP Pro, SP 2 // // Application: Prototype for CSE687 Project #4b - Reflection // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////////// #include #include #include #include /////////////////////////////////////////////////////////// // Telling Windows to export definitions from this module // // Note: the library project defines DLL_LIB, users don't #ifdef DLL_LIB #define REFLAPI _declspec(dllexport) #else #define REFLAPI _declspec(dllimport) #endif /////////////////////////////////////////////////////////// // Defining a data structure to hold reflection information typedef std::set sets; typedef std::multiset msets; typedef std::list Params; // order is important typedef std::multimap Methods; // overloads typedef std::map Types; // types are unique /////////////////////////////////////////////////////////// // The reflector class does all the work class REFLAPI reflector { public: reflector(); reflector* Create(); virtual ~reflector() {} sets getTypes(); msets getMethods(const std::string& type); Params getParams(const std::string& type, const std::string& method); template std::string show(const std::string& msg, const T& stuff); protected: Types types; }; reflector* reflector::Create() { return new reflector; } class REFLAPI gateway { public: gateway() : n(0) {} virtual ~gateway() {} static gateway* Create() { return new gateway; } virtual int& value() { return n; } virtual void say() { std::cout << "\n hi from gateway, with value " << value(); } private: int n; }; /////////////////////////////////////////////////////////// // Define global C functions to get unmangled names extern "C" { REFLAPI const char* GetTypes(); } extern "C" { REFLAPI const char* GetMethods(const char* type); } extern "C" { REFLAPI const char* GetParams(const char* type, const char* method); } #endif