我有一个名为 Pagemanager 的函数类,它是这样的
class Page : public Ipage //Ipage is abstract with pure virtual function
{
public:
page(void);
~page(void);
virtual int FillDbgPage(char* sz, unsigned int max_bytes,
char* arg1, char* arg2, char* arg3, char* arg4){return 0;}
};
//Pagemanager.h
class pageManager : public IPage
{
public:
pageManager(void);
~pageManager(void);
//client calls this function to register himself as a page content owners
void registerPage(char* PageName, Page* PagePtr)
//webserver calls this function to request page update
int FillDbgPage(char* sz, unsigned int max_bytes,
char* arg1, char* arg2, char* arg3, char* arg4);
Private:
char name[10]; //stores the name of the page
Ipage* storePagePtr; //stores the address of the page
};
//pageManager.cpp
int pageManager::FillDbgPage(char* sz, unsigned int max_bytes, char* arg1,
char* arg2, char* arg3, char* arg4)
{
if(arg4!=NULL)
{
if (strcmp(arg4, name)==0)
{
cout<<"Page"<<arg4<<"Found"<<endl;
if(storePagePtr==Null)
cout<<"storePagePtr not initialized"<<endl;
else
int len = storePagePtr->FillDbgPage(sz, max_bytes, arg1, arg2, arg3, arg4);
else
cout<<"Sorry"<<arg4<<not found!<<endl;
else
{
strcat(sz, ("<a href = http://127.0.0.1/dbg_image_pipe?arg4="));
strcat(sz, name);
strcat(sz,">");
strcat(sz, name);
strcat)sz, "<br>");
strcat(sz, ("</a>\n"));
}
return strlen(sz);
}
void pageManager::RegisterPage(char* PageName, Page *PagePtr)
{
storePagePtr= PagePtr;
strcpy(name, PageName);
}
//this is code from cpp file which will be done by end users for example
pageManager systemRegister;
class myPage1 : public Page
{
public:
virtual int FillDbgPage(char* sz, unsigned int max_bytes, char* arg1,
char* arg2, char* arg3, char* arg4)
{
//sample content that user will print in the page he created
sprintf(sz, "Hello World"! <br> This is my page!);
return strlen(sz);
}
myPage1 Page1;
void module1_initialize()
{
systemRegister.RegisterPage("Page1", &Page1);
}
问题是现在创建了 1 页,它存储在 name 和 sotrePagePtr 中,但是如果有 4 页,我该怎么办。假设用户想要 4 个不同的文件,我如何正确保存它们以便将来显示它们变得更容易