]>
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 #define ASSERT(x) if (!(x) ) throw;
40 // just another portable stream class...
52 void WriteBytes( const void* srcBuf
, size_t count
);
54 ScriptStream
& operator<<( const char* str
);
55 ScriptStream
& operator<<( const wxString
& str
);
56 ScriptStream
& operator<<( char ch
);
60 inline char* GetBuf() { return m_pBuf
; }
61 inline size_t GetBufSize() { return m_Size
; }
63 // clears current contents of the stream
64 void Reset() { m_Size
= 0; }
70 // used internally by ScriptTemplate
72 enum TEMPLATE_VARIABLE_TYPES
80 // helper structures used only by ScriptTemplate
89 TVarInfo( const char* name
, int ofs
, int varType
)
96 struct TArrayInfo
: public TVarInfo
101 int m_ObjRefTemplOfs
;
103 TArrayInfo( const char* name
)
104 : TVarInfo( name
, 0, TVAR_REF_ARRAY
)
108 // stores offset of the given member (of the given class)
109 // to (*pOfs), though the use of template classes would have
110 // solved this problem in much clearer fashion
112 // FOR NOW:: obtaining physical offset of class member
113 // does not appeare to be protable across compilers?
114 // FIXME:: +/- 1 problem
117 #define WEIRD_OFFSET 1
119 #define WEIRD_OFFSET 0
123 #define GET_VAR_OFS( className, varName, pOfs ) \
125 int* className::* varPtr; \
126 varPtr = (int* className::*)&className::varName; \
128 (*pOfs) = int(*(int*)&varPtr)-WEIRD_OFFSET; \
133 #if defined( wxUSE_TEMPLATE_STL )
135 typedef vector
<TVarInfo
*> TVarListT
;
137 // container class for sections
138 typedef vector
<ScriptSection
*> SectListT
;
142 typedef TVarInfo
* TVarInfoPtrT
;
143 typedef ScriptSection
* ScriptSectionPtrT
;
145 typedef WXSTL_VECTOR_SHALLOW_COPY(TVarInfoPtrT
) TVarListT
;
147 // container class for sections
148 typedef WXSTL_VECTOR_SHALLOW_COPY(ScriptSectionPtrT
) SectListT
;
152 // class performs preprocessing of arbitrary scripts,
153 // replaces identifiers enclosed in $(..) tag, whith
154 // values of the corresponding class member variables
159 // do not use wxString object here - parsing of
160 // C string can be much faster (in debug v.)
165 inline void PrintVar( TVarInfo
* pInfo
,
170 ScriptTemplate( const wxString
& templateText
);
171 virtual ~ScriptTemplate();
173 bool HasVar( const char* name
);
175 // Member variables registration methods.
177 // NOTE:: GET_VAR_OFS() macro should be used
178 // to get offset of the class member (see #define above)
179 void AddStringVar ( const char* name
, int ofs
);
180 void AddIntegerVar( const char* name
, int ofs
);
181 void AddDoubleVar ( const char* name
, int ofs
);
183 void AddObjectRefArray( const char* name
,
184 int ofsRefToFirstObj
,
189 // reads the script, replaces $(..) tags with values
190 // of registered members of dataObj object, and outputs
191 // the result to given text stream
193 void PrintScript( void* dataObj
, ScriptStream
& stm
);
198 // class manages section and aggregated sections of
199 // inter-linked documents
205 // NOTE:: "$(NAME)", $(ID), "$(BODY)" and "$(REFLIST)" are
206 // reseved template variables of ScriptSection
208 // the below there members are registered to ScriptTemplate,
209 // GUID within the section tree (numeric)
211 ScriptSection
* m_pParent
;
212 wxString m_Id
; // $(ID)
213 wxString m_Name
;// $(NAME)
214 wxString m_Body
; // $(BODY)
216 // NULL, if this section is not aggregated anywhere
218 SectListT m_Subsections
; // aggregated sectons
219 SectListT m_References
; // registered as $(REFLIST)
221 bool m_AutoHide
; // see autoHide arg, in constructor
222 bool m_SortOn
; // true, if sort subsectons by naem
224 // tempalte for this section
225 ScriptTemplate
* m_pSectTempl
;
227 // template used for links (or references) to this section
228 ScriptTemplate
* m_pRefTempl
;
230 // do not call destructor of this object,
231 // call RemoveRef() instead
234 static int m_IdCounter
; // generator of GUIDs
236 // fields registered and used by ScriptTemplate object
241 virtual void AddRef();
242 virtual void RemoveRef();
243 void DoRemoveEmptySections(int& nRemoved
, SectListT
& removedLst
);
244 void DoRemoveDeadLinks( SectListT
& removedLst
);
248 // NOTE:: pass NULL to certain template, if your sure
249 // this kind of template will never be used,
250 // e.g. if section is contained but never referrenced,
251 // then pReferenceTemplate can be NULL
253 // if autoHide option is true, the section will be automatically
254 // collapsed (not shown) if it doesn't contain any references
255 // to other sections (e.g. could be usefull for autoamically
256 // hiding empty index-sections).
258 ScriptSection( const wxString
& name
= wxEmptyString
,
259 const wxString
& body
= wxEmptyString
,
260 ScriptTemplate
* pSectionTemplate
= NULL
,
261 ScriptTemplate
* pReferenceTemplate
= NULL
,
262 bool autoHide
= false,
266 // calls RemoveRef() to all aggreagated sections first,
267 // then to all referenced section - this way all
268 // sections (even not aggregated ones) become "garbage-collected"
270 // NOTE:: do not call destructor directlly, call RemoveRef()
272 virtual ~ScriptSection();
275 // if addToReferencesToo is true, section is aggregated and
276 // also added to reference list of this section
278 void AddSection( ScriptSection
* pSection
, bool addToReferencesToo
= false );
280 // add cross-reference to this given section
281 void AddReference( ScriptSection
* pReferredSection
);
283 // subsection may be given of variable depth level,
284 // e.g. "publications/reviews/software"
286 ScriptSection
* GetSubsection( const char* name
);
288 // returns list aggregated sections
289 SectListT
& GetSubsections();
291 // binds reserved template names ( $(..) ) to member
292 // vairalbes in the ScriptSection class, should be called
293 // to initialize each user-code provided script template
295 static void RegisterTemplate( ScriptTemplate
& sectionTempalte
);
297 // prints out section tree to the stream, starting from
298 // this section as a root node
299 virtual void Print( ScriptStream
& stm
);
301 // searches empty sections which has autoHide == true,
302 // and colapses them (this method should be called )
303 // on the root-section of the sections tree
305 // NOTE:: does not work properly, yet!
306 void RemoveEmptySections();
309 // base class for documnetation generators
310 // (allows user code set up target script type,
311 // independently of documentation type)
313 class DocGeneratorBase
318 // override this method to do some post processing
319 // after generation of document, or even write some
320 // data into output stream, before the section tree
321 // is flushed into it.
323 // return false, if something has gone wrong and
324 // document cannot be saved now
326 virtual bool OnSaveDocument( ScriptStream
& WXUNUSED(stm
) )
329 // override this method to provide reference to
330 // the top section of the document (used as default
331 // starting section when saving a document)
333 virtual ScriptSection
* GetTopSection()
339 : m_Tags(0) // no defaul script
342 // dectrouctors of polymorphic classes SHOULD be virtual
343 virtual ~DocGeneratorBase() {}
345 // returns tags, being used for specific target script
346 MarkupTagsT
GetScriptMarkupTags() { return m_Tags
; }
348 // sets tag array for specific script
350 // NOTE:: Why virtual? since approach with MarkupTagsT is
351 // "flowless" only in theory. Overriding this method
352 // allows document generators to check the type of the
353 // target script, and perhaps make some modifications
354 // to generator's tamplates, to match the specific script
356 virtual void SetScriptMarkupTags( MarkupTagsT tags
)
359 // seves document to file starting from the root-node of
360 // the document (provided by GetTopSection() method),
361 // or from "pFromSection" if it's not NULL.
363 // fopenOptions arg. is string passed to fopen() method,
364 // returns true, if saving was successful
366 virtual bool SaveDocument( const char* fname
,
367 const char* fopenOptions
= "w",
368 ScriptSection
* pFromSection
= NULL