]>
git.saurik.com Git - wxWidgets.git/blob - utils/HelpGen/src/scriptbinder.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleskandars Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef __SCRIPTBINDER_G__
13 #define __SCRIPTBINDER_G__
15 #if defined( wxUSE_TEMPLATE_STL )
29 #include "wx/string.h"
35 typedef wxString string
;
42 #define ASSERT(x) if (!(x) ) throw;
47 // just another portable stream class...
59 void WriteBytes( const void* srcBuf
, size_t count
);
61 ScriptStream
& operator<<( const char* str
);
62 ScriptStream
& operator<<( const string
& str
);
63 ScriptStream
& operator<<( char ch
);
67 inline char* GetBuf() { return mpBuf
; }
68 inline size_t GetBufSize() { return mSize
; }
70 // clears current contents of the stream
71 void Reset() { mSize
= 0; }
77 // used internally by ScriptTemplate
79 enum TEMPLATE_VARIABLE_TYPES
87 // helper structures used only by ScriptTemplate
96 TVarInfo( const char* name
, int ofs
, int varType
)
103 struct TArrayInfo
: public TVarInfo
110 TArrayInfo( const char* name
)
111 : TVarInfo( name
, 0, TVAR_REF_ARRAY
)
115 // stores offset of the given member (of the given class)
116 // to (*pOfs), though the use of template classes would have
117 // solved this problem in much clearer fashion
119 // FOR NOW:: obtaining physical offset of class member
120 // does not appeare to be protable across compilers?
121 // FIXME:: +/- 1 problem
124 #define WEIRD_OFFSET 1
126 #define WEIRD_OFFSET 0
130 #define GET_VAR_OFS( className, varName, pOfs ) \
132 int* className::* varPtr; \
133 varPtr = (int* className::*)&className::varName; \
135 (*pOfs) = int(*(int*)&varPtr)-WEIRD_OFFSET; \
140 #if defined( wxUSE_TEMPLATE_STL )
142 typedef vector
<TVarInfo
*> TVarListT
;
144 // container class for sections
145 typedef vector
<ScriptSection
*> SectListT
;
149 typedef TVarInfo
* TVarInfoPtrT
;
150 typedef ScriptSection
* ScriptSectionPtrT
;
152 typedef WXSTL_VECTOR_SHALLOW_COPY(TVarInfoPtrT
) TVarListT
;
154 // container class for sections
155 typedef WXSTL_VECTOR_SHALLOW_COPY(ScriptSectionPtrT
) SectListT
;
159 // class performs preprocessing of arbitrary scripts,
160 // replaces identifiers enclosed in $(..) tag, whith
161 // values of the corresponding class member variables
166 // do not use string object here - parsing of
167 // C string can be much faster (in debug v.)
172 inline void PrintVar( TVarInfo
* pInfo
,
177 ScriptTemplate( const string
& templateText
);
178 virtual ~ScriptTemplate();
180 bool HasVar( const char* name
);
182 // Member variables registration methods.
184 // NOTE:: GET_VAR_OFS() macro should be used
185 // to get offset of the class member (see #define above)
186 void AddStringVar ( const char* name
, int ofs
);
187 void AddIntegerVar( const char* name
, int ofs
);
188 void AddDoubleVar ( const char* name
, int ofs
);
190 void AddObjectRefArray( const char* name
,
191 int ofsRefToFirstObj
,
196 // reads the script, replaces $(..) tags with values
197 // of registered members of dataObj object, and outputs
198 // the result to given text stream
200 void PrintScript( void* dataObj
, ScriptStream
& stm
);
205 // class manages section and aggregated sections of
206 // inter-linked documents
212 // NOTE:: "$(NAME)", $(ID), "$(BODY)" and "$(REFLIST)" are
213 // reseved template variables of ScriptSection
215 // the below there members are registered to ScriptTemplate,
216 // GUID within the section tree (numeric)
218 ScriptSection
* mpParent
;
220 string m_Name
;// $(NAME)
221 string mBody
; // $(BODY)
223 // NULL, if this section is not aggregated anywhere
225 SectListT mSubsections
; // aggregated sectons
226 SectListT mReferences
; // registered as $(REFLIST)
228 bool mAutoHide
; // see autoHide arg, in constructor
229 bool mSortOn
; // true, if sort subsectons by naem
231 // tempalte for this section
232 ScriptTemplate
* mpSectTempl
;
234 // template used for links (or references) to this section
235 ScriptTemplate
* mpRefTempl
;
237 // do not call destructor of this object,
238 // call RemoveRef() instead
241 static int mIdCounter
; // generator of GUIDs
243 // fields registered and used by ScriptTemplate object
248 virtual void AddRef();
249 virtual void RemoveRef();
250 void DoRemoveEmptySections(int& nRemoved
, SectListT
& removedLst
);
251 void DoRemoveDeadLinks( SectListT
& removedLst
);
255 // NOTE:: pass NULL to certain template, if your sure
256 // this kind of template will never be used,
257 // e.g. if section is contained but never referrenced,
258 // then pReferenceTemplate can be NULL
260 // if autoHide option is true, the section will be automatically
261 // collapsed (not shown) if it doesn't contain any references
262 // to other sections (e.g. could be usefull for autoamically
263 // hiding empty index-sections).
265 ScriptSection( const string
& name
= "",
266 const string
& body
= "",
267 ScriptTemplate
* pSectionTemplate
= NULL
,
268 ScriptTemplate
* pReferenceTemplate
= NULL
,
269 bool autoHide
= false,
273 // calls RemoveRef() to all aggreagated sections first,
274 // then to all referenced section - this way all
275 // sections (even not aggregated ones) become "garbage-collected"
277 // NOTE:: do not call destructor directlly, call RemoveRef()
279 virtual ~ScriptSection();
282 // if addToReferencesToo is true, section is aggregated and
283 // also added to reference list of this section
285 void AddSection( ScriptSection
* pSection
, bool addToReferencesToo
= false );
287 // add cross-reference to this given section
288 void AddReference( ScriptSection
* pReferredSection
);
290 // subsection may be given of variable depth level,
291 // e.g. "publications/reviews/software"
293 ScriptSection
* GetSubsection( const char* name
);
295 // returns list aggregated sections
296 SectListT
& GetSubsections();
298 // binds reserved template names ( $(..) ) to member
299 // vairalbes in the ScriptSection class, should be called
300 // to initialize each user-code provided script template
302 static void RegisterTemplate( ScriptTemplate
& sectionTempalte
);
304 // prints out section tree to the stream, starting from
305 // this section as a root node
306 virtual void Print( ScriptStream
& stm
);
308 // searches empty sections which has autoHide == true,
309 // and colapses them (this method should be called )
310 // on the root-section of the sections tree
312 // NOTE:: does not work properly, yet!
313 void RemoveEmptySections();
316 // base class for documnetation generators
317 // (allows user code set up target script type,
318 // independently of documentation type)
320 class DocGeneratorBase
325 // override this method to do some post processing
326 // after generation of document, or even write some
327 // data into output stream, before the section tree
328 // is flushed into it.
330 // return false, if something has gone wrong and
331 // document cannot be saved now
333 virtual bool OnSaveDocument( ScriptStream
& WXUNUSED(stm
) )
336 // override this method to provide reference to
337 // the top section of the document (used as default
338 // starting section when saving a document)
340 virtual ScriptSection
* GetTopSection()
346 : mTags(0) // no defaul script
349 // dectrouctors of polymorphic classes SHOULD be virtual
350 virtual ~DocGeneratorBase() {}
352 // returns tags, being used for specific target script
353 MarkupTagsT
GetScriptMarkupTags() { return mTags
; }
355 // sets tag array for specific script
357 // NOTE:: Why virtual? since approach with MarkupTagsT is
358 // "flowless" only in theory. Overriding this method
359 // allows document generators to check the type of the
360 // target script, and perhaps make some modifications
361 // to generator's tamplates, to match the specific script
363 virtual void SetScriptMarkupTags( MarkupTagsT tags
)
366 // seves document to file starting from the root-node of
367 // the document (provided by GetTopSection() method),
368 // or from "pFromSection" if it's not NULL.
370 // fopenOptions arg. is string passed to fopen() method,
371 // returns true, if saving was successfull
373 virtual bool SaveDocument( const char* fname
,
374 const char* fopenOptions
= "w",
375 ScriptSection
* pFromSection
= NULL