Skip to content

Instantly share code, notes, and snippets.

@DineshDevaraj
Last active March 22, 2017 16:36
Show Gist options
  • Save DineshDevaraj/b68f17ea1dd62bde15c033ea700d1f77 to your computer and use it in GitHub Desktop.
Save DineshDevaraj/b68f17ea1dd62bde15c033ea700d1f77 to your computer and use it in GitHub Desktop.
/* Date : 22 Mar 2017 - Wed */
struct ContentViewer_t;
struct ContentEngine_t;
struct RenderingEngine_t;
struct Callable_t
{
virtual void callback() = 0;
};
struct ContentEngine_t : Callable_t
{
Callable_t *cview, *reng;
virtual void SaySomething() = 0;
virtual void TalkWithREng() = 0;
virtual void TalkWithCView() = 0;
virtual void SetContentViewer(Callable_t *) = 0;
virtual void SetRenderingEngine(Callable_t *) = 0;
};
struct HTMLContentEngine_t : ContentEngine_t
{
/* function to talk to content
engine from rendering engine */
void callback() { /* do something */ }
void SetContentViewer(Callable_t *ptr) { cview=ptr; }
void SetRenderingEngine(Callable_t *ptr) { reng=ptr; }
void SaySomething() { /* do something */ }
void TalkWithCView() { cview->callback(); }
void TalkWithREng() { reng->callback(); }
};
struct TextContentEngine_t : ContentEngine_t
{
/* function to talk to content
engine from rendering engine */
void callback() { /* do something */ }
void SetContentViewer(Callable_t *ptr) { cview=ptr; }
void SetRenderingEngine(Callable_t *ptr) { reng=ptr; }
void SaySomething() { /* do something */ }
void TalkWithCView() { cview->callback(); }
void TalkWithREng() { reng->callback(); }
};
struct RenderingEngine_t : Callable_t
{
Callable_t *cview, *ceng;
virtual void SaySomething() = 0;
virtual void TalkWithCEng() = 0;
virtual void TalkWithCView() = 0;
virtual void SetContentEngine(Callable_t *) = 0;
virtual void SetContentViewer(Callable_t *) = 0;
};
struct HTMLRenderingEngine_t : RenderingEngine_t
{
/* Function to talk to redering
engine from content engine */
void callback() { /* do something */ }
void SetContentEngine(Callable_t *ptr) { ceng=ptr; }
void SetContentViewer(Callable_t *ptr) { cview=ptr; }
void SaySomething() { /* do something */ }
void TalkWithCView() { cview->callback(); }
void TalkWithCEng() { ceng->callback(); }
};
struct TextRenderingEngine_t : RenderingEngine_t
{
/* Function to talk to redering
engine from content engine */
void callback() { /* do something */ }
void SetContentEngine(Callable_t *ptr) { ceng=ptr; }
void SetContentViewer(Callable_t *ptr) { cview=ptr; }
void SaySomething() { /* do something */ }
void TalkWithCView() { cview->callback(); }
void TalkWithCEng() { ceng->callback(); }
};
struct FileType
{
enum Values { Html = 'h', Text = 't' };
};
typedef FileType::Values FileType_t;
struct ContentViewer_t : Callable_t
{
ContentEngine_t *ceng;
RenderingEngine_t *reng;
void callback() { /* do something */ }
ContentViewer_t(FileType_t fileType)
{
if(FileType::Html == fileType)
{
ceng = new HTMLContentEngine_t;
reng = new HTMLRenderingEngine_t;
}
else if(FileType::Text == fileType)
{
ceng = new TextContentEngine_t;
reng = new TextRenderingEngine_t;
}
ceng->SetRenderingEngine(reng);
reng->SetContentEngine(ceng);
}
void TalkWithOthers()
{
ceng->SaySomething();
reng->SaySomething();
}
~ContentViewer_t()
{
delete ceng;
delete reng;
}
};
int main(int argc, char *argv[])
{
ContentViewer_t cview(FileType_t(*argv));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment