home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 January / dppcpro0199a.iso / January / Fp98 / SDK / WebBot / webbot.h < prev   
Encoding:
C/C++ Source or Header  |  1997-09-18  |  6.5 KB  |  269 lines

  1. /*
  2.  * webbot.h: definitions for custom WebBots(tm) in FrontPage 2.0
  3.  * 
  4.  * Copyright (c) 1996 Microsoft Corporation.  All rights reserved.
  5.  *
  6.  * Note: This header requires an ANSI-C or a C++ compiler.
  7.  */
  8.  
  9. #ifndef WEBBOT_H
  10. #define WEBBOT_H
  11.  
  12.  
  13. struct WebBotDict;
  14. typedef struct WebBotDict WebBotDict;
  15. struct WebBotString;
  16. typedef struct WebBotString WebBotString;
  17.  
  18.  
  19. #ifdef WEBBOT_V11_COMPAT
  20. #define DictNumValues DictOldNumValues
  21. #define DictGetValue  DictOldGetValue
  22. #define DictGetValueN DictOldGetValueN
  23. #define DictSetValue  DictOldSetValue
  24. #define DictNextKey   DictOldNextKey
  25. #else
  26. #define DictNumValues DictNewNumValues
  27. #define DictGetValue  DictNewGetValue
  28. #define DictGetValueN DictNewGetValueN
  29. #define DictSetValue  DictNewSetValue
  30. #define DictSetValueN DictNewSetValueN
  31. #define DictNextKey   DictNewNextKey
  32. #define DictRemoveKey DictNewRemoveKey
  33. #endif
  34.  
  35.  
  36. struct WebBotFuncs
  37. {
  38.     /* Old Dict methods */
  39.     long (*DictOldNumValues)
  40.         (WebBotDict* dict,
  41.          const char* key);
  42.     const char* (*DictOldGetValue)
  43.         (WebBotDict* dict,
  44.          const char* key);
  45.     const char* (*DictOldGetValueN)
  46.         (WebBotDict* dict,
  47.          const char* key,
  48.          short valueNum);
  49.     void (*DictOldSetValue)
  50.         (WebBotDict* dict,
  51.          const char* key,
  52.          const char* value);
  53.     void (*DictReset)                   /* This one is current */
  54.         (WebBotDict* dict);
  55.     const char* (*DictOldNextKey)
  56.         (WebBotDict* dict);
  57.  
  58.     /* String methods */
  59.     void (*StringClear)
  60.         (WebBotString* string);
  61.     void (*StringAppendTo)
  62.         (WebBotString* string, const char* stringToAppend);
  63.     const char* (*StringGetContents)
  64.         (WebBotString* string);
  65.  
  66.     /* New Dict methods */
  67.     long (*DictNewNumValues)
  68.         (WebBotDict* dict,
  69.          const char* key);
  70.     const char* (*DictNewGetValue)
  71.         (WebBotDict* dict,
  72.          const char* key);
  73.     const char* (*DictNewGetValueN)
  74.         (WebBotDict* dict,
  75.          const char* key,
  76.          short valueNum);
  77.     void (*DictNewSetValue)
  78.         (WebBotDict* dict,
  79.          const char* key,
  80.          const char* value);
  81.     void (*DictNewSetValueN)
  82.         (WebBotDict* dict,
  83.          const char* key,
  84.          const char* value,
  85.          short valueNum);
  86.     const char* (*DictNewNextKey)
  87.         (WebBotDict* dict);
  88.     void (*DictNewRemoveKey)
  89.         (WebBotDict* dict,
  90.          const char* key);
  91. };
  92.  
  93. typedef struct WebBotFuncs WebBotFuncs;
  94.  
  95.  
  96. #ifdef WIN32
  97. #define WEBBOT_EXPORT _declspec(dllexport) 
  98. #else
  99. #define WEBBOT_EXPORT /* nothing */
  100. #endif
  101.  
  102. #if defined(_AFXDLL) || defined(_AFXEXT)
  103. #define WEBBOT_MANAGE_STATE AFX_MANAGE_STATE(AfxGetStaticModuleState());
  104. #else
  105. #define WEBBOT_MANAGE_STATE /* nothing */
  106. #endif
  107.  
  108.  
  109. #ifdef __cplusplus
  110.  
  111. class CWebBotDict
  112. {
  113. public:
  114.     CWebBotDict
  115.         (WebBotDict*   dict,
  116.          const WebBotFuncs*  funcs)
  117.     {
  118.         Funcs = funcs;
  119.         Dict  = dict;
  120.     }
  121.  
  122.     long NumValues
  123.         (const char* key) const
  124.     {
  125.         return ((*Funcs->DictNumValues)(Dict, key));
  126.     }
  127.  
  128.     const char* GetValue
  129.         (const char* key) const
  130.     {
  131.         return ((*Funcs->DictGetValue)(Dict, key));
  132.     }
  133.  
  134.     const char* GetValueN
  135.         (const char* key,
  136.          short valueNum) const
  137.     {
  138.         return ((*Funcs->DictGetValueN)(Dict, key, valueNum));
  139.     }
  140.  
  141.     void SetValue
  142.         (const char *key,
  143.          const char *value)
  144.     {
  145.         ((*Funcs->DictSetValue)(Dict, key, value));
  146.     }
  147.  
  148. #ifndef WEBBOT_V11_COMPAT
  149.     void SetValueN
  150.         (const char* key,
  151.          const char* value,
  152.          short valueNum)
  153.     {
  154.         (*Funcs->DictSetValueN)(Dict, key, value, valueNum);
  155.     }
  156.  
  157.     void RemoveKey(const char* key)
  158.     {
  159.         (*Funcs->DictRemoveKey)(Dict, key);
  160.     }
  161. #endif
  162.  
  163.     void Reset()
  164.     {
  165.         (*Funcs->DictReset)(Dict);
  166.     }
  167.  
  168.     const char* NextKey()
  169.     {
  170.         return ((*Funcs->DictNextKey)(Dict));
  171.     }
  172.  
  173. private:
  174.     const WebBotFuncs*  Funcs;
  175.     WebBotDict*         Dict;
  176. };
  177.  
  178.  
  179. class CWebBotString
  180. {
  181. public:
  182.     CWebBotString
  183.         (WebBotString*       string,
  184.          const WebBotFuncs*  funcs)
  185.     {
  186.         Funcs  = funcs;
  187.         String = string;
  188.     }
  189.  
  190.     void Clear()
  191.     {
  192.         (*Funcs->StringClear)(String);
  193.     }
  194.  
  195.     void Append
  196.         (const char* stringToAppend)
  197.     {
  198.         (*Funcs->StringAppendTo)(String, stringToAppend);
  199.     }
  200.  
  201.     const char* GetContents() const
  202.     {
  203.         return ((*Funcs->StringGetContents)(String));
  204.     }
  205.  
  206. private:
  207.     const WebBotFuncs*  Funcs;
  208.     WebBotString*       String;
  209. };
  210.  
  211.  
  212. //
  213. // Original Bot Interface function macro in 1.1 WebBot SDK
  214. //
  215. #define BeginWebBot(botname,ret,bot,cgi,form) \
  216. extern "C" {                                  \
  217.     void WEBBOT_EXPORT botname##_Expand(      \
  218.      WebBotString*      retString,            \
  219.      WebBotDict*        botAttributes,        \
  220.      WebBotDict*        cgiEnvironment,       \
  221.      WebBotDict*        formData,             \
  222.      const WebBotFuncs* funcs)                \
  223. {                                             \
  224.     CWebBotString ret(retString, funcs);      \
  225.     CWebBotDict bot(botAttributes, funcs);    \
  226.     CWebBotDict cgi(cgiEnvironment, funcs);   \
  227.     CWebBotDict form(formData, funcs); 
  228.  
  229. #define EndWebBot }}
  230.  
  231. //
  232. // WebBot Expand method macro
  233. //
  234. #define BeginWebBotExpand(botname,ret,bot,cgi,form) \
  235. extern "C" {                                        \
  236.     void WEBBOT_EXPORT botname##_Expand(            \
  237.      WebBotString*      retString,                  \
  238.      WebBotDict*        botAttributes,              \
  239.      WebBotDict*        cgiEnvironment,             \
  240.      WebBotDict*        formData,                   \
  241.      const WebBotFuncs* funcs)                      \
  242. {                                                   \
  243.     CWebBotString ret(retString, funcs);            \
  244.     CWebBotDict bot(botAttributes, funcs);          \
  245.     CWebBotDict cgi(cgiEnvironment, funcs);         \
  246.     CWebBotDict form(formData, funcs); 
  247.  
  248. #define EndWebBotExpand }}
  249.  
  250. //
  251. // WebBot Edit method macro
  252. //
  253. #define BeginWebBotEdit(botname,bot)             \
  254. extern "C" {                                     \
  255.     int WEBBOT_EXPORT botname##_Edit(            \
  256.      WebBotDict*        botAttributes,           \
  257.      const WebBotFuncs* funcs)                   \
  258. {                                                \
  259.     WEBBOT_MANAGE_STATE                          \
  260.     CWebBotDict bot(botAttributes, funcs);
  261.  
  262. #define EndWebBotEdit }}
  263.  
  264.  
  265. #endif /* __cplusplus */
  266.  
  267.  
  268. #endif /* WEBBOT_H */
  269.