+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: No names yet.
-// Purpose: Implementation of C++/Java parser
-// compatible with SourceParserBase interface
-// Author: Aleksandras Gluchovas
-// Modified by:
-// Created: 22/09/98
-// RCS-ID: $Id$
-// Copyright: (c) Aleskandars Gluchovas
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef __CJPARSESR_G__
-#define __CJPARSESR_G__
-
-#include "srcparser.h"
-
-#include <iostream.h>
-#include <memory.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-// class parses given "memory-resident" Java or C++ source code
-// and captures information about classes/attrubutes/methods/
-// arguments/etc into structures. Conforms with SourceParserBase
-// interface requirements.
-
-class CJSourceParser : public SourceParserBase
-{
-protected:
- // begining of the full-text area of the source file
- char* mpStart;
-
- // points to first character after the end
- // of teh full-text area
- char* mpEnd;
-
- // current "privacy level"
- int mCurVis;
-
- // current parsing position int full-text area
- char* cur;
-
- // about the current class
- bool mIsVirtual;
- bool mIsTemplate;
- size_t mNestingLevel;
-
- // context data for which is currently being collected
- spContext* mpCurCtx;
-
- int mCurCtxType; // type of the current context
-
- bool mCommentsOn;
- bool mMacrosOn;
-
-protected:
-
- void AttachComments( spContext& ctx, char* cur );
- void ParseKeyword( char*& cur );
- bool ParseNameAndRetVal( char*& cur, bool& isAMacro );
- bool ParseArguments( char*& cur );
- void ParseMemberVar( char*& cur );
- void SkipFunction( char*& cur );
- void SkipFunctionBody( char*& cur );
- bool CheckVisibilty( char*& cur );
-
- void AddClassNode( char*& cur );
- void AddMacroNode( char*& cur );
- void AddEnumNode( char*& cur );
- void AddTypeDefNode( char*& cur );
-
- void DumpOperationInfo( spOperation& info, const string& tab, ostream& os );
- void DumpClassHeader( spClass& info, ostream& os );
- void DumpClassBody( spClass& info, ostream& os );
-
-public:
-
- // NOTE:: discarding of macros or comments improves performance and
- // decreases memory usage
-
- CJSourceParser(bool collectCommnets = 1,
- bool collectMacros = 1);
-
- // returns the root-node of the created context tree
- // (user is responsible for releasing it from the heep)
- // "end" should point to the last (character + 1) of the
- // source text
-
- virtual spFile* Parse( char* start, char* end );
-};
-
-// inline'ed helpers used (just info):
-/*
-static inline void skip_to_eol( char*& cur );
-static inline void skip_eol( char*& cur );
-static inline bool skip_to_next_comment_in_the_line( char*& cur );
-static void skip_to_prev_line( char*& cur );
-static inline void skip_comments( char*& cur );
-static inline void clear_commets_queue();
-static inline void skip_quoted_string( char*& cur );
-static inline bool get_next_token( char*& cur );
-static inline void skip_preprocessor_dir( char*& cur );
-static void skip_token( char*& cur );
-static inline size_t get_token_len( char* tok );
-static inline bool cmp_tokens( char* tok1, char* tok2 );
-static inline bool cmp_tokens_fast( char* tok1, char* tok2, size_t len );
-static inline void skip_tempalate_statement( char*& cur );
-static inline void skip_statement( char*& cur );
-static inline void skip_token_back( char*& cur );
-static inline void skip_next_token_back( char*& cur );
-static string get_token_str( char* cur );
-static size_t skip_block( char*& cur );
-static inline bool skip_imp_block( char*& cur );
-static bool is_class_token( char*& cur );
-inline static bool is_forward_decl( char* cur );
-inline static bool is_function( char* cur, bool& isAMacro );
-static inline void skip_scope_block( char*& cur );
-static void arrange_indirection_tokens_between( string& type, string& identifier );
-static bool is_keyword( char* cur );
-static inline void get_string_between( char* start, char* end, string* pStr );
-static char* set_comment_text( string& text, char* start );
-*/
-
-#endif
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: No names yet.
-// Purpose: Contrib. demo
-// Author: Aleksandras Gluchovas
-// Modified by:
-// Created: 22/09/98
-// RCS-ID: $Id$
-// Copyright: (c) Aleskandars Gluchovas
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef __DOCRIPPER_G__
-#define __DOCRIPPER_G__
-
-#include "scriptbinder.h"
-#include "srcparser.h"
-#include "sourcepainter.h"
-
-#if defined( wxUSE_TEMPLATE_STL )
-
- #include <vector>
-
- typedef vector<ScriptTemplate*> STemplateListT;
-
-#else
-
- #include "wxstlvec.h"
-
- typedef ScriptTemplate* ScriptTemplatePtrT;
- typedef WXSTL_VECTOR_SHALLOW_COPY(ScriptTemplatePtrT) STemplateListT;
-
-#endif
-
-
-// specific DocGenerator class for "Ripper",
-// also acts as source code visitor
-
-class RipperDocGen : public DocGeneratorBase, public spVisitor
-{
-protected:
- // templates for various sections
- ScriptTemplate mTopTempl;
- ScriptTemplate mContentIdxTempl;
- ScriptTemplate mSuperContentTempl;
- ScriptTemplate mSubContentTempl;
- ScriptTemplate mOutLineTempl;
- ScriptTemplate mOutLine1Templ;
-
- // template used for corss-references
- ScriptTemplate mRefTempl;
-
- // template used to show not-existing sections
- ScriptTemplate mDeadRefTempl;
-
- // template collection for generation of class-tree
- STemplateListT mTreeTemplates;
-
- // pointers to all major index sections
- ScriptSection* mpTopIdx;
- ScriptSection* mpClassIdx;
- ScriptSection* mpEnumIdx;
- ScriptSection* mpTypeDefIdx;
- ScriptSection* mpMacroIdx;
- ScriptSection* mpGlobalVarsIdx;
- ScriptSection* mpGlobalFuncIdx;
- ScriptSection* mpConstIdx;
-
- // parser set up from user-code for sepcific language
- SourceParserBase* mpParser;
-
- // class section, which is currently being
- // assembled
- ScriptSection* mpCurClassSect;
-
- // source syntax heighlighter object
- SourcePainter mSrcPainter;
-
- // context, to which all file contexts
- // are assembled
- spContext* mpFileBinderCtx;
-
- // script tags set up from usesr code
- MarkupTagsT mTags;
-
-protected:
- // helpers
- void AppendComments( spContext& fromContext, string& str );
-
- void AppendMulitilineStr( string& st, string& mlStr );
-
- void AppendHighlightedSource( string& st, string source );
-
- // returns TRUE, if no comments found in the context,
- // plus, creates dummy(empty) section, and puts a
- // reference woth "dead-link" template to it in the
- // given index-section "toSect"
-
- bool CheckIfUncommented( spContext& ctx, ScriptSection& toSect );
-
- // checks if context has any comments, then returns
- // template of normal reference, otherwise of dead reference
-
- ScriptTemplate* GetRefTemplFor( spContext& ctx );
-
- // adds "someClass::" perfix to the context name,
- // if it's not in the file scope (i.e. if it's not global)
-
- string GetScopedName( spContext& ofCtx );
-
- // adds section to currently assembled class section
- // and places references to it from "public", "protected"
- // or "private" indexing-subsections of the class, depending
- // on the visibility of the context
-
- void AddToCurrentClass( ScriptSection* pSection, spContext& ctx,
- const char* subSectionName );
-
- // called, after all files are processed, to
- // resolve possible super/derived class relations,
- // and put cross references to them - where resolution was
- // successful
- void LinkSuperClassRefs();
-
- // implementations of "visiting procedures", declared in spVisitor
-
- virtual void VisitClass( spClass& cl );
- virtual void VisitEnumeration( spEnumeration& en );
- virtual void VisitTypeDef( spTypeDef& td );
- virtual void VisitPreprocessorLine( spPreprocessorLine& pd );
- virtual void VisitAttribute( spAttribute& attr );
- virtual void VisitOperation( spOperation& op );
-
- // overriden member of DocGernatorBase
-
- virtual bool OnSaveDocument( ScriptStream& stm );
-
- virtual ScriptSection* GetTopSection()
- { return mpTopIdx; }
-
-public:
- RipperDocGen();
- ~RipperDocGen();
-
- // should be called onece to set user-code provided,
- // parser for specific source code language
- // (NOTE:: it's the user-code's responsibility to
- // relseas memory of pParser)
-
- void Init( SourceParserBase* pParser );
-
- // should be called on each file
-
- void ProcessFile( const char* sourceFile );
-};
-
-
-#endif
\ No newline at end of file
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: No names yet.
-// Purpose: Contrib. demo
-// Author: Aleksandras Gluchovas
-// Modified by:
-// Created: 27/12/98
-// RCS-ID: $Id$
-// Copyright: (c) Aleskandars Gluchovas
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef __IFCONTEXT_G__
-#define __IFCONTEXT_G__
-
-#include "srcparser.h"
-#include "cjparser.h"
-
-class spBookmark
-{
-public:
- size_t mFrom;
- size_t mLen;
- size_t mFileNo;
-
- inline spBookmark() {}
-
- inline spBookmark( int from, int len, int fileNo )
- : mFrom( from ), mLen( len ), mFileNo( fileNo )
- {}
-};
-
-#if defined( wxUSE_TEMPLATE_STL )
-
- typedef vector<spBookmark) BookmarkListT
-
-#else
-
- typedef WXSTL_VECTOR_SHALLOW_COPY(spBookmark) BookmarkListT;
-
-#endif
-
-
-class spInterFileContext : public spContext
-{
-protected:
-
- BookmarkListT mDeletionMarks;
-
- BookmarkListT mFiltered;
-
- size_t mCurFileNo;
-
- CJSourceParser mParser;
-
-protected:
-
- size_t GetFileNoOfContext( spContext& ctx );
- size_t GetFileNo( const string& fname );
-
- void InsertBookmarkSorted( BookmarkListT& lst, spBookmark& mark );
-
- void DoAppendSourceFragment( string& source,
- string& result,
- size_t pos, size_t len );
-
- void GenerateContextBody( spContext& ctx,
- string& source,
- string& result,
- size_t& lastSavedPos,
- size_t& lastKnownPos );
-
-public:
-
- StrListT mFiles;
- StrListT mContents;
-
-public:
-
- spInterFileContext();
- ~spInterFileContext();
-
- void AddFile( const string& fname, const string& content );
-
- void RemoveContext( spContext& ctx );
-
- void GenrateContents();
-
- void ParseContents( SourceParserPlugin* pPlugin = NULL );
-
- void WriteToFiles();
-
- // overriden method of the base class (finds out the source fragment)
-
- virtual string GetBody( spContext* pCtx = NULL );
-
- virtual string GetHeader( spContext* pCtx = NULL );
-};
-
-
-#endif
\ No newline at end of file
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: No names yet.
-// Purpose: Contrib. demo
-// Author: Aleksandras Gluchovas
-// Modified by:
-// Created: 22/09/98
-// RCS-ID: $Id$
-// Copyright: (c) Aleskandars Gluchovas
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef __MARKUP_G__
-#define __MARKUP_G__
-
-// indicies for the MarkupTagsT array
-
-#define TAG_BOLD 0
-#define TAG_ITALIC 1
-
-#define TAG_FIXED_FONT 2
-#define TAG_BLACK_FONT 3
-#define TAG_RED_FONT 4
-#define TAG_GREEN_FONT 5
-#define TAG_BLUE_FONT 6
-
-#define TAG_PARAGRAPH 7
-#define TAG_NEW_LINE 8
-#define TAG_HEADING_1 9
-#define TAG_HEADING_2 10
-#define TAG_HEADING_3 11
-
-#define TAG_ITEM_LIST 12
-#define TAG_LIST_ITEM 13
-
-struct TagStructT
-{
- char* start; // tag that starts style
- char* end; // tag that finishes style
-};
-
-// tag array
-typedef TagStructT* MarkupTagsT;
-
-// returns array of TagStructT with tag strings for HTML
-
-MarkupTagsT get_HTML_markup_tags();
-
-// MarkupTagsT get_PostScript_markup_tags();
-// MarkupTagsT get_Latex_markup_tags();
-
-#endif
\ No newline at end of file
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: No names yet.
-// Purpose: Contrib. demo
-// Author: Aleksandras Gluchovas
-// Modified by:
-// Created: 22/09/98
-// RCS-ID: $Id$
-// Copyright: (c) Aleskandars Gluchovas
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef __SCRIPTBINDER_G__
-#define __SCRIPTBINDER_G__
-
-#if defined( wxUSE_TEMPLATE_STL )
-
- #include <vector>
-
- #ifdef WIN32
- #include <bstring.h>
- #else
- #include <strclass.h>
- #include <string.h>
- #endif
-
-#else
-
- #include "wxstlvec.h"
- #include "wx/string.h"
-
- // FIXME:: dirty!
- typedef wxString string;
-
-#endif
-
-#ifndef ASSERT
-// assert yourself
-#define ASSERT(x) if (!(x) ) throw;
-#endif
-
-#include "markup.h"
-
-// just another portable stream class...
-
-class ScriptStream
-{
-protected:
- char* mpBuf;
- size_t mSize;
- size_t mCapacity;
-public:
- ScriptStream();
- ~ScriptStream();
-
- void WriteBytes( const void* srcBuf, size_t count );
-
- ScriptStream& operator<<( const char* str );
- ScriptStream& operator<<( const string& str );
- ScriptStream& operator<<( char ch );
-
- void endl();
-
- inline char* GetBuf() { return mpBuf; }
- inline size_t GetBufSize() { return mSize; }
-
- // clears current contents of the stream
- void Reset() { mSize = 0; }
-};
-
-
-class ScriptTemplate;
-
-// used internally by ScriptTemplate
-
-enum TEMPLATE_VARIABLE_TYPES
-{
- TVAR_INTEGER,
- TVAR_STRING,
- TVAR_DOUBLE,
- TVAR_REF_ARRAY
-};
-
-// helper structures used only by ScriptTemplate
-
-struct TVarInfo
-{
-public:
- const char* mName;
- int mType;
- int mOfs;
-
- TVarInfo( const char* name, int ofs, int varType )
- : mName(name),
- mType( varType ),
- mOfs( ofs )
- {}
-};
-
-struct TArrayInfo : public TVarInfo
-{
-public:
- int mRefOfs;
- int mSizeIntOfs;
- int mObjRefTemplOfs;
-
- TArrayInfo( const char* name )
- : TVarInfo( name, 0, TVAR_REF_ARRAY )
- {}
-};
-
-// stores offset of the given member (of the given class)
-// to (*pOfs), though the use of template classes would have
-// solved this problem in much clearer fashion
-
-// FOR NOW:: obtaining physical offset of class member
-// does not appeare to be protable across compilers?
-// FIXME:: +/- 1 problem
-
-#ifdef __UNIX__
- #define WEIRD_OFFSET 1
-#else
- #define WEIRD_OFFSET 0
-
-#endif
-
-#define GET_VAR_OFS( className, varName, pOfs ) \
- { \
- int* className::* varPtr; \
- varPtr = (int* className::*)&className::varName; \
- \
- (*pOfs) = int(*(int*)&varPtr)-WEIRD_OFFSET; \
- }
-
-class ScriptSection;
-
-#if defined( wxUSE_TEMPLATE_STL )
-
- typedef vector<TVarInfo*> TVarListT;
-
- // container class for sections
- typedef vector<ScriptSection*> SectListT;
-
-#else
-
- typedef TVarInfo* TVarInfoPtrT;
- typedef ScriptSection* ScriptSectionPtrT;
-
- typedef WXSTL_VECTOR_SHALLOW_COPY(TVarInfoPtrT) TVarListT;
-
- // container class for sections
- typedef WXSTL_VECTOR_SHALLOW_COPY(ScriptSectionPtrT) SectListT;
-
-#endif
-
-// class performs preprocessing of arbitrary scripts,
-// replaces identifiers enclosed in $(..) tag, whith
-// values of the corresponding class member variables
-
-class ScriptTemplate
-{
-protected:
- // do not use string object here - parsing of
- // C string can be much faster (in debug v.)
- char* mTText;
-
-
- TVarListT mVars;
-
- inline void PrintVar( TVarInfo* pInfo,
- void* dataObj,
- ScriptStream& stm );
-
-public:
- ScriptTemplate( const string& templateText );
- virtual ~ScriptTemplate();
-
- bool HasVar( const char* name );
-
- // Member variables registration methods.
-
- // NOTE:: GET_VAR_OFS() macro should be used
- // to get offset of the class member (see #define above)
- void AddStringVar ( const char* name, int ofs );
- void AddIntegerVar( const char* name, int ofs );
- void AddDoubleVar ( const char* name, int ofs );
-
- void AddObjectRefArray( const char* name,
- int ofsRefToFirstObj,
- int ofsObjSizeInt,
- int ofsObjRefTempl
- );
-
- // reads the script, replaces $(..) tags with values
- // of registered members of dataObj object, and outputs
- // the result to given text stream
-
- void PrintScript( void* dataObj, ScriptStream& stm );
-};
-
-class ScriptSection;
-
-// class manages section and aggregated sections of
-// inter-linked documents
-
-class ScriptSection
-{
-protected:
-
- // NOTE:: "$(NAME)", $(ID), "$(BODY)" and "$(REFLIST)" aree
- // reseved template variables of ScriptSection
-
- // the below there members are registered to ScriptTemplate,
- // GUID within the section tree (numeric)
-
- ScriptSection* mpParent;
- string mId; // $(ID)
- string mName; // $(NAME)
- string mBody; // $(BODY)
-
- // NULL, if this section is not aggregated anywhere
-
- SectListT mSubsections; // aggregated sectons
- SectListT mReferences; // registered as $(REFLIST)
-
- bool mAutoHide; // see autoHide arg, in constructor
- bool mSortOn; // TRUE, if sort subsectons by naem
-
- // tempalte for this section
- ScriptTemplate* mpSectTempl;
-
- // template used for links (or references) to this section
- ScriptTemplate* mpRefTempl;
-
- // do not call destructor of this object,
- // call RemoveRef() instead
- int mRefCount;
-
- static int mIdCounter; // generator of GUIDs
-
- // fields registered and used by ScriptTemplate object
- void* mRefFirst;
- int mArrSize;
-
-protected:
- virtual void AddRef();
- virtual void RemoveRef();
- void DoRemoveEmptySections(int& nRemoved, SectListT& removedLst);
- void DoRemoveDeadLinks( SectListT& removedLst);
-
-public:
-
- // NOTE:: pass NULL to certain template, if your sure
- // this kind of template will never be used,
- // e.g. if section is contained but never referrenced,
- // then pReferenceTemplate can be NULL
-
- // if autoHide option is TRUE, the section will be automatically
- // collapsed (not shown) if it doesn't contain any references
- // to other sections (e.g. could be usefull for autoamically
- // hiding empty index-sections).
-
- ScriptSection( const string& name = "",
- const string& body = "",
- ScriptTemplate* pSectionTemplate = NULL,
- ScriptTemplate* pReferenceTemplate = NULL,
- bool autoHide = FALSE,
- bool sorted = FALSE
- );
-
- // calls RemoveRef() to all aggreagated sections first,
- // then to all referenced section - this way all
- // sections (even not aggregated ones) become "garbage-collected"
-
- // NOTE:: do not call destructor directlly, call RemoveRef()
- // instead
- virtual ~ScriptSection();
-
-
- // if addToReferencesToo is TRUE, section is aggregated and
- // also added to reference list of this section
-
- void AddSection( ScriptSection* pSection, bool addToReferencesToo = FALSE );
-
- // add cross-reference to this given section
- void AddReference( ScriptSection* pReferredSection );
-
- // subsection may be given of variable depth level,
- // e.g. "publications/reviews/software"
-
- ScriptSection* GetSubsection( const char* name );
-
- // returns list aggregated sections
- SectListT& GetSubsections();
-
- // binds reserved template names ( $(..) ) to member
- // vairalbes in the ScriptSection class, should be called
- // to initialize each user-code provided script template
-
- static void RegisterTemplate( ScriptTemplate& sectionTempalte );
-
- // prints out section tree to the stream, starting from
- // this section as a root node
- virtual void Print( ScriptStream& stm );
-
- // searches empty sections which has autoHide == TRUE,
- // and colapses them (this method should be called )
- // on the root-section of the sections tree
-
- // NOTE:: does not work properly, yet!
- void RemoveEmptySections();
-};
-
-// base class for documnetation generators
-// (allows user code set up target script type,
-// independently of documentation type)
-
-class DocGeneratorBase
-{
-protected:
- MarkupTagsT mTags;
-
- // override this method to do some post processing
- // after generation of document, or even write some
- // data into output stream, before the section tree
- // is flushed into it.
-
- // return FALSE, if something has gone wrong and
- // document cannot be saved now
-
- virtual bool OnSaveDocument( ScriptStream& stm )
- { return 1; }
-
- // override this method to provide reference to
- // the top section of the document (used as default
- // starting section when saving a document)
-
- virtual ScriptSection* GetTopSection()
- { return 0; }
-
-public:
-
- DocGeneratorBase()
- : mTags(0) // no defaul script
- {}
-
- // dectrouctors of polymorphic classes SHOULD be virtual
- virtual ~DocGeneratorBase() {}
-
- // returns tags, being used for specific target script
- MarkupTagsT GetScriptMarkupTags() { return mTags; }
-
- // sets tag array for specific script
-
- // NOTE:: Why virtual? since approach with MarkupTagsT is
- // "flowless" only in theory. Overriding this method
- // allows document generators to check the type of the
- // target script, and perhaps make some modifications
- // to generator's tamplates, to match the specific script
-
- virtual void SetScriptMarkupTags( MarkupTagsT tags )
- { mTags = tags; }
-
- // seves document to file starting from the root-node of
- // the document (provided by GetTopSection() method),
- // or from "pFromSection" if it's not NULL.
-
- // fopenOptions arg. is string passed to fopen() method,
- // returns TRUE, if saving was successfull
-
- virtual bool SaveDocument( const char* fname,
- const char* fopenOptions = "w",
- ScriptSection* pFromSection = NULL
- );
-
-};
-
-#endif
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: No names yet.
-// Purpose: Contrib. demo
-// Author: Aleksandras Gluchovas
-// Modified by:
-// Created: 22/09/98
-// RCS-ID: $Id$
-// Copyright: (c) Aleskandars Gluchovas
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef __SOURCEPAINTER_G__
-#define __SOURCEPAINTER_G__
-
-#ifndef ASSERT
-#define ASSERT(x) if (!(x)) throw
-#endif
-
-#if defined( wxUSE_TEMPLATE_STL )
-
- #include <vector.h>
- typedef vector<int> SPBlockListT;
-
- #ifdef WIN32
- #include <bstring.h>
- #else
- #include <strclass.h>
- #include <string.h>
- #endif
-#else
-
- #include "wxstlvec.h"
- #include "wx/string.h"
-
- // FIXME:: dirty!
- #define string wxString
-
- typedef WXSTL_VECTOR_SHALLOW_COPY(int) SPBlockListT;
-
-#endif
-
-#include "markup.h" // import MarkupTagsT definition
-
-// "colored" codes for highlighted blocks
-
-#define RANK_BLACK 0 // common source fragments
-#define RANK_BLUE 1 // basic types
-#define RANK_RED 2 // reserved words
-#define RANK_GREEN 3 // comments
-
-// colored block description format :
-// int( ( rank << 16 ) | ( source_range_len ) )
-
-
-// FOR NOW:: no lagnguage-map selection
-
-// source code syntax heighlighter (CPP+JAVA+VB+PASCAL)
-
-class SourcePainter
-{
-protected:
- string mResultStr;
- SPBlockListT mBlocks;
- bool mCollectResultsOn;
-
- // state variables
- bool mIsInComment;
- bool mCommentIsMultiline;
-public:
-
- // assembleResultString == TRUE - instructs painter
- // to collect each chunk of srouce passed to ProcessSource(),
- // so that results cann be futher obtained in a single string
- // instead of vector of block descriptions
-
- SourcePainter( bool assembleResultString = TRUE );
- virtual ~SourcePainter() {}
-
- // can be called multiple times (e.g. on each source line)
- void ProcessSource( char* src, int srcLen );
-
- // method, for manually adjusting state of source painter
- void SetState( bool isInComment,
- bool commentIsMultiline );
-
- // reinitializes object - clears results of previouse processing
- void Init( bool assembleResultString = TRUE );
-
- // generates string of highlighted source for the scipting
- // language given by "tags" argument
-
- virtual void GetResultString(string& result, MarkupTagsT tags);
-
- // returns vector of block descriptors, see SPBlockListT definition
- // (block descriptors can be used for fast custom hightlighted text generation)
-
- SPBlockListT& GetBlocks();
-
- // NOTE:: static method
- // returns if the given word is a reserved word or basic type identifier
- static bool IsKeyword( char* word, int wordLen );
-};
-
-#endif
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: No names yet.
-// Purpose: To provide a simple _framework_
-// for series of source code parsers with
-// compatible interfaces
-// Author: Aleksandras Gluchovas
-// Modified by: AG on 28/12/98
-// Created: 22/09/98
-// RCS-ID: $Id$
-// Copyright: (c) Aleskandars Gluchovas
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef __SRCPARSER_G__
-#define __SRCPARSER_G__
-
-#if defined( wxUSE_TEMPLATE_STL )
- #include <vector>
-
- #ifdef WIN32
- #include <bstring.h>
- #else
-
- #include <strclass.h>
- #include <string.h>
-
- #endif
-
-#else
- #include "wx/string.h"
- #include "wxstlvec.h"
-
- // FOR NOW:: quick n' dirty:
-
- #define string wxString
-
-#endif
-
-#include "markup.h" // markup tags used in spOperator::GetFullName()
-
-// these methods are used for debugging only and disappear in the release build
-#ifdef __WXDEBUG__
- #define DECLARE_DUMP virtual void DumpThis(const wxString& indent) const;
-#else
- #define DECLARE_DUMP
-#endif
-
-// context class list in "inside-out" order :
-
-class spContext;
-
-class spParameter;
-class spAttribute;
-class spOperation;
-class spEnumeration;
-class spTypeDef;
-class spPreprocessorLine;
-class spClass;
-class spNameSpace;
-class spFile;
-
-// source context visibilities
-enum SRC_VISIBLITY_TYPES
-{
- SP_VIS_PUBLIC,
- SP_VIS_PROTECTED,
- SP_VIS_PRIVATE
-};
-
-// class types
-enum SP_CLASS_TYPES
-{
- SP_CLTYPE_INVALID,
- SP_CLTYPE_CLASS,
- SP_CLTYPE_TEMPLATE_CLASS,
- SP_CLTYPE_STRUCTURE,
- SP_CLTYPE_UNION,
- SP_CLTYPE_INTERFACE
-};
-
-// inheritance types
-enum SP_INHERITANCE_TYPES
-{
- SP_INHERIT_VIRTUAL,
- SP_INHERIT_PUBLIC,
- SP_INHERIT_PRIVATE
-};
-
-// proprocessor definitions types (specific to C++ code)
-
-enum SP_PREP_DEFINITION_TYPES
-{
- SP_PREP_DEF_DEFINE_SYMBOL,
- SP_PREP_DEF_REDEFINE_SYMBOL,
- SP_PREP_DEF_INCLUDE_FILE,
- SP_PREP_DEF_OTHER
-};
-
-// common context types
-
-#define SP_CTX_UNKNOWN 0x000
-#define SP_CTX_FILE 0x001
-#define SP_CTX_NAMESPACE 0x002
-#define SP_CTX_CLASS 0x004
-#define SP_CTX_TYPEDEF 0x008
-#define SP_CTX_PREPROCESSOR 0x010
-#define SP_CTX_ENUMERATION 0x020
-#define SP_CTX_ATTRIBUTE 0x040
-#define SP_CTX_OPERATION 0x080
-#define SP_CTX_PARAMETER 0x100
-
-// other (custom) context codes may be defined elsewere, however they should
-// not clash with above codes for common type and also should not
-// exceed 16-bits of in value
-
-// masks all context types (up to 16 custom context can be defined)
-
-#define SP_CTX_ANY 0xFFFF
-
-class spComment;
-
-
-
-#if defined( wxUSE_TEMPLATE_STL )
-
- // context members
- typedef vector<spContext*> MMemberListT;
- // comments list
- typedef vector<spComment*> MCommentListT;
- // list of parameters
- typedef vector<spParameter*> MParamListT;
- // string list
- typedef vector<string> StrListT;
-
-#else
-
- typedef spContext* spContextPtrT;
- typedef spComment* spCommentPtrT;
- typedef spParameter* spParameterPtrT;
- typedef WXSTL_VECTOR_SHALLOW_COPY(spContextPtrT) MMemberListT;
- typedef WXSTL_VECTOR_SHALLOW_COPY(spCommentPtrT) MCommentListT;
- typedef WXSTL_VECTOR_SHALLOW_COPY(spParameterPtrT) MParamListT;
- typedef WXSTL_VECTOR_SHALLOW_COPY(string) StrListT;
-
-#endif;
-// base class for all visitors of source code contents
-
-class spVisitor
-{
-protected:
- bool mSiblingSkipped;
- bool mChildSkipped;
- int mContextMask;
-
- spContext* mpCurCxt;
-
-public:
- // methods invoked by context
-
- // method invoked from user's controling code
- // to visit all nodes staring at the given context.
- // Content is sorted if requrired, see comments
- // spClass on sorting the class members
-
- void VisitAll( spContext& atContext,
- bool sortContent = TRUE
- );
-
- // methods invoked by visitor
-
- // goes to the next context in the outter scope
- // NOTE:: should not be invoked more than once while
- // visiting certain context
-
- void SkipSiblings();
-
- // prevents going down into the contexts contained by
- // the current context
- // NOTE:: the same as above
-
- void SkipChildren();
-
- // can be called only in from visiting procedure
- void RemoveCurrentContext();
-
- // method enables fast filtered traversal
- // of source content, e.g. collecting only classes,
- // or only global functions
-
- // arg. context - can contain combination of contexts concatinated
- // with bitwise OR, e.g. SP_CTX_CLASS | SP_CTX_NAMESPACE
- //
- // method can be invoked from the user's controling as well as
- // from within the visting procedure
-
- void SetFilter( int contextMask );
-
- // methods should be implemneted by specific visitor:
-
- // NOTE:: Do not confuse visiting with parsing, first
- // the source is parsed, and than can be visited
- // multiple times by variouse visitors (there can
- // be more the one visitor visiting content at a time)
-
- virtual void VisitFile( spFile& fl ) {}
-
- virtual void VisitNameSpace( spNameSpace& ns ) {}
-
- virtual void VisitClass( spClass& cl ) {}
-
- virtual void VisitEnumeration( spEnumeration& en ) {}
-
- virtual void VisitTypeDef( spTypeDef& td ) {}
-
- virtual void VisitPreprocessorLine( spPreprocessorLine& pd ) {}
-
- virtual void VisitAttribute( spAttribute& attr ) {}
-
- virtual void VisitOperation( spOperation& op ) {}
-
- virtual void VisitParameter( spParameter& param ) {}
-
- virtual void VisitCustomContext( spContext& ctx ) {}
-};
-
-// stores one section of comments,
-// multiple sections can be put to geather
-// and attached to some context
-
-class spComment
-{
-public:
- string mText;
- bool mIsMultiline; // multiline comments ar those with /**/'s
-
- // TRUE, if these was an empty empty
- // line above single line comment
-
- bool mStartsPar;
-
-public:
-
- bool IsMultiline() const;
- bool StartsParagraph() const;
-
- string& GetText();
-
- // contstant version of GetText()
- string GetText() const;
-};
-
-// abstract base class for common (to most languages) code
-// contexts (constructs), e.g file, namespace, class, operation,
-// etc
-
-class spContext
-{
-protected:
- // "linked" list of comments belonging to this context
- MCommentListT mComments;
-
- // NULL, if this is file context
- MMemberListT mMembers;
-
- // NULL, if this is top-most context
- spContext* mpParent;
-
- // points to context object, where the this context
- // was originally declared, meaning that this object
- // is redeclaration (or if in the case of operation
- // this context object most probably referres to the
- // implemnetation in .cpp file for example)
-
- // is NULL, if this object referres to the first occurence
- // of the context
-
- spContext* mpFirstOccurence;
-
- // used, to avoid excessive sorting of context's agreggates
- bool mAlreadySorted;
-
-public:
-
- // source line number, (-1) if unknown
- int mSrcLineNo;
-
- // offset of context in the source file, (-1) if unknown
- int mSrcOffset;
-
- // lentgh of the context in characters, (-1) if unknown
- int mContextLength;
-
- // source line number, in which this cotext ends, (-1) if unknown
- int mLastScrLineNo;
-
- // fields are valid, if the may contain other contexts nested inside
- int mHeaderLength;
- int mFooterLength;
-
- // zero-based index of the first character of
- // this context in the source line, (-1) if unknown
- int mFirstCharPos;
-
- // zero-based index of the first character of
- // this context in the last source line of this context, (-1) if unknown
- int mLastCharPos;
-
- // see SRC_VISIBLITY_TYPES enumeration
- int mVisibility;
-
- // TRUE, if context does not really exist in the source
- // but was created by external tools (e.g. forward engineering)
-
- bool mIsVirtualContext;
- bool mVirtualContextHasChildren;
-
- // body of the context in case (mIsVirtual == TRUE)
- string mVirtualContextBody;
- string mVittualContextFooter;
-
- // e.g. can be used by documentation generator to store
- // reference to section object
- void* mpUserData;
-
-public:
- // universal identifier of the context (e.g. class name)
- string mName;
-
-public:
- // default constructor
- spContext();
-
- // automatically destorys all aggregated contexts
- // (thus, it's enought to call destructor of root-context)
- virtual ~spContext();
-
- // see mUererData member;
- void* GetUserData() { return mpUserData; }
-
- // sets untyped pointer to user data
- void SetUserData( void* pUserData )
- { mpUserData = pUserData; }
-
- // searches the whole context tree for the cotnexts
- // which match given masks, pust results into lst array
- void GetContextList( MMemberListT& lst, int contextMask );
-
- // used by default visitor's implementation
- bool IsSorted();
-
- /*** forward/reverse ingineering fecilities ***/
-
- bool PositionIsKnown();
-
- bool IsVirtualContext();
-
- bool VitualContextHasChildren();
-
- void SetVirtualContextBody( const string& body,
- bool hasChildren = FALSE,
- const string& footer = "" );
-
- string GetVirtualContextBody();
- string GetFooterOfVirtualContextBody();
-
- // can be overriden by top-level context classes
- // to find-out ot the source-fragment of this
- // context using it's position information
- virtual string GetBody( spContext* pCtx = NULL );
-
- virtual string GetHeader( spContext* pCtx = NULL );
-
- // TRUE, if there is at least one entry
- // in the comment list of this context
- bool HasComments();
- MCommentListT& GetCommentList() { return mComments; }
- const MCommentListT& GetCommentList() const { return mComments; }
-
- // should be overriden, if the context supports sorting
- // of it's members
- virtual void SortMembers() {}
-
- // returns identifier of this context
- inline string& GetName() { return mName; }
-
- // returns -1, if souce line # is unknow
- inline int GetSourceLineNo() { return mSrcLineNo; }
-
- // see comments on mpFirstOccurence member variable
- bool IsFirstOccurence();
- spContext* GetFirstOccurence();
-
- // returns not-NULL value if this context
- // is aggregated by another cotnext
- spContext* GetOutterContext();
-
- // perhaps more intuitive alias for `GetOutterContext()'
- inline spContext* GetParent() { return mpParent; }
-
- bool HasOutterContext();
-
- // add one aggregate (or child) into this context
- void AddMember ( spContext* pMember );
- MMemberListT& GetMembers();
-
- // append comment to the comment list decribing
- // this context
- void AddComment( spComment* pComment );
-
- // returns NULL, if the context with the given
- // name and type is not contained by this context
- // and it's children. Children's children are not
- // searched recursivelly if searchSubMembers is FALSE
-
- spContext* FindContext( const string& identifier,
- int contextType = SP_CTX_ANY,
- bool searchSubMembers = TRUE
- );
-
- // removes this context from it's parent
- // (NOTE:: context should have an outter cotnext
- // to when this method is called, otherwise removal
- // will result assertion failure)
- void RemoveThisContext();
-
- // returns TRUE, if this object is aggregated in the file
- bool IsInFile();
-
- // TRUE, if outter context is a namespace
- bool IsInNameSpace();
-
- // TRUE, if outter context is a class
- bool IsInClass();
-
- // TRUE, if outter cotext is an operation (TRUE for "spParameter"s)
- bool IsInOperation();
-
- // TRUE if the context is public
- bool IsPublic() const { return mVisibility == SP_VIS_PUBLIC; }
-
- // NOTE:: method returns not the type of this object
- // but the file/namespace/class/operation or file in which this
- // attribute is contained. First, check for the type of
- // context using the above method.
-
- // Requiering container which does not exist, will result
- // in assertion failure
-
- spClass& GetClass();
- spFile& GetFile();
- spNameSpace& GetNameSpace();
- spOperation& GetOperation();
-
- // each new context should override this method
- // to return it's specific type
- virtual int GetContextType() const { return SP_CTX_UNKNOWN; }
-
- // perhaps more intuitive short-cut
- inline int GetType() { return GetContextType(); }
-
- // cast this context to the desired type - returns NULL if type is wrong
- spAttribute *CastToAttribute()
- {
- return GetContextType() == SP_CTX_ATTRIBUTE ? (spAttribute *)this
- : NULL;
- }
-
- // derived classes override this to invoke VisitXXX method
- // which corresponds to the class of specific context,
- // - this is what the "Visitor" pattern told us ^)
-
- // if method is not overriden, then it's probably user-defined
- // custom context
-
- virtual void AcceptVisitor( spVisitor& visitor )
-
- { visitor.VisitCustomContext( *this ); };
-
- // called by visitors, to remove given subcontext
- // of this context object
- void RemoveChild( spContext* pChild );
-
- void RemoveChildren();
-
- spContext* GetEnclosingContext( int mask = SP_CTX_ANY );
-
-#ifdef __WXDEBUG__
- virtual void Dump(const wxString& indent) const;
-#endif // __WXDEBUG__
-
- DECLARE_DUMP
-};
-
-// stores information about single argument of operation
-
-class spParameter : public spContext
-{
-public:
- // type of argument (parameter)
- string mType;
-
- // "stringified" initial value
- string mInitVal;
-
-public:
- virtual int GetContextType() const { return SP_CTX_PARAMETER; }
-
- virtual void AcceptVisitor( spVisitor& visitor )
- { visitor.VisitParameter( *this ); }
-
- DECLARE_DUMP
-};
-
-
-// stores information about member(or global) variable
-
-class spAttribute : public spContext
-{
-public:
- // type of the attribute
- string mType;
-
- // it's initial value
- string mInitVal;
-
- // constantness
- bool mIsConstant;
-public:
-
- virtual int GetContextType() const { return SP_CTX_ATTRIBUTE; }
-
- virtual void AcceptVisitor( spVisitor& visitor )
- { visitor.VisitAttribute( *this ); }
-
- DECLARE_DUMP
-};
-
-class spOperation : public spContext
-{
-public:
- // type of return value
- string mRetType;
-
- // argument list
- //MParamListT mParams;
-
- // TRUE, if operation does not modify
- // the content of the object
- bool mIsConstant;
-
- // flag, specific to C++
- bool mIsVirtual;
-
- // TRUE, if definition follows the declaration immediatelly
- bool mHasDefinition;
-
- // scope if any (e.g. MyClass::MyFunction(), scope stirng is "MyClass" )
- // usually found along with implementation of the method, which is now skipped
-
- string mScope;
-
-public:
- spOperation();
-
- // returns full declaration of the operations
- // (ret val., identifier, arg. list),
-
- // arguments are marked up with italic,
- // default values marked up with bold-italic,
- // all the rest is marked as bold
-
- // NOTE:: this method may be overriden by class
- // specific to concrete parser, to provide
- // language-dependent reperesnetation of
- // operation and it's argumetn list
- //
- // the default implementation outputs name in
- // C++/Java syntax
-
- virtual string GetFullName(MarkupTagsT tags);
-
- virtual int GetContextType() const { return SP_CTX_OPERATION; }
-
- virtual void AcceptVisitor( spVisitor& visitor )
- { visitor.VisitOperation( *this ); }
-
- DECLARE_DUMP
-};
-
-// stores infromation about preprocessor directive
-
-class spPreprocessorLine : public spContext
-{
-
-public:
-
- // prepocessor statement including '#' and
- // attached multiple lines with '\' character
- string mLine;
-
- int mDefType; // see SP_PREP_DEFINITION_TYPES enumeration
-
-public:
-
- virtual int GetContextType() const { return SP_CTX_PREPROCESSOR; }
-
- virtual int GetStatementType() const { return mDefType; }
-
- string CPP_GetIncludedFileNeme() const;
-
- virtual void AcceptVisitor( spVisitor& visitor )
- { visitor.VisitPreprocessorLine( *this ); }
-
- DECLARE_DUMP
-};
-
-// stores information about the class
-
-class spClass : public spContext
-{
-public:
- // list of superclasses/interfaces
- StrListT mSuperClassNames;
-
- // see SP_CLASS_TYPES enumeration
- int mClassSubType;
-
- // see SP_INHERITANCE_TYPES enumeration
- int mInheritanceType;
-
- // valid if mClassSubType is SP_CLTYPE_TEMPLATE_CLASS
- string mTemplateTypes;
-
- // TRUE, if it's and interface of abstract base class
- bool mIsAbstract;
-
-public:
- // sorts class members in the following order:
- //
- // (by "privacy level" - first private, than protected, public)
- //
- // within above set
- //
- // (by member type - attributes first, than methods, nested classes)
- //
- // within above set
- //
- // (by identifier of the member)
-
- virtual void SortMembers();
-
- virtual int GetContextType() const { return SP_CTX_CLASS; }
-
- virtual void AcceptVisitor( spVisitor& visitor )
- { visitor.VisitClass( *this ); }
-
- DECLARE_DUMP
-};
-
-// stores information about enum statement
-
-class spEnumeration : public spContext
-{
-public:
- string mEnumContent; // full-text content of enumeration
-
-public:
- virtual int GetContextType() const { return SP_CTX_ENUMERATION; }
-
- virtual void AcceptVisitor( spVisitor& visitor )
- { visitor.VisitEnumeration( *this ); }
-
- DECLARE_DUMP
-};
-
-class spTypeDef : public spContext
-{
-public:
- // the original type which is redefined
- // by this type definition
- string mOriginalType;
-
-public:
- virtual int GetContextType() const { return SP_CTX_TYPEDEF; }
-
- virtual void AcceptVisitor( spVisitor& visitor )
- { visitor.VisitTypeDef( *this ); }
-
- DECLARE_DUMP
-};
-
-// NOTE:: files context may be put to other
-// file context, resulting in a collection
-// of parsed file contexts, with a virtual "superfile"
-
-class spFile : public spContext
-{
-public:
- // since file name cannot be determined from
- // source code, filling in this field is optional
- string mFileName;
-
-public:
- virtual int GetContextType() const { return SP_CTX_FILE; }
-
- virtual void AcceptVisitor( spVisitor& visitor )
- { visitor.VisitFile( *this ); }
-
- DECLARE_DUMP
-};
-
-//TODO:: comments.
-
-class SourceParserPlugin
-{
-public:
- virtual bool CanUnderstandContext( char* cur, char* end, spContext* pOuttterCtx ) = 0;
- virtual void ParseContext( char* start, char*& cur, char* end, spContext* pOuttterCtx ) = 0;
-};
-
-// abstract interface for source parsers
-// which can output parsing results in the
-// form of context-tree, where each node
-// should be derivative of spContext, (see
-// above classes)
-
-class SourceParserBase
-{
-private:
- // auto-resizing file buffer, created in ParseFile()
- // to reuse large heap block for multiple parsings
-
- char* mpFileBuf;
- int mFileBufSz;
-
-protected:
- SourceParserPlugin* mpPlugin;
-
-protected:
- // value is set in the derived parser classes
- int mParserStatus;
-
-public:
- SourceParserBase();
- virtual ~SourceParserBase();
-
- // loads entier source file(as text) into memory,
- // and passes it's contents to ParseAll() method,
- // memory occupied by source text is released after
- // parsing is done
- //
- // (NOTE:: this is the default implementation),
-
- virtual spFile* ParseFile( const char* fname );
-
- // should returns the root-node of the created context tree
- // (user is responsible for releasing it from the heep)
- // "end" should point to the (last character + 1) of the
- // source text area
-
- virtual spFile* Parse( char* start, char* end ) = 0;
-
- // returns parser "status word" (specific to concrete parser)
- int GetParserStatus() { return mParserStatus; }
-
- void SetPlugin( SourceParserPlugin* pPlugin );
-};
-
-#endif
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: No names yet.
-// Purpose: Contrib. demo
-// Author: Aleksandras Gluchovas
-// Modified by:
-// Created: 27/09/98
-// RCS-ID: $Id$
-// Copyright: (c) Aleskandars Gluchovas
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef __WXSTLAC_G__
-#define __WXSTLAC_G__
-
-#ifdef new
-#undef new
-#endif
-
-#include <stddef.h>
-#include <sys/types.h>
-#include <memory.h>
-#include <limits.h>
-#include <new.h>
-
-// the below macro used internally (see actual interface after this macro)
-
-// arguments:
-//
-// ARG_IS_UNIQUE
-// ASSOC_CONT_CLASS_NAME
-//
-// ARG_VALUE_TYPE
-// ARG_KEY_TYPE
-// ARG_ACTUAL_VALUE_TYPE
-//
-// _KEY_NAME
-// _VALUE_NAME
-//
-// _X_KEY_NAME
-// _X_VALUE_NAME
-//
-// _INSERT_METHOD_DEFINITION
-
-#define __DEFINE_ASOC_CLASS( ARG_IS_UNIQUE, \
-FUNCTOR,\
-ASSOC_CONT_CLASS_NAME, \
-ARG_VALUE_TYPE, \
-ARG_KEY_TYPE, \
-ARG_ACTUAL_VALUE_TYPE, \
-_KEY_NAME, \
-_VALUE_NAME, \
-_X_KEY_NAME, \
-_X_VALUE_NAME, \
-_INSERT_METHOD_DEFINITION \
-) class \
-ASSOC_CONT_CLASS_NAME\
-{\
-protected:\
-\
-public:\
- typedef ARG_VALUE_TYPE value_type;\
- typedef ARG_KEY_TYPE key_type;\
- typedef ARG_ACTUAL_VALUE_TYPE actual_value_type;\
-\
- typedef value_type* pointer;\
- typedef value_type& reference;\
-\
- typedef const value_type& const_reference;\
-\
- typedef FUNCTOR key_compare;\
- typedef key_compare Compare;\
-\
-protected:\
-\
- struct tree_node \
- {\
- tree_node* mpParent;\
- tree_node* mpLeft;\
- tree_node* mpRight;\
-\
- value_type mData;\
- };\
-\
- typedef tree_node* node_ref_type;\
-\
- node_ref_type mpRoot;\
- node_ref_type mpLeftMost;\
- node_ref_type mpRightMost;\
-\
- node_ref_type mpFreeListHead;\
- int mKeyIsUnique;\
-\
- key_compare mCmpFunctorObj;\
-\
-public:\
-\
- static inline node_ref_type next( node_ref_type pNode )\
- {\
- if ( pNode->mpRight ) \
- {\
- pNode = pNode->mpRight;\
-\
- while ( pNode->mpLeft ) pNode = pNode->mpLeft;\
-\
- return pNode;\
- }\
- else\
- if ( pNode->mpParent )\
- {\
- if ( pNode == pNode->mpParent->mpLeft )\
-\
- return pNode->mpParent;\
-\
- pNode = pNode->mpParent;\
-\
- node_ref_type prevNode = pNode;\
- pNode = pNode->mpParent;\
-\
- while(pNode)\
- {\
- if ( pNode->mpRight &&\
- pNode->mpRight != prevNode\
- ) return pNode;\
-\
- prevNode = pNode;\
- pNode= pNode->mpParent;\
- }\
-\
- return 0;\
- }\
- else\
- return 0;\
- }\
-\
- static inline node_ref_type prev( node_ref_type pNode )\
- {\
- if ( pNode->mpLeft ) \
- {\
- pNode = pNode->mpLeft;\
-\
- while ( pNode->mpRight ) pNode = pNode->mpRight;\
-\
- return pNode;\
- }\
- else\
- if ( pNode->mpParent )\
- {\
- if ( pNode == pNode->mpParent->mpRight )\
- return pNode->mpParent;\
-\
- pNode = pNode->mpParent;\
-\
- node_ref_type prevNode = pNode;\
- pNode = pNode->mpParent;\
-\
- while(pNode)\
- {\
- if ( pNode->mpLeft &&\
- pNode->mpLeft != prevNode\
- ) return pNode;\
-\
- prevNode = pNode;\
- pNode= pNode->mpParent;\
- }\
-\
- return 0;\
- }\
- else \
- return 0;\
- }\
-\
-protected:\
-\
- inline int are_equel( const key_type& x, const key_type& y )\
- {\
- return ( !mCmpFunctorObj(x,y) && !mCmpFunctorObj(y,x) );\
- }\
-\
- inline int is_less( const key_type& x, const key_type& y )\
- {\
- return mCmpFunctorObj(x,y);\
- }\
-\
- static inline const actual_value_type& value( node_ref_type pNode )\
- {\
- return pNode->_VALUE_NAME;\
- }\
-\
- static inline const key_type& key( node_ref_type pNode )\
- {\
- return pNode->_KEY_NAME;\
- }\
-\
- inline node_ref_type AllocNode() \
- { \
- if ( mpFreeListHead ) \
- {\
- node_ref_type pFreeNode = mpFreeListHead;\
- mpFreeListHead = mpFreeListHead->mpLeft;\
-\
- return pFreeNode;\
- }\
- else\
- {\
- char* pHeapBlock = new char[sizeof(tree_node)];\
-\
- return (node_ref_type)pHeapBlock;\
- }\
- }\
-\
- inline void DestroyFreeList()\
- {\
- while ( mpFreeListHead )\
- {\
- node_ref_type tmp = mpFreeListHead;\
- mpFreeListHead = mpFreeListHead->mpLeft;\
-\
- delete [](char*)tmp;\
- }\
- }\
-\
- inline void RecycleNode( node_ref_type pNode ) \
- {\
- pNode->mpLeft = mpFreeListHead;\
- mpFreeListHead = pNode;\
- }\
-\
- inline node_ref_type do_insert(const value_type& x = value_type() )\
- {\
- node_ref_type pNewNode = AllocNode();\
-\
- pNewNode->mpParent = \
- pNewNode->mpLeft =\
- pNewNode->mpRight = 0;\
-\
- node_ref_type pCurrent = mpRoot;\
- node_ref_type pParent = 0;\
- \
- while (pCurrent) \
- {\
- if ( mKeyIsUnique && are_equel( _X_KEY_NAME, value(pCurrent) ) )\
- {\
- RecycleNode(pNewNode);\
- return 0;\
- }\
-\
- pParent = pCurrent;\
-\
- pCurrent = is_less( _X_KEY_NAME, value(pCurrent) ) \
- ? pCurrent->mpLeft \
- : pCurrent->mpRight;\
- }\
- \
- pNewNode->mpParent = pParent;\
-\
- if(pParent)\
-\
- if( is_less(_X_KEY_NAME, value(pParent) ) )\
- \
- pParent->mpLeft = pNewNode;\
- else\
- pParent->mpRight = pNewNode;\
- else\
- mpRoot = pNewNode;\
-\
- new ( &pNewNode->_KEY_NAME ) key_type(_X_KEY_NAME);\
- new ( &pNewNode->_VALUE_NAME ) actual_value_type(_X_VALUE_NAME);\
-\
- if ( prev(pNewNode) == 0 ) mpLeftMost = pNewNode;\
- if ( next(pNewNode) == 0 ) mpRightMost = pNewNode;\
-\
- return pNewNode;\
- }\
-\
- friend class iterator;\
-\
-public:\
-\
- class iterator;\
- class const_iterator;\
-\
- class iterator \
- {\
- public:\
- node_ref_type mpNode;\
- friend class CONT_CLASS_NAME;\
- friend class const_iterator;\
- friend class const_reverse_iterator;\
-\
- inline iterator( node_ref_type pNode )\
- {\
- mpNode = pNode;\
- }\
- \
- public:\
- inline iterator() {}\
- inline int operator==( const iterator& rhs ) const { return (mpNode == rhs.mpNode); }\
- inline int operator!=( const iterator& rhs ) const { return (mpNode != rhs.mpNode); }\
-\
- inline iterator( const iterator& other )\
- {\
- mpNode = other.mpNode;\
- }\
-\
- inline const iterator& operator=( const iterator& other )\
- {\
- mpNode = other.mpNode;\
- return *this;\
- }\
-\
- inline const iterator& operator--() \
- {\
- mpNode = ASSOC_CONT_CLASS_NAME::prev(mpNode);\
- return *this;\
- }\
-\
- inline iterator operator--(int)\
- {\
- iterator tmp = *this;\
- mpNode = ASSOC_CONT_CLASS_NAME::prev(mpNode);\
- return tmp;\
- }\
-\
- inline const iterator& operator++() \
- {\
- mpNode = ASSOC_CONT_CLASS_NAME::next(mpNode);\
- return *this;\
- }\
-\
- inline iterator operator++(int)\
- {\
- iterator tmp = *this;\
- mpNode = ASSOC_CONT_CLASS_NAME::next(mpNode);\
- return tmp;\
- }\
-\
- inline reference operator*() const { return mpNode->mData; }\
- };\
-\
-\
- class const_iterator \
- {\
- public:\
- node_ref_type mpNode;\
- friend class CONT_CLASS_NAME;\
- friend class const_reverse_iterator;\
-\
- inline const_iterator( node_ref_type pNode )\
- {\
- mpNode = pNode;\
- }\
- \
- public:\
- inline const_iterator() {}\
-\
- inline int operator==( const const_iterator& rhs ) const { return (mpNode == rhs.mpNode); }\
- inline int operator!=( const const_iterator& rhs ) const { return (mpNode != rhs.mpNode); }\
-\
- inline const_iterator( const iterator& other )\
- {\
- mpNode = other.mpNode;\
- }\
-\
- inline const_iterator( const const_iterator& other )\
- {\
- mpNode = other.mpNode;\
- }\
-\
- inline const const_iterator& operator=( const const_iterator& other )\
- {\
- mpNode = other.mpNode;\
- return *this;\
- }\
-\
- inline const const_iterator& operator--() \
- {\
- mpNode = ASSOC_CONT_CLASS_NAME::prev(mpNode);\
- return *this;\
- }\
-\
- inline const_iterator operator--(int)\
- {\
- const_iterator tmp = *this;\
- mpNode = ASSOC_CONT_CLASS_NAME::prev(mpNode);\
- return tmp;\
- }\
-\
- inline const const_iterator& operator++() \
- {\
- mpNode = ASSOC_CONT_CLASS_NAME::next(mpNode);\
- return *this;\
- }\
-\
- inline const_iterator operator++(int)\
- {\
- const_iterator tmp = *this;\
- mpNode = ASSOC_CONT_CLASS_NAME::next(mpNode);\
- return tmp;\
- }\
-\
- inline const_reference operator*() const { return mpNode->mData; }\
- };\
-\
-public:\
-\
- inline ASSOC_CONT_CLASS_NAME( key_compare cmpFunctorObj = key_compare(),\
- int keyIsUnique = ARG_IS_UNIQUE )\
- : mpFreeListHead( 0 ),\
- mKeyIsUnique( keyIsUnique ),\
- mCmpFunctorObj( cmpFunctorObj )\
- {\
- mpLeftMost = 0;\
- mpRightMost = 0;\
- mpRoot = 0;\
- }\
-\
- inline ~ASSOC_CONT_CLASS_NAME() \
- { \
- erase( begin(), end() ); \
-\
- DestroyFreeList();\
- }\
-\
- inline iterator begin() { return mpLeftMost; }\
- inline iterator end() { return 0; }\
-\
- inline const_iterator begin() const { return mpLeftMost; }\
- inline const_iterator end() const { return 0; }\
-\
- inline iterator lower_bound( const key_type& x )\
- { \
- node_ref_type pCurrent = mpRoot;\
- \
- while( pCurrent )\
- {\
- node_ref_type pParent = pCurrent;\
-\
- if( are_equel( x, key(pCurrent) ) )\
- \
- return (pCurrent);\
- else\
- pCurrent = is_less( x, key(pCurrent) ) \
- ? pCurrent->mpLeft \
- : pCurrent->mpRight;\
-\
- if ( !pCurrent ) return (pParent);\
- }\
-\
- return begin();\
- }\
-\
- inline const_iterator lower_bound( const key_type& x ) const\
-\
- { return const_iterator( lower_bound(x).mpNode ); }\
-\
- inline iterator upper_bound( const key_type& x )\
- {\
- node_ref_type pCurrent = mpRoot;\
- \
- while( pCurrent )\
- {\
- node_ref_type pParent = pCurrent;\
-\
- if( are_equel( x, key(pCurrent) ) )\
- \
- return (pCurrent);\
- else\
- pCurrent = is_less( x, key(pCurrent) ) \
- ? pCurrent->mpLeft \
- : pCurrent->mpRight;\
-\
- if ( !pCurrent ) return next(pParent);\
- }\
-\
- return end();\
- }\
-\
- inline const_iterator upper_bound( const key_type& x ) const\
-\
- { return const_iterator( upper_bound(x).mpNode ); }\
-\
- inline iterator find( const key_type& x )\
- {\
- node_ref_type pCurrent = mpRoot;\
- \
- while( pCurrent )\
- {\
- if( are_equel( x, key(pCurrent) ) )\
- \
- return (pCurrent);\
- else\
- pCurrent = is_less( x, key(pCurrent) ) \
- ? pCurrent->mpLeft \
- : pCurrent->mpRight;\
- }\
-\
- return end();\
- }\
-\
- inline const_iterator find( const key_type& x ) const\
-\
- { return const_iterator( find(x).mpNode ); }\
-\
- inline void erase(iterator first, iterator last)\
- {\
- if ( first.mpNode == 0 ) return;\
-\
- while( first != last ) \
- {\
- iterator next = first;\
- ++next;\
- erase( first );\
- first = next;\
- }\
- }\
-\
- inline void erase(iterator position)\
- {\
- if ( position.mpNode == 0 ) return;\
-\
- node_ref_type pZ = position.mpNode;\
- node_ref_type pX, pY;\
-\
- if ( pZ == mpLeftMost ) mpLeftMost = next(pZ);\
- if ( pZ == mpRightMost ) mpRightMost = prev( pZ );\
-\
- if ( !pZ->mpLeft || !pZ->mpRight )\
- \
- pY = pZ;\
- else \
- {\
- pY = pZ->mpRight;\
- \
- while (pY->mpLeft) \
- \
- pY = pY->mpLeft;\
- }\
- \
- if ( pY->mpLeft)\
- \
- pX = pY->mpLeft;\
- else\
- pX = pY->mpRight;\
- \
- if ( pX ) pX->mpParent = pY->mpParent;\
- \
- if (pY->mpParent)\
- \
- if (pY == pY->mpParent->mpLeft )\
- \
- pY->mpParent->mpLeft = pX;\
- else\
- pY->mpParent->mpRight = pX;\
- else\
- mpRoot = pX;\
- \
- node_ref_type toRemove = 0;\
- \
- if (pY != pZ) {\
- \
- pY->mpLeft = pZ->mpLeft;\
- \
- if (pY->mpLeft) pY->mpLeft->mpParent = pY;\
- \
- pY->mpRight = pZ->mpRight;\
- \
- if ( pY->mpRight ) \
- \
- pY->mpRight->mpParent = pY;\
- \
- pY->mpParent = pZ->mpParent;\
- \
- if (pZ->mpParent)\
- \
- if (pZ == pZ->mpParent->mpLeft)\
- \
- pZ->mpParent->mpLeft = pY;\
- else\
- pZ->mpParent->mpRight = pY;\
- else\
- mpRoot = pY;\
- \
- toRemove = pZ;\
- } \
- else \
- toRemove = pY;\
- \
- value(toRemove).~actual_value_type();\
- key(toRemove).~actual_value_type();\
-\
- RecycleNode( toRemove );\
- }\
-\
- _INSERT_METHOD_DEFINITION\
-}
-
-// do not undefine ___WXSTL_COMMA, where associated containers are defined!
-// (it is used as workaround for constraints of C-Preprocessor's nested macros)
-
-#define ___WXSTL_COMMA ,
-
-#define __DEFINE_MAP(ARG_IS_UNIQUE, KEY_TYPE, VAL_TYPE, FUNCTOR ) __DEFINE_ASOC_CLASS( ARG_IS_UNIQUE,\
-FUNCTOR,\
-__WXSTLMAP_##KEY_TYPE##VAL_TYPE##ARG_IS_UNIQUE, \
-struct key_value_pair { KEY_TYPE first ; \
- VAL_TYPE second;\
- key_value_pair() {}\
- key_value_pair( const KEY_TYPE& key ___WXSTL_COMMA const VAL_TYPE& value ) \
- : first(key) ___WXSTL_COMMA second( value ) {} \
- } , \
-KEY_TYPE,\
-VAL_TYPE,\
-mData.first, mData.second, x.first, x.second, \
-struct insert_result_iterator\
-{\
- iterator first;\
- int second;\
-};\
-inline insert_result_iterator insert( const value_type& x )\
-{\
- insert_result_iterator result;\
-\
- result.first = do_insert(x);\
- result.second = ( result.first == end() ) ? 0 : 1;\
-\
- return result;\
-} )
-
-#define __DEFINE_SET(ARG_IS_UNIQUE, KEY_TYPE, FUNCTOR ) __DEFINE_ASOC_CLASS( ARG_IS_UNIQUE,\
-FUNCTOR,\
-__WXSTLSET_##TYPE##ARG_IS_UNIQUE, \
-KEY_TYPE,\
-KEY_TYPE,\
-KEY_TYPE,\
-mData, mData, x, x, \
-struct insert_result_iterator\
-{\
- iterator first;\
- int second;\
-};\
-inline insert_result_iterator insert( const value_type& x )\
-{\
- insert_result_iterator result;\
-\
- result.first = do_insert(x);\
- result.second = ( result.first == end() ) ? 0 : 1;\
-\
- return result;\
-} )
-
-// helper macros to create functor objects for associative containers of the given type
-
-#define LESS_THEN_FUNCTOR(TYPE) struct \
-{ inline int operator()(const TYPE& x, const TYPE& y ) const { return x < y; } }
-
-#define GREATER_THEN_FUNCTOR(TYPE) struct \
-{ inline int operator()(const TYPE& x, const TYPE& y ) const { return x > y; } }
-
-// functor argument should be created using the two above macros
-// or passing own class with method "operator()(const TYPE&,cosnt TYPE&)" defined in it
-
-#define WXSTL_MAP( KEY_TYPE, VALUE_TYPE, FUNCTOR ) __DEFINE_MAP( 1 ,KEY_TYPE, VALUE_TYPE, FUNCTOR)
-#define WXSTL_MULTIMAP( KEY_TYPE, VALUE_TYPE, FUNCTOR ) __DEFINE_MAP( 0 ,KEY_TYPE, VALUE_TYPE, FUNCTOR)
-#define WXSTL_SET( KEY_TYPE, FUNCTOR ) __DEFINE_SET( 1 ,KEY_TYPE, FUNCTOR )
-#define WXSTL_MULTISET( KEY_TYPE, FUNCTOR ) __DEFINE_SET( 0 ,KEY_TYPE, FUNCTOR )
-
-#endif
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: No names yet.
-// Purpose: Contrib. demo
-// Author: Aleksandras Gluchovas
-// Modified by:
-// Created: 27/09/98
-// RCS-ID: $Id$
-// Copyright: (c) Aleskandars Gluchovas
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef __WXSTLLST_G__
-#define __WXSTLLST_G__
-
-#ifdef new
-#undef new
-#endif
-
-#include <stddef.h>
-#include <sys/types.h>
-#include <memory.h>
-#include <limits.h>
-#include <new.h>
-
-// VERSION:: 0.2 (copy-constructor/adign-op added)
-
-// FOR NOW:: class-member operators "new" and "delete"
-// are ignored by list class, memory allocated
-// and freed using global operators
-
-typedef int Type;
-
-
-// the below macro used internally (see actual interface after this macro)
-
-#define __DEFINE_STL_LIST(listClass,Type) class \
- listClass \
-{\
-public:\
-\
- typedef Type value_type;\
- typedef value_type* pointer;\
- typedef const value_type* const_pointer;\
- typedef value_type& reference;\
- typedef const value_type& const_reference;\
- typedef size_t size_type;\
- typedef ptrdiff_t difference_type;\
-\
-protected:\
- struct list_node\
- {\
- list_node* mpNext;\
- list_node* mpPrev;\
- value_type mData;\
- };\
-\
- typedef list_node* node_ref_type;\
-\
- node_ref_type mpFreeListHead;\
- node_ref_type mpTerminator;\
- size_type mSize;\
-\
- inline node_ref_type AllocNode() \
- { \
- if ( mpFreeListHead ) \
- {\
- node_ref_type pFreeNode = mpFreeListHead;\
- mpFreeListHead = mpFreeListHead->mpPrev;\
-\
- return pFreeNode;\
- }\
- else\
- {\
- char* pHeapBlock = new char[sizeof(list_node)];\
-\
- return (node_ref_type)pHeapBlock;\
- }\
- }\
-\
- inline void DestroyFreeList()\
- {\
- while ( mpFreeListHead )\
- {\
- node_ref_type tmp = mpFreeListHead;\
- mpFreeListHead = mpFreeListHead->mpPrev;\
-\
- delete [](char*)tmp;\
- }\
- }\
-\
- inline void RecycleNode( node_ref_type pNode ) \
- {\
- pNode->mpPrev = mpFreeListHead;\
- mpFreeListHead = pNode;\
- }\
-\
-public:\
-\
- class iterator \
- {\
- public:\
- node_ref_type mpNode;\
- friend class listClass;\
- friend class const_iterator;\
- friend class const_reverse_iterator;\
-\
- protected:\
- iterator( node_ref_type pNode )\
- {\
- mpNode = pNode;\
- }\
- \
- public:\
- iterator() {}\
- int operator==( const iterator& rhs ) const { return (mpNode == rhs.mpNode); }\
- int operator!=( const iterator& rhs ) const { return (mpNode != rhs.mpNode); }\
-\
- inline iterator( const iterator& other )\
- {\
- mpNode = other.mpNode;\
- }\
-\
- inline const iterator& operator--() \
- {\
- mpNode = mpNode->mpPrev;\
- return *this;\
- }\
-\
- inline iterator operator--(int)\
- {\
- iterator tmp = *this;\
- mpNode = mpNode->mpPrev;\
- return tmp;\
- }\
-\
- inline const iterator& operator++() \
- {\
- mpNode = mpNode->mpNext;\
- return *this;\
- }\
-\
- inline iterator operator++(int)\
- {\
- iterator tmp = *this;\
- mpNode = mpNode->mpNext;\
- return tmp;\
- }\
-\
- inline reference operator*() const { return mpNode->mData; }\
- };\
-\
-\
- class const_iterator \
- {\
- protected:\
- node_ref_type mpNode;\
- friend class listClass;\
-\
- protected:\
- const_iterator( node_ref_type pNode )\
- {\
- mpNode = pNode;\
- }\
- \
- public:\
- \
- const_iterator() {}\
- int operator==( const const_iterator& rhs ) const { return (mpNode == rhs.mpNode); }\
- int operator!=( const const_iterator& rhs ) const { return (mpNode != rhs.mpNode); }\
-\
-\
- inline const_iterator( const iterator& other )\
- {\
- mpNode = other.mpNode;\
- }\
-\
- inline const const_iterator& operator--() \
- {\
- mpNode = mpNode->mpPrev;\
- return *this;\
- }\
-\
- inline const_iterator operator--(int)\
- {\
- const_iterator tmp = *this;\
- mpNode = mpNode->mpPrev;\
- return tmp;\
- }\
-\
- inline const const_iterator& operator++() \
- {\
- mpNode = mpNode->mpNext;\
- return *this;\
- }\
-\
- inline const_iterator operator++(int)\
- {\
- const_iterator tmp = *this;\
- mpNode = mpNode->mpNext;\
- return tmp;\
- }\
-\
- inline const_reference operator*() const { return mpNode->mData; }\
- };\
-\
- typedef iterator OutputIterator;\
- typedef const_iterator InputIterator;\
-\
- class reverse_iterator \
- {\
- public:\
- node_ref_type mpNode;\
- friend class listClass;\
- friend class const_reverse_iterator;\
-\
- protected:\
- reverse_iterator ( node_ref_type pNode )\
- {\
- mpNode = pNode;\
- }\
- \
- public:\
-\
- reverse_iterator() {}\
- int operator==( const reverse_iterator& rhs ) const { return (mpNode == rhs.mpNode); }\
- int operator!=( const reverse_iterator& rhs ) const { return (mpNode != rhs.mpNode); }\
-\
- inline reverse_iterator( const reverse_iterator& other )\
- {\
- mpNode = other.mpNode;\
- }\
-\
- inline const reverse_iterator& operator--() \
- {\
- mpNode = mpNode->mpNext;\
- return *this;\
- }\
-\
- inline reverse_iterator operator--(int)\
- {\
- reverse_iterator tmp = *this;\
- mpNode = mpNode->mpPrev;\
- return tmp;\
- }\
-\
- inline const reverse_iterator & operator++() \
- {\
- mpNode = mpNode->mpNext;\
- return *this;\
- }\
-\
- inline reverse_iterator operator++(int)\
- {\
- reverse_iterator tmp = *this;\
- mpNode = mpNode->mpPrev;\
- return tmp;\
- }\
-\
- inline const_reference operator*() const { return mpNode->mData; }\
- };\
-\
-\
- class const_reverse_iterator \
- {\
- protected:\
- node_ref_type mpNode;\
- friend class listClass;\
-\
- protected:\
- const_reverse_iterator( node_ref_type pNode )\
- {\
- mpNode = pNode;\
- }\
- \
- public:\
-\
- const_reverse_iterator() {}\
- int operator==( const const_reverse_iterator& rhs ) const { return (mpNode == rhs.mpNode); }\
- int operator!=( const const_reverse_iterator& rhs ) const { return (mpNode != rhs.mpNode); }\
-\
- inline const_reverse_iterator( const reverse_iterator& other )\
- {\
- mpNode = other.mpNode;\
- }\
-\
- inline const const_reverse_iterator& operator--() \
- {\
- mpNode = mpNode->mpNext;\
- return *this;\
- }\
-\
- inline const_reverse_iterator operator--(int)\
- {\
- const_reverse_iterator tmp = *this;\
- mpNode = mpNode->mpNext;\
- return tmp;\
- }\
-\
- inline const const_reverse_iterator& operator++() \
- {\
- mpNode = mpNode->mpPrev;\
- return *this;\
- }\
-\
- inline const_reverse_iterator operator++(int)\
- {\
- const_reverse_iterator tmp = *this;\
- mpNode = mpNode->mpPrev;\
- return tmp;\
- }\
-\
- inline const_reference operator*() const { return mpNode->mData; }\
- };\
-\
-public:\
-\
- inline listClass()\
- : mpFreeListHead( 0 ),\
- mSize(0)\
- {\
- mpTerminator = AllocNode();\
- mpTerminator->mpPrev = mpTerminator->mpNext = mpTerminator;\
- }\
-\
- listClass( const listClass& other )\
- {\
- mpTerminator = AllocNode();\
- mpTerminator->mpPrev = mpTerminator->mpNext = mpTerminator;\
-\
- for( listClass::const_iterator i = other.begin(); i != other.end(); ++i )\
-\
- push_back( (*i) );\
- }\
-\
- inline const listClass& operator=( const listClass& rhs ) \
- {\
- erase( begin(), end() );\
-\
- for( listClass::const_iterator i = rhs.begin(); i != rhs.end(); ++i )\
-\
- push_back( (*i) );\
-\
- return *this;\
- }\
-\
- inline listClass(const_iterator first, const_iterator last)\
- : mpFreeListHead( 0 ),\
- mSize(0)\
- \
- { while( first != last ) push_back( *first++ ); }\
-\
- inline listClass( size_type n, const value_type& value = value_type() )\
- \
- { for( size_t i = 0; i != n; ++n ) push_back( value ); }\
-\
- inline ~listClass() \
- { \
- erase( begin(), end() ); \
-\
- RecycleNode( mpTerminator );\
- DestroyFreeList();\
- }\
-\
- inline iterator begin() { return iterator(mpTerminator->mpNext); }\
- \
- inline const_iterator begin() const \
- { return const_iterator(mpTerminator->mpNext); }\
- \
- inline iterator end() { return iterator(mpTerminator); }\
-\
- inline const_iterator end() const { return const_iterator(mpTerminator); }\
-\
- inline reverse_iterator rbegin() \
- { return reverse_iterator(mpTerminator->mpPrev); }\
-\
- inline reverse_iterator rend() \
- { return reverse_iterator(mpTerminator); }\
-\
- inline const_reverse_iterator rbegin() const\
- { return const_reverse_iterator(mpTerminator->mpPrev); }\
-\
- inline const_reverse_iterator rend() const\
- { return const_reverse_iterator(mpTerminator); }\
-\
- inline int empty() const { return (mSize == 0); }\
-\
- inline size_type size() const { return mSize; }\
-\
- inline size_type max_size() const { return UINT_MAX/sizeof(list_node); }\
-\
- inline reference front() { return mpTerminator->mData; }\
-\
- inline const_reference front() const { return mpTerminator->mData; }\
-\
- inline reference back() { return mpTerminator->mpPrev->mData; }\
-\
- inline const_reference back() const { return mpTerminator->mpPrev->mData; }\
-\
- inline void push_front(const value_type& x) { insert( begin(), x ); }\
-\
- inline void push_back(const value_type& x) { insert( end(), x ); }\
-\
- iterator insert(iterator position, const value_type& x = value_type())\
- {\
- node_ref_type pNew = AllocNode();\
-\
- node_ref_type pos = *((node_ref_type*)&position);\
-\
- pNew->mpNext = pos;\
- pNew->mpPrev = pos->mpPrev;\
- pos->mpPrev->mpNext = pNew;\
- pos->mpPrev = pNew;\
-\
- new (&pNew->mData) value_type(x);\
-\
- ++mSize;\
-\
- return iterator(pNew);\
- }\
-\
- inline void insert(iterator position, const_iterator first, const_iterator last )\
- {\
- while( first != last ) insert( position, *first++ );\
- }\
-\
- inline void splice( iterator position, listClass& other )\
- {\
- if ( other.begin() == other.end() ) return;\
-\
- node_ref_type pTill = other.mpTerminator->mpPrev;\
- node_ref_type pFrom = other.begin().mpNode;\
-\
- mpTerminator->mpPrev->mpNext = pFrom;\
- pFrom->mpPrev = mpTerminator->mpPrev->mpNext;\
-\
- pTill->mpNext = mpTerminator;\
- mpTerminator->mpPrev = pTill;\
-\
- other.mpTerminator->mpNext = \
- other.mpTerminator->mpPrev = other.mpTerminator;\
-\
- mSize += other.mSize;\
- other.mSize = 0;\
- }\
-\
- inline void splice( iterator position, listClass& other, iterator first, iterator last )\
- {\
- if ( first == last ) return;\
-\
- size_type sz = 0;\
- iterator tmp = first;\
- while( tmp != last ) \
- {\
- ++tmp;\
- ++sz;\
- }\
-\
- mSize += sz;\
- other.mSize -= sz;\
-\
- node_ref_type pPos = position.mpNode;\
- node_ref_type pFirst = first.mpNode;\
- node_ref_type pLast = last.mpNode;\
- node_ref_type pTill = last.mpNode->mpPrev;\
-\
- pPos->mpPrev->mpNext = pFirst;\
- pPos->mpPrev = pTill;\
-\
- pFirst->mpPrev->mpNext = last.mpNode;\
- pLast->mpPrev = pTill;\
-\
- pFirst->mpPrev = pPos->mpPrev;\
- pTill->mpNext = pPos;\
- }\
-\
- inline void pop_front() { erase( begin() ); }\
- inline void pop_back() { erase( --end() ); }\
- \
- inline void erase(iterator position)\
- {\
- erase( position, ++position );\
- }\
- \
- inline void erase(iterator first, iterator last)\
- {\
- node_ref_type firstNode = *((node_ref_type*)&first);\
- node_ref_type lastNode = *((node_ref_type*)&last);\
-\
- firstNode->mpPrev->mpNext = lastNode;\
- lastNode->mpPrev = firstNode->mpPrev;\
-\
- while( firstNode != lastNode )\
- {\
- node_ref_type next = firstNode->mpNext;\
-\
- typedef value_type value_type_local;\
- firstNode->mData.value_type_local::~value_type_local();\
-\
- RecycleNode( firstNode );\
-\
- firstNode = next;\
-\
- --mSize;\
- }\
- }\
-\
- inline void remove(const value_type& value)\
- {\
- for( iterator i = begin(); i != end(); ++i )\
- \
- if ( (*i) == value ) \
- {\
- erase( i ); break;\
- }\
- }\
-\
- void sort()\
- {\
- if ( mSize < 2 ) return;\
-\
- iterator from = begin();\
- iterator other_end = end();\
- --other_end;\
-\
- for( size_type i = 0; i != mSize; ++i )\
- {\
- size_type nSwaps = 0;\
-\
- iterator next = begin();\
- ++next;\
-\
- for( iterator j = begin(); j != other_end; ++j )\
- {\
-\
- if ( (*next) < (*j) )\
- {\
- value_type tmp = (*j);\
- (*j) = (*next);\
- (*next) = tmp;\
-\
- ++nSwaps;\
- }\
-\
- ++next;\
- }\
-\
- if ( !nSwaps) break;\
-\
- --other_end;\
- }\
- }\
-}
-
-// defines list class with the given element type
-#define WXSTL_LIST(ELEMENT_CLASS) __DEFINE_STL_LIST(\
-\
-_WXSTL_LIST_##ELEMENT_CLASS, ELEMENT_CLASS )
-
-#endif
\ No newline at end of file
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: No names yet.
-// Purpose: Contrib. demo
-// Author: Aleksandras Gluchovas
-// Modified by:
-// Created: 27/09/98
-// RCS-ID: $Id$
-// Copyright: (c) Aleskandars Gluchovas
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef __WXSTLVEC_G__
-#define __WXSTLVEC_G__
-
-#ifdef new
-#undef new
-#endif
-
-#include <memory.h>
-#include <string.h> // imports memmove()
-#include <stddef.h>
-#include <sys/types.h>
-#include <limits.h>
-#include <new>
-
-// the below macro used internally (see actual interface after this macro)
-
-#define __DEFINE_STL_VECTOR_DEEP( vectorClass, Type ) class vectorClass {\
-\
-public:\
- typedef Type value_type;\
- typedef value_type* iterator;\
- typedef const value_type* const_iterator;\
- typedef iterator pointer;\
- typedef const iterator const_pointer;\
- typedef value_type& reference;\
- typedef const value_type& const_reference;\
- typedef size_t size_type;\
- typedef ptrdiff_t difference_type;\
-\
- typedef iterator OutputIterator;\
- typedef const_iterator InputIterator;\
-\
-protected:\
-\
- inline void PlacementCopy( const_iterator first, const_iterator last, iterator result )\
- {\
- while ( first != last ) \
- new (result++) value_type(*first++);\
- }\
-\
- inline void ConstructObjects( iterator first, iterator last, const value_type& pattern )\
- {\
- while( first != last ) \
- new (first++) value_type(pattern);\
- }\
-\
- inline void CopyObjects( iterator first, iterator last, iterator result )\
- {\
- while( first != last ) \
- *result++ = *first++;\
- }\
-\
- inline void CopyObjectsBack( iterator first, iterator last, iterator result )\
- {\
- result += difference_type(last,first);\
-\
- while( first != last ) \
- *(--result) = *(--last);\
- }\
-\
-public:\
-\
- class reverse_iterator \
- {\
- friend class vectorClass;\
- friend class const_reverse_iterator;\
-\
- public:\
- iterator mpPos;\
-\
- public:\
-\
- reverse_iterator() {}\
-\
- reverse_iterator ( iterator pPos )\
- {\
- mpPos = pPos;\
- }\
- \
- int operator==( const reverse_iterator& rhs ) const { return (mpPos == rhs.mpPos); }\
- int operator!=( const reverse_iterator& rhs ) const { return (mpPos != rhs.mpPos); }\
-\
- inline reverse_iterator( const reverse_iterator& other )\
- {\
- mpPos = other.mpPos;\
- }\
-\
- inline const reverse_iterator& operator--() \
- {\
- --mpPos;\
- return *this;\
- }\
-\
- inline reverse_iterator operator--(int)\
- {\
- reverse_iterator tmp = *this;\
- --mpPos;\
- return tmp;\
- }\
-\
- inline const reverse_iterator & operator++() \
- {\
- ++mpPos;\
- return *this;\
- }\
-\
- inline reverse_iterator operator++(int)\
- {\
- reverse_iterator tmp = *this;\
- ++mpPos;\
- return tmp;\
- }\
-\
- inline const_reference operator*() const { return *mpPos; }\
- };\
-\
-\
- class const_reverse_iterator \
- {\
- protected:\
- iterator mpPos;\
- public:\
-\
- const_reverse_iterator() {}\
-\
- const_reverse_iterator( const iterator pPos )\
- {\
- mpPos = pPos;\
- }\
- \
- int operator==( const const_reverse_iterator& rhs ) const { return (mpPos == rhs.mpPos); }\
- int operator!=( const const_reverse_iterator& rhs ) const { return (mpPos != rhs.mpPos); }\
-\
- inline const_reverse_iterator( const reverse_iterator& other )\
- {\
- mpPos = other.mpPos;\
- }\
-\
- inline const const_reverse_iterator& operator--() \
- {\
- --mpPos;\
- return *this;\
- }\
-\
- inline const_reverse_iterator operator--(int)\
- {\
- const_reverse_iterator tmp = *this;\
- --mpPos;\
- return tmp;\
- }\
-\
- inline const const_reverse_iterator & operator++() \
- {\
- ++mpPos;\
- return *this;\
- }\
-\
- inline const_reverse_iterator operator++(int)\
- {\
- const_reverse_iterator tmp = *this;\
- ++mpPos;\
- return tmp;\
- }\
-\
- inline const_reference operator*() const { return *mpPos; }\
- };\
-\
-protected:\
- \
- pointer mpStart;\
- pointer mpEnd;\
- pointer mpEndOfBuf;\
-\
-protected:\
-\
- inline void quick_sort(int low, int hi) \
- {\
- }\
-\
- inline void DestructRange( iterator first, iterator last )\
- {\
- typedef value_type value_type_local;\
-\
- while ( first != last ) \
- {\
- first->value_type_local::~value_type_local();\
- ++first;\
- }\
- }\
-\
- inline iterator DoInsert(iterator position, const value_type& x)\
- {\
- if ( mpEnd < mpEndOfBuf )\
- {\
- new (mpEnd) value_type(*(mpEnd-1) );\
- \
- CopyObjectsBack( position, mpEnd, position + 1 );\
- \
- *position = x;\
- \
- ++mpEnd;\
- \
- return position;\
- }\
- \
- size_type minBufLen = WXSTL_VECTOR_MIN_BUF_SIZE/sizeof(value_type);\
- \
- size_type doubledSize = size()*2;\
- \
- size_type newLen = ( doubledSize < minBufLen ) ? minBufLen : doubledSize;\
- \
- iterator pNewStart = (iterator)( new char[newLen*sizeof(value_type)] );\
- \
- PlacementCopy( mpStart, position, pNewStart );\
- \
- iterator atPosition = pNewStart + difference_type( position - mpStart );\
- \
- new (atPosition) value_type(x);\
- \
- iterator newPos = atPosition;\
- \
- ++atPosition;\
- \
- if ( mpStart ) \
- {\
- PlacementCopy( position, mpEnd, atPosition );\
- DestructRange( mpStart, mpEnd );\
- delete [](char*)mpStart;\
- }\
- \
- mpEnd = atPosition + difference_type( mpEnd - position );\
- \
- mpStart = pNewStart;\
- mpEndOfBuf = pNewStart + newLen;\
- \
- return newPos;\
- }\
-\
-public:\
-\
- inline vectorClass() : mpStart(0), \
- mpEnd(0),\
- mpEndOfBuf(0)\
- {}\
-\
- inline vectorClass( const_iterator first, const_iterator last )\
- : mpStart(0),\
- mpEnd(0),\
- mpEndOfBuf(0)\
- \
- { while( first != last ) push_back( *first++ ); }\
-\
- inline vectorClass( size_type n, const value_type& value = value_type() )\
- : mpStart(0),\
- mpEnd(0),\
- mpEndOfBuf(0)\
- \
- { for( size_type i = 0; i != n; ++i ) push_back( value ); }\
-\
- inline const vectorClass& operator=( const vectorClass& other )\
- {\
- if (mpStart) \
- {\
- DestructRange( begin(), end() );\
- delete [](char*)mpStart; \
- }\
-\
- size_t newLen = difference_type( other.mpEndOfBuf - other.mpStart );\
-\
- mpStart = (iterator)( new char[newLen*sizeof(value_type)] );\
-\
- PlacementCopy( other.begin(), other.end(), mpStart );\
-\
- mpEnd = mpStart + other.size();\
-\
- mpEndOfBuf = mpStart + newLen;\
-\
- return *this;\
- }\
-\
- inline vectorClass( const vectorClass& other )\
- : mpStart(0),\
- mpEnd(0),\
- mpEndOfBuf(0)\
- {\
- this->operator=( other );\
- }\
-\
- inline ~vectorClass() \
- { \
- if (mpStart) \
- {\
- DestructRange( begin(), end() );\
- delete [](char*)mpStart; \
- }\
- }\
-\
- inline iterator begin() { return mpStart; }\
-\
- inline const_iterator begin() const { return mpStart; }\
-\
- inline iterator end() { return mpEnd; }\
-\
- inline const_iterator end() const { return mpEnd; }\
-\
- inline size_type size() const { return (size_type)difference_type(mpEnd-mpStart); }\
-\
- inline size_type max_size() const { return UINT_MAX/sizeof(value_type); }\
-\
- inline size_type capacity() const \
- { return difference_type(mpEndOfBuf-mpStart)/sizeof(value_type); }\
-\
- inline int empty() const { return mpStart == mpEnd; }\
-\
- inline reference operator[](size_type n) { return *(mpStart+n); }\
-\
- inline const_reference operator[](size_type n) const { return *(mpStart+n); }\
-\
- inline reference front() { return (*mpStart); }\
- \
- inline const_reference front() const { return (*mpStart); }\
-\
- inline reference back() { return (*(mpEnd-1)); }\
-\
- inline const_reference back() const { return (*(mpEnd-1)); }\
-\
- inline void reserve(size_type n) {}\
-\
- inline void push_back(const value_type& x)\
- {\
- if ( mpEnd != mpEndOfBuf ) \
- {\
- new (mpEnd) value_type(x);\
- ++mpEnd;\
- }\
- else\
- DoInsert( mpEnd, x );\
- }\
-\
- inline iterator insert(iterator position, const value_type& x = value_type())\
- {\
- if ( position == mpEnd && mpEnd != mpEndOfBuf )\
- {\
- new (mpEnd) value_type(x);\
- ++mpEnd;\
- return (mpEnd-1);\
- }\
- else return DoInsert( position, x );\
- }\
-\
- inline void pop_back()\
- {\
- DestructRange( mpEnd-1, mpEnd );\
-\
- --mpEnd;\
- }\
-\
- inline void erase(iterator first, iterator last)\
- {\
- if ( last == mpEnd )\
- {\
- DestructRange( first, last );\
- mpEnd = first;\
- return;\
- }\
- \
- CopyObjects( last, last + difference_type( mpEnd - last ), first );\
- \
- iterator newEnd = mpEnd - difference_type( last - first );\
- DestructRange( newEnd, mpEnd );\
- \
- mpEnd = newEnd;\
- }\
-\
- inline void erase( iterator position )\
- {\
- erase( position, position + 1 );\
- }\
-\
- inline void sort()\
- {\
- if ( size() < 2 ) return;\
- quick_sort( 0, size()-1 );\
- }\
-}
-
-/////////////////////////////// shallow-copy container ///////////////////////
-
-#define __DEFINE_STL_VECTOR_SHALLOW( vectorClass, Type ) class vectorClass {\
-\
-public:\
- typedef Type value_type;\
- typedef value_type* iterator;\
- typedef const value_type* const_iterator;\
- typedef iterator pointer;\
- typedef const iterator const_pointer;\
- typedef value_type& reference;\
- typedef const value_type& const_reference;\
- typedef size_t size_type;\
- typedef ptrdiff_t difference_type;\
-\
- typedef iterator OutputIterator;\
- typedef const_iterator InputIterator;\
-\
-protected:\
-\
- inline void PlacementCopy( const_iterator first, const_iterator last, iterator result )\
- {\
- memcpy(result, first, int(difference_type(last-first)*sizeof(value_type)) );\
- }\
-\
- inline void ConstructObjects( iterator first, iterator last, const value_type& pattern )\
- {\
- if ( sizeof(pattern) == 1 )\
- \
- memset( first, int(difference_type(last-first)/sizeof(value_type)), \
- int(*((char*)&pattern)) );\
- else\
- while( first != last ) \
- *first++ = pattern;\
- }\
-\
- inline void CopyObjects( iterator first, iterator last, iterator result )\
- {\
- memcpy(result, first, int(difference_type(last-first)*sizeof(value_type)) );\
- }\
-\
- inline void CopyObjectsBack( iterator first, iterator last, iterator result )\
- {\
- memmove(result, first, int(difference_type(last-first)*sizeof(value_type)) );\
- }\
-\
-public:\
-\
- class reverse_iterator \
- {\
- friend class vectorClass;\
- friend class const_reverse_iterator;\
-\
- public:\
- iterator mpPos;\
-\
- public:\
-\
- reverse_iterator() {}\
-\
- reverse_iterator ( iterator pPos )\
- {\
- mpPos = pPos;\
- }\
- \
- int operator==( const reverse_iterator& rhs ) const { return (mpPos == rhs.mpPos); }\
- int operator!=( const reverse_iterator& rhs ) const { return (mpPos != rhs.mpPos); }\
-\
- inline reverse_iterator( const reverse_iterator& other )\
- {\
- mpPos = other.mpPos;\
- }\
-\
- inline const reverse_iterator& operator--() \
- {\
- --mpPos;\
- return *this;\
- }\
-\
- inline reverse_iterator operator--(int)\
- {\
- reverse_iterator tmp = *this;\
- --mpPos;\
- return tmp;\
- }\
-\
- inline const reverse_iterator & operator++() \
- {\
- ++mpPos;\
- return *this;\
- }\
-\
- inline reverse_iterator operator++(int)\
- {\
- reverse_iterator tmp = *this;\
- ++mpPos;\
- return tmp;\
- }\
-\
- inline const_reference operator*() const { return *mpPos; }\
- };\
-\
-\
- class const_reverse_iterator \
- {\
- protected:\
- iterator mpPos;\
- public:\
-\
- const_reverse_iterator() {}\
-\
- const_reverse_iterator( const iterator pPos )\
- {\
- mpPos = pPos;\
- }\
- \
- int operator==( const const_reverse_iterator& rhs ) const { return (mpPos == rhs.mpPos); }\
- int operator!=( const const_reverse_iterator& rhs ) const { return (mpPos != rhs.mpPos); }\
-\
- inline const_reverse_iterator( const reverse_iterator& other )\
- {\
- mpPos = other.mpPos;\
- }\
-\
- inline const const_reverse_iterator& operator--() \
- {\
- --mpPos;\
- return *this;\
- }\
-\
- inline const_reverse_iterator operator--(int)\
- {\
- const_reverse_iterator tmp = *this;\
- --mpPos;\
- return tmp;\
- }\
-\
- inline const const_reverse_iterator & operator++() \
- {\
- ++mpPos;\
- return *this;\
- }\
-\
- inline const_reverse_iterator operator++(int)\
- {\
- const_reverse_iterator tmp = *this;\
- ++mpPos;\
- return tmp;\
- }\
-\
- inline const_reference operator*() const { return *mpPos; }\
- };\
-\
-protected:\
- \
- pointer mpStart;\
- pointer mpEnd;\
- pointer mpEndOfBuf;\
-\
-protected:\
-\
- inline void quick_sort(int low, int hi) \
- {\
- }\
-\
- inline void DestructRange( iterator first, iterator last )\
- {\
- }\
-\
- inline iterator DoInsert(iterator position, const value_type& x)\
- {\
- if ( mpEnd < mpEndOfBuf )\
- {\
- new (mpEnd) value_type(*(mpEnd-1) );\
- \
- CopyObjectsBack( position, mpEnd, position + 1 );\
- \
- *position = x;\
- \
- ++mpEnd;\
- \
- return position;\
- }\
- \
- size_type minBufLen = WXSTL_VECTOR_MIN_BUF_SIZE/sizeof(value_type);\
- \
- size_type doubledSize = size()*2;\
- \
- size_type newLen = ( doubledSize < minBufLen ) ? minBufLen : doubledSize;\
- \
- iterator pNewStart = (iterator)( new char[newLen*sizeof(value_type)] );\
- \
- PlacementCopy( mpStart, position, pNewStart );\
- \
- iterator atPosition = pNewStart + difference_type( position - mpStart );\
- \
- new (atPosition) value_type(x);\
- \
- iterator newPos = atPosition;\
- \
- ++atPosition;\
- \
- if ( mpStart ) \
- {\
- PlacementCopy( position, mpEnd, atPosition );\
- DestructRange( mpStart, mpEnd );\
- delete [](char*)mpStart;\
- }\
- \
- mpEnd = atPosition + difference_type( mpEnd - position );\
- \
- mpStart = pNewStart;\
- mpEndOfBuf = pNewStart + newLen;\
- \
- return newPos;\
- }\
-\
-public:\
-\
- inline vectorClass() : mpStart(0), \
- mpEnd(0),\
- mpEndOfBuf(0)\
- {}\
-\
- inline vectorClass( const_iterator first, const_iterator last )\
- : mpStart(0),\
- mpEnd(0),\
- mpEndOfBuf(0)\
- \
- { while( first != last ) push_back( *first++ ); }\
-\
- inline vectorClass( size_type n, const value_type& value = value_type() )\
- : mpStart(0),\
- mpEnd(0),\
- mpEndOfBuf(0)\
- \
- { for( size_type i = 0; i != n; ++i ) push_back( value ); }\
-\
- inline const vectorClass& operator=( const vectorClass& other )\
- {\
- if (mpStart) \
- {\
- DestructRange( begin(), end() );\
- delete [](char*)mpStart; \
- }\
-\
- size_t newLen = difference_type( other.mpEndOfBuf - other.mpStart );\
-\
- mpStart = (iterator)( new char[newLen*sizeof(value_type)] );\
-\
- PlacementCopy( other.begin(), other.end(), mpStart );\
-\
- mpEnd = mpStart + other.size();\
-\
- mpEndOfBuf = mpStart + newLen;\
-\
- return *this;\
- }\
-\
- inline vectorClass( const vectorClass& other )\
- : mpStart(0),\
- mpEnd(0),\
- mpEndOfBuf(0)\
- {\
- this->operator=( other );\
- }\
-\
- inline ~vectorClass() \
- { \
- if (mpStart) \
- {\
- DestructRange( begin(), end() );\
- delete [](char*)mpStart; \
- }\
- }\
-\
- inline iterator begin() { return mpStart; }\
-\
- inline const_iterator begin() const { return mpStart; }\
-\
- inline iterator end() { return mpEnd; }\
-\
- inline const_iterator end() const { return mpEnd; }\
-\
- inline size_type size() const { return (size_type)difference_type(mpEnd-mpStart); }\
-\
- inline size_type max_size() const { return UINT_MAX/sizeof(value_type); }\
-\
- inline size_type capacity() const \
- { return difference_type(mpEndOfBuf-mpStart)/sizeof(value_type); }\
-\
- inline int empty() const { return mpStart == mpEnd; }\
-\
- inline reference operator[](size_type n) { return *(mpStart+n); }\
-\
- inline const_reference operator[](size_type n) const { return *(mpStart+n); }\
-\
- inline reference front() { return (*mpStart); }\
- \
- inline const_reference front() const { return (*mpStart); }\
-\
- inline reference back() { return (*(mpEnd-1)); }\
-\
- inline const_reference back() const { return (*(mpEnd-1)); }\
-\
- inline void reserve(size_type n) {}\
-\
- inline void push_back(const value_type& x)\
- {\
- if ( mpEnd != mpEndOfBuf ) \
- {\
- new (mpEnd) value_type(x);\
- ++mpEnd;\
- }\
- else\
- DoInsert( mpEnd, x );\
- }\
-\
- inline iterator insert(iterator position, const value_type& x = value_type())\
- {\
- if ( position == mpEnd && mpEnd != mpEndOfBuf )\
- {\
- new (mpEnd) value_type(x);\
- ++mpEnd;\
- return (mpEnd-1);\
- }\
- else return DoInsert( position, x );\
- }\
-\
- inline void pop_back()\
- {\
- DestructRange( mpEnd-1, mpEnd );\
-\
- --mpEnd;\
- }\
-\
- inline void erase(iterator first, iterator last)\
- {\
- if ( last == mpEnd )\
- {\
- DestructRange( first, last );\
- mpEnd = first;\
- return;\
- }\
- \
- CopyObjects( last, last + difference_type( mpEnd - last ), first );\
- \
- iterator newEnd = mpEnd - difference_type( last - first );\
- DestructRange( newEnd, mpEnd );\
- \
- mpEnd = newEnd;\
- }\
-\
- inline void erase( iterator position )\
- {\
- erase( position, position + 1 );\
- }\
-\
- inline void sort()\
- {\
- if ( size() < 2 ) return;\
- quick_sort( 0, size()-1 );\
- }\
-}
-
-
-
-// redefine below symbol to change the default allocation unit of vector content buffer
-#define WXSTL_VECTOR_MIN_BUF_SIZE 64
-
-// defines vector class, where objects are copied
-// using "deep-copy" sematics (i.e. by calling their copy constructors)
-
-#define WXSTL_VECTOR(ELEMENT_CLASS) \
-__DEFINE_STL_VECTOR_DEEP(_WXSTL_VECTOR_##ELEMENT_CLASS, ELEMENT_CLASS)
-
-// defines vector class, where objects are copied
-// using "shallow-copy" sematics (i.e. instead of calling
-// their constructors, memcpy() and memmove() are used to copy their raw data)
-
-
-#define WXSTL_VECTOR_SHALLOW_COPY(ELEMENT_CLASS) __DEFINE_STL_VECTOR_SHALLOW(_WXSTL_VECTORSC_##ELEMENT_CLASS, ELEMENT_CLASS)
-
-#endif
// just a copy of argv
static char **g_argv = NULL;
+class HelpGenApp: public wxApp
+{
+public:
+ HelpGenApp() {};
+
+ bool OnInit();
+};
+
+IMPLEMENT_APP(HelpGenApp);
+
// -----------------------------------------------------------------------------
// private functions
// -----------------------------------------------------------------------------
exit(1);
}
+/*
int main(int argc, char **argv)
+{
+*/
+
+bool HelpGenApp::OnInit()
{
enum
{
wxLogError("Can't complete diff.");
// failure
- return 1;
+ return false;
}
DocManager docman(paramNames);
docman.DumpDifferences(ctxTop);
}
- return 0;
+ return false;
}
// -----------------------------------------------------------------------------
/*
$Log$
+ Revision 1.8 1999/09/13 14:29:39 JS
+ Made HelpGen into a wxWin app (still uses command-line args); moved includes
+ into src for simplicity; added VC++ 5 project file
+
Revision 1.7 1999/02/21 22:32:32 VZ
1. more C++ parser fixes - now it almost parses wx/string.h
a) #if/#ifdef/#else (very) limited support
-/* mondrian ICON "mondrian.ico" */
#include "wx/msw/wx.rc"
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: No names yet.
+// Purpose: Implementation of C++/Java parser
+// compatible with SourceParserBase interface
+// Author: Aleksandras Gluchovas
+// Modified by:
+// Created: 22/09/98
+// RCS-ID: $Id$
+// Copyright: (c) Aleskandars Gluchovas
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __CJPARSESR_G__
+#define __CJPARSESR_G__
+
+#include "srcparser.h"
+
+#include <iostream.h>
+#include <memory.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+// class parses given "memory-resident" Java or C++ source code
+// and captures information about classes/attrubutes/methods/
+// arguments/etc into structures. Conforms with SourceParserBase
+// interface requirements.
+
+class CJSourceParser : public SourceParserBase
+{
+protected:
+ // begining of the full-text area of the source file
+ char* mpStart;
+
+ // points to first character after the end
+ // of teh full-text area
+ char* mpEnd;
+
+ // current "privacy level"
+ int mCurVis;
+
+ // current parsing position int full-text area
+ char* cur;
+
+ // about the current class
+ bool mIsVirtual;
+ bool mIsTemplate;
+ size_t mNestingLevel;
+
+ // context data for which is currently being collected
+ spContext* mpCurCtx;
+
+ int mCurCtxType; // type of the current context
+
+ bool mCommentsOn;
+ bool mMacrosOn;
+
+protected:
+
+ void AttachComments( spContext& ctx, char* cur );
+ void ParseKeyword( char*& cur );
+ bool ParseNameAndRetVal( char*& cur, bool& isAMacro );
+ bool ParseArguments( char*& cur );
+ void ParseMemberVar( char*& cur );
+ void SkipFunction( char*& cur );
+ void SkipFunctionBody( char*& cur );
+ bool CheckVisibilty( char*& cur );
+
+ void AddClassNode( char*& cur );
+ void AddMacroNode( char*& cur );
+ void AddEnumNode( char*& cur );
+ void AddTypeDefNode( char*& cur );
+
+ void DumpOperationInfo( spOperation& info, const string& tab, ostream& os );
+ void DumpClassHeader( spClass& info, ostream& os );
+ void DumpClassBody( spClass& info, ostream& os );
+
+public:
+
+ // NOTE:: discarding of macros or comments improves performance and
+ // decreases memory usage
+
+ CJSourceParser(bool collectCommnets = 1,
+ bool collectMacros = 1);
+
+ // returns the root-node of the created context tree
+ // (user is responsible for releasing it from the heep)
+ // "end" should point to the last (character + 1) of the
+ // source text
+
+ virtual spFile* Parse( char* start, char* end );
+};
+
+// inline'ed helpers used (just info):
+/*
+static inline void skip_to_eol( char*& cur );
+static inline void skip_eol( char*& cur );
+static inline bool skip_to_next_comment_in_the_line( char*& cur );
+static void skip_to_prev_line( char*& cur );
+static inline void skip_comments( char*& cur );
+static inline void clear_commets_queue();
+static inline void skip_quoted_string( char*& cur );
+static inline bool get_next_token( char*& cur );
+static inline void skip_preprocessor_dir( char*& cur );
+static void skip_token( char*& cur );
+static inline size_t get_token_len( char* tok );
+static inline bool cmp_tokens( char* tok1, char* tok2 );
+static inline bool cmp_tokens_fast( char* tok1, char* tok2, size_t len );
+static inline void skip_tempalate_statement( char*& cur );
+static inline void skip_statement( char*& cur );
+static inline void skip_token_back( char*& cur );
+static inline void skip_next_token_back( char*& cur );
+static string get_token_str( char* cur );
+static size_t skip_block( char*& cur );
+static inline bool skip_imp_block( char*& cur );
+static bool is_class_token( char*& cur );
+inline static bool is_forward_decl( char* cur );
+inline static bool is_function( char* cur, bool& isAMacro );
+static inline void skip_scope_block( char*& cur );
+static void arrange_indirection_tokens_between( string& type, string& identifier );
+static bool is_keyword( char* cur );
+static inline void get_string_between( char* start, char* end, string* pStr );
+static char* set_comment_text( string& text, char* start );
+*/
+
+#endif
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: No names yet.
+// Purpose: Contrib. demo
+// Author: Aleksandras Gluchovas
+// Modified by:
+// Created: 22/09/98
+// RCS-ID: $Id$
+// Copyright: (c) Aleskandars Gluchovas
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __DOCRIPPER_G__
+#define __DOCRIPPER_G__
+
+#include "scriptbinder.h"
+#include "srcparser.h"
+#include "sourcepainter.h"
+
+#if defined( wxUSE_TEMPLATE_STL )
+
+ #include <vector>
+
+ typedef vector<ScriptTemplate*> STemplateListT;
+
+#else
+
+ #include "wxstlvec.h"
+
+ typedef ScriptTemplate* ScriptTemplatePtrT;
+ typedef WXSTL_VECTOR_SHALLOW_COPY(ScriptTemplatePtrT) STemplateListT;
+
+#endif
+
+
+// specific DocGenerator class for "Ripper",
+// also acts as source code visitor
+
+class RipperDocGen : public DocGeneratorBase, public spVisitor
+{
+protected:
+ // templates for various sections
+ ScriptTemplate mTopTempl;
+ ScriptTemplate mContentIdxTempl;
+ ScriptTemplate mSuperContentTempl;
+ ScriptTemplate mSubContentTempl;
+ ScriptTemplate mOutLineTempl;
+ ScriptTemplate mOutLine1Templ;
+
+ // template used for corss-references
+ ScriptTemplate mRefTempl;
+
+ // template used to show not-existing sections
+ ScriptTemplate mDeadRefTempl;
+
+ // template collection for generation of class-tree
+ STemplateListT mTreeTemplates;
+
+ // pointers to all major index sections
+ ScriptSection* mpTopIdx;
+ ScriptSection* mpClassIdx;
+ ScriptSection* mpEnumIdx;
+ ScriptSection* mpTypeDefIdx;
+ ScriptSection* mpMacroIdx;
+ ScriptSection* mpGlobalVarsIdx;
+ ScriptSection* mpGlobalFuncIdx;
+ ScriptSection* mpConstIdx;
+
+ // parser set up from user-code for sepcific language
+ SourceParserBase* mpParser;
+
+ // class section, which is currently being
+ // assembled
+ ScriptSection* mpCurClassSect;
+
+ // source syntax heighlighter object
+ SourcePainter mSrcPainter;
+
+ // context, to which all file contexts
+ // are assembled
+ spContext* mpFileBinderCtx;
+
+ // script tags set up from usesr code
+ MarkupTagsT mTags;
+
+protected:
+ // helpers
+ void AppendComments( spContext& fromContext, string& str );
+
+ void AppendMulitilineStr( string& st, string& mlStr );
+
+ void AppendHighlightedSource( string& st, string source );
+
+ // returns TRUE, if no comments found in the context,
+ // plus, creates dummy(empty) section, and puts a
+ // reference woth "dead-link" template to it in the
+ // given index-section "toSect"
+
+ bool CheckIfUncommented( spContext& ctx, ScriptSection& toSect );
+
+ // checks if context has any comments, then returns
+ // template of normal reference, otherwise of dead reference
+
+ ScriptTemplate* GetRefTemplFor( spContext& ctx );
+
+ // adds "someClass::" perfix to the context name,
+ // if it's not in the file scope (i.e. if it's not global)
+
+ string GetScopedName( spContext& ofCtx );
+
+ // adds section to currently assembled class section
+ // and places references to it from "public", "protected"
+ // or "private" indexing-subsections of the class, depending
+ // on the visibility of the context
+
+ void AddToCurrentClass( ScriptSection* pSection, spContext& ctx,
+ const char* subSectionName );
+
+ // called, after all files are processed, to
+ // resolve possible super/derived class relations,
+ // and put cross references to them - where resolution was
+ // successful
+ void LinkSuperClassRefs();
+
+ // implementations of "visiting procedures", declared in spVisitor
+
+ virtual void VisitClass( spClass& cl );
+ virtual void VisitEnumeration( spEnumeration& en );
+ virtual void VisitTypeDef( spTypeDef& td );
+ virtual void VisitPreprocessorLine( spPreprocessorLine& pd );
+ virtual void VisitAttribute( spAttribute& attr );
+ virtual void VisitOperation( spOperation& op );
+
+ // overriden member of DocGernatorBase
+
+ virtual bool OnSaveDocument( ScriptStream& stm );
+
+ virtual ScriptSection* GetTopSection()
+ { return mpTopIdx; }
+
+public:
+ RipperDocGen();
+ ~RipperDocGen();
+
+ // should be called onece to set user-code provided,
+ // parser for specific source code language
+ // (NOTE:: it's the user-code's responsibility to
+ // relseas memory of pParser)
+
+ void Init( SourceParserBase* pParser );
+
+ // should be called on each file
+
+ void ProcessFile( const char* sourceFile );
+};
+
+
+#endif
\ No newline at end of file
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: No names yet.
+// Purpose: Contrib. demo
+// Author: Aleksandras Gluchovas
+// Modified by:
+// Created: 27/12/98
+// RCS-ID: $Id$
+// Copyright: (c) Aleskandars Gluchovas
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __IFCONTEXT_G__
+#define __IFCONTEXT_G__
+
+#include "srcparser.h"
+#include "cjparser.h"
+
+class spBookmark
+{
+public:
+ size_t mFrom;
+ size_t mLen;
+ size_t mFileNo;
+
+ inline spBookmark() {}
+
+ inline spBookmark( int from, int len, int fileNo )
+ : mFrom( from ), mLen( len ), mFileNo( fileNo )
+ {}
+};
+
+#if defined( wxUSE_TEMPLATE_STL )
+
+ typedef vector<spBookmark) BookmarkListT
+
+#else
+
+ typedef WXSTL_VECTOR_SHALLOW_COPY(spBookmark) BookmarkListT;
+
+#endif
+
+
+class spInterFileContext : public spContext
+{
+protected:
+
+ BookmarkListT mDeletionMarks;
+
+ BookmarkListT mFiltered;
+
+ size_t mCurFileNo;
+
+ CJSourceParser mParser;
+
+protected:
+
+ size_t GetFileNoOfContext( spContext& ctx );
+ size_t GetFileNo( const string& fname );
+
+ void InsertBookmarkSorted( BookmarkListT& lst, spBookmark& mark );
+
+ void DoAppendSourceFragment( string& source,
+ string& result,
+ size_t pos, size_t len );
+
+ void GenerateContextBody( spContext& ctx,
+ string& source,
+ string& result,
+ size_t& lastSavedPos,
+ size_t& lastKnownPos );
+
+public:
+
+ StrListT mFiles;
+ StrListT mContents;
+
+public:
+
+ spInterFileContext();
+ ~spInterFileContext();
+
+ void AddFile( const string& fname, const string& content );
+
+ void RemoveContext( spContext& ctx );
+
+ void GenrateContents();
+
+ void ParseContents( SourceParserPlugin* pPlugin = NULL );
+
+ void WriteToFiles();
+
+ // overriden method of the base class (finds out the source fragment)
+
+ virtual string GetBody( spContext* pCtx = NULL );
+
+ virtual string GetHeader( spContext* pCtx = NULL );
+};
+
+
+#endif
\ No newline at end of file
+++ /dev/null
-#
-# File: makefile.nt
-# Author: Julian Smart
-# Created: 1993
-# Updated:
-# Copyright: (c) 1993, AIAI, University of Edinburgh
-#
-# "%W% %G%"
-#
-# Makefile : Builds minimal example (MS VC++).
-# Use FINAL=1 argument to nmake to build final version with no debugging
-# info
-
-# Set WXDIR for your system
-WXDIR = $(WXWIN)
-
-WXUSINGDLL=0
-
-!include $(WXDIR)\src\ntwxwin.mak
-
-THISDIR = $(WXDIR)\utils\HelpGen\src
-PROGRAM=HelpGen
-EXTRAINC=-I..\include
-
-OBJECTS = $(PROGRAM).obj cjparser.obj ifcontext.obj markup.obj\
- scriptbinder.obj srcparser.obj sourcepainter.obj
-
-$(PROGRAM): $(PROGRAM).exe
-
-all: wx $(PROGRAM).exe
-
-wx:
- cd $(WXDIR)\src\msw
- nmake -f makefile.nt FINAL=$(FINAL)
- cd $(THISDIR)
-
-wxclean:
- cd $(WXDIR)\src\msw
- nmake -f makefile.nt clean
- cd $(THISDIR)
-
-$(PROGRAM).exe: $(DUMMYOBJ) $(WXLIB) $(OBJECTS) $(PROGRAM).res
- $(link) @<<
--out:$(PROGRAM).exe
-$(LINKFLAGS)
-$(DUMMYOBJ) $(OBJECTS) $(PROGRAM).res
-$(LIBS)
-<<
-
-
-$(PROGRAM).obj: $(PROGRAM).$(SRCSUFF) $(DUMMYOBJ)
- $(cc) @<<
-$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
-<<
-
-$(PROGRAM).res : $(PROGRAM).rc $(WXDIR)\include\wx\msw\wx.rc
- $(rc) -r /i$(WXDIR)\include -fo$@ $(PROGRAM).rc
-
-
-clean:
- -erase *.obj
- -erase *.exe
- -erase *.res
- -erase *.map
- -erase *.sbr
- -erase *.pdb
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: No names yet.
+// Purpose: Contrib. demo
+// Author: Aleksandras Gluchovas
+// Modified by:
+// Created: 22/09/98
+// RCS-ID: $Id$
+// Copyright: (c) Aleskandars Gluchovas
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __MARKUP_G__
+#define __MARKUP_G__
+
+// indicies for the MarkupTagsT array
+
+#define TAG_BOLD 0
+#define TAG_ITALIC 1
+
+#define TAG_FIXED_FONT 2
+#define TAG_BLACK_FONT 3
+#define TAG_RED_FONT 4
+#define TAG_GREEN_FONT 5
+#define TAG_BLUE_FONT 6
+
+#define TAG_PARAGRAPH 7
+#define TAG_NEW_LINE 8
+#define TAG_HEADING_1 9
+#define TAG_HEADING_2 10
+#define TAG_HEADING_3 11
+
+#define TAG_ITEM_LIST 12
+#define TAG_LIST_ITEM 13
+
+struct TagStructT
+{
+ char* start; // tag that starts style
+ char* end; // tag that finishes style
+};
+
+// tag array
+typedef TagStructT* MarkupTagsT;
+
+// returns array of TagStructT with tag strings for HTML
+
+MarkupTagsT get_HTML_markup_tags();
+
+// MarkupTagsT get_PostScript_markup_tags();
+// MarkupTagsT get_Latex_markup_tags();
+
+#endif
\ No newline at end of file
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: No names yet.
+// Purpose: Contrib. demo
+// Author: Aleksandras Gluchovas
+// Modified by:
+// Created: 22/09/98
+// RCS-ID: $Id$
+// Copyright: (c) Aleskandars Gluchovas
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __SCRIPTBINDER_G__
+#define __SCRIPTBINDER_G__
+
+#if defined( wxUSE_TEMPLATE_STL )
+
+ #include <vector>
+
+ #ifdef WIN32
+ #include <bstring.h>
+ #else
+ #include <strclass.h>
+ #include <string.h>
+ #endif
+
+#else
+
+ #include "wxstlvec.h"
+ #include "wx/string.h"
+
+ // FIXME:: dirty!
+ typedef wxString string;
+
+#endif
+
+#ifndef ASSERT
+// assert yourself
+#define ASSERT(x) if (!(x) ) throw;
+#endif
+
+#include "markup.h"
+
+// just another portable stream class...
+
+class ScriptStream
+{
+protected:
+ char* mpBuf;
+ size_t mSize;
+ size_t mCapacity;
+public:
+ ScriptStream();
+ ~ScriptStream();
+
+ void WriteBytes( const void* srcBuf, size_t count );
+
+ ScriptStream& operator<<( const char* str );
+ ScriptStream& operator<<( const string& str );
+ ScriptStream& operator<<( char ch );
+
+ void endl();
+
+ inline char* GetBuf() { return mpBuf; }
+ inline size_t GetBufSize() { return mSize; }
+
+ // clears current contents of the stream
+ void Reset() { mSize = 0; }
+};
+
+
+class ScriptTemplate;
+
+// used internally by ScriptTemplate
+
+enum TEMPLATE_VARIABLE_TYPES
+{
+ TVAR_INTEGER,
+ TVAR_STRING,
+ TVAR_DOUBLE,
+ TVAR_REF_ARRAY
+};
+
+// helper structures used only by ScriptTemplate
+
+struct TVarInfo
+{
+public:
+ const char* mName;
+ int mType;
+ int mOfs;
+
+ TVarInfo( const char* name, int ofs, int varType )
+ : mName(name),
+ mType( varType ),
+ mOfs( ofs )
+ {}
+};
+
+struct TArrayInfo : public TVarInfo
+{
+public:
+ int mRefOfs;
+ int mSizeIntOfs;
+ int mObjRefTemplOfs;
+
+ TArrayInfo( const char* name )
+ : TVarInfo( name, 0, TVAR_REF_ARRAY )
+ {}
+};
+
+// stores offset of the given member (of the given class)
+// to (*pOfs), though the use of template classes would have
+// solved this problem in much clearer fashion
+
+// FOR NOW:: obtaining physical offset of class member
+// does not appeare to be protable across compilers?
+// FIXME:: +/- 1 problem
+
+#ifdef __UNIX__
+ #define WEIRD_OFFSET 1
+#else
+ #define WEIRD_OFFSET 0
+
+#endif
+
+#define GET_VAR_OFS( className, varName, pOfs ) \
+ { \
+ int* className::* varPtr; \
+ varPtr = (int* className::*)&className::varName; \
+ \
+ (*pOfs) = int(*(int*)&varPtr)-WEIRD_OFFSET; \
+ }
+
+class ScriptSection;
+
+#if defined( wxUSE_TEMPLATE_STL )
+
+ typedef vector<TVarInfo*> TVarListT;
+
+ // container class for sections
+ typedef vector<ScriptSection*> SectListT;
+
+#else
+
+ typedef TVarInfo* TVarInfoPtrT;
+ typedef ScriptSection* ScriptSectionPtrT;
+
+ typedef WXSTL_VECTOR_SHALLOW_COPY(TVarInfoPtrT) TVarListT;
+
+ // container class for sections
+ typedef WXSTL_VECTOR_SHALLOW_COPY(ScriptSectionPtrT) SectListT;
+
+#endif
+
+// class performs preprocessing of arbitrary scripts,
+// replaces identifiers enclosed in $(..) tag, whith
+// values of the corresponding class member variables
+
+class ScriptTemplate
+{
+protected:
+ // do not use string object here - parsing of
+ // C string can be much faster (in debug v.)
+ char* mTText;
+
+
+ TVarListT mVars;
+
+ inline void PrintVar( TVarInfo* pInfo,
+ void* dataObj,
+ ScriptStream& stm );
+
+public:
+ ScriptTemplate( const string& templateText );
+ virtual ~ScriptTemplate();
+
+ bool HasVar( const char* name );
+
+ // Member variables registration methods.
+
+ // NOTE:: GET_VAR_OFS() macro should be used
+ // to get offset of the class member (see #define above)
+ void AddStringVar ( const char* name, int ofs );
+ void AddIntegerVar( const char* name, int ofs );
+ void AddDoubleVar ( const char* name, int ofs );
+
+ void AddObjectRefArray( const char* name,
+ int ofsRefToFirstObj,
+ int ofsObjSizeInt,
+ int ofsObjRefTempl
+ );
+
+ // reads the script, replaces $(..) tags with values
+ // of registered members of dataObj object, and outputs
+ // the result to given text stream
+
+ void PrintScript( void* dataObj, ScriptStream& stm );
+};
+
+class ScriptSection;
+
+// class manages section and aggregated sections of
+// inter-linked documents
+
+class ScriptSection
+{
+protected:
+
+ // NOTE:: "$(NAME)", $(ID), "$(BODY)" and "$(REFLIST)" aree
+ // reseved template variables of ScriptSection
+
+ // the below there members are registered to ScriptTemplate,
+ // GUID within the section tree (numeric)
+
+ ScriptSection* mpParent;
+ string mId; // $(ID)
+ string mName; // $(NAME)
+ string mBody; // $(BODY)
+
+ // NULL, if this section is not aggregated anywhere
+
+ SectListT mSubsections; // aggregated sectons
+ SectListT mReferences; // registered as $(REFLIST)
+
+ bool mAutoHide; // see autoHide arg, in constructor
+ bool mSortOn; // TRUE, if sort subsectons by naem
+
+ // tempalte for this section
+ ScriptTemplate* mpSectTempl;
+
+ // template used for links (or references) to this section
+ ScriptTemplate* mpRefTempl;
+
+ // do not call destructor of this object,
+ // call RemoveRef() instead
+ int mRefCount;
+
+ static int mIdCounter; // generator of GUIDs
+
+ // fields registered and used by ScriptTemplate object
+ void* mRefFirst;
+ int mArrSize;
+
+protected:
+ virtual void AddRef();
+ virtual void RemoveRef();
+ void DoRemoveEmptySections(int& nRemoved, SectListT& removedLst);
+ void DoRemoveDeadLinks( SectListT& removedLst);
+
+public:
+
+ // NOTE:: pass NULL to certain template, if your sure
+ // this kind of template will never be used,
+ // e.g. if section is contained but never referrenced,
+ // then pReferenceTemplate can be NULL
+
+ // if autoHide option is TRUE, the section will be automatically
+ // collapsed (not shown) if it doesn't contain any references
+ // to other sections (e.g. could be usefull for autoamically
+ // hiding empty index-sections).
+
+ ScriptSection( const string& name = "",
+ const string& body = "",
+ ScriptTemplate* pSectionTemplate = NULL,
+ ScriptTemplate* pReferenceTemplate = NULL,
+ bool autoHide = FALSE,
+ bool sorted = FALSE
+ );
+
+ // calls RemoveRef() to all aggreagated sections first,
+ // then to all referenced section - this way all
+ // sections (even not aggregated ones) become "garbage-collected"
+
+ // NOTE:: do not call destructor directlly, call RemoveRef()
+ // instead
+ virtual ~ScriptSection();
+
+
+ // if addToReferencesToo is TRUE, section is aggregated and
+ // also added to reference list of this section
+
+ void AddSection( ScriptSection* pSection, bool addToReferencesToo = FALSE );
+
+ // add cross-reference to this given section
+ void AddReference( ScriptSection* pReferredSection );
+
+ // subsection may be given of variable depth level,
+ // e.g. "publications/reviews/software"
+
+ ScriptSection* GetSubsection( const char* name );
+
+ // returns list aggregated sections
+ SectListT& GetSubsections();
+
+ // binds reserved template names ( $(..) ) to member
+ // vairalbes in the ScriptSection class, should be called
+ // to initialize each user-code provided script template
+
+ static void RegisterTemplate( ScriptTemplate& sectionTempalte );
+
+ // prints out section tree to the stream, starting from
+ // this section as a root node
+ virtual void Print( ScriptStream& stm );
+
+ // searches empty sections which has autoHide == TRUE,
+ // and colapses them (this method should be called )
+ // on the root-section of the sections tree
+
+ // NOTE:: does not work properly, yet!
+ void RemoveEmptySections();
+};
+
+// base class for documnetation generators
+// (allows user code set up target script type,
+// independently of documentation type)
+
+class DocGeneratorBase
+{
+protected:
+ MarkupTagsT mTags;
+
+ // override this method to do some post processing
+ // after generation of document, or even write some
+ // data into output stream, before the section tree
+ // is flushed into it.
+
+ // return FALSE, if something has gone wrong and
+ // document cannot be saved now
+
+ virtual bool OnSaveDocument( ScriptStream& stm )
+ { return 1; }
+
+ // override this method to provide reference to
+ // the top section of the document (used as default
+ // starting section when saving a document)
+
+ virtual ScriptSection* GetTopSection()
+ { return 0; }
+
+public:
+
+ DocGeneratorBase()
+ : mTags(0) // no defaul script
+ {}
+
+ // dectrouctors of polymorphic classes SHOULD be virtual
+ virtual ~DocGeneratorBase() {}
+
+ // returns tags, being used for specific target script
+ MarkupTagsT GetScriptMarkupTags() { return mTags; }
+
+ // sets tag array for specific script
+
+ // NOTE:: Why virtual? since approach with MarkupTagsT is
+ // "flowless" only in theory. Overriding this method
+ // allows document generators to check the type of the
+ // target script, and perhaps make some modifications
+ // to generator's tamplates, to match the specific script
+
+ virtual void SetScriptMarkupTags( MarkupTagsT tags )
+ { mTags = tags; }
+
+ // seves document to file starting from the root-node of
+ // the document (provided by GetTopSection() method),
+ // or from "pFromSection" if it's not NULL.
+
+ // fopenOptions arg. is string passed to fopen() method,
+ // returns TRUE, if saving was successfull
+
+ virtual bool SaveDocument( const char* fname,
+ const char* fopenOptions = "w",
+ ScriptSection* pFromSection = NULL
+ );
+
+};
+
+#endif
#include <map>
#else
- #include <wxstlac.h>
+ #include "wxstlac.h"
#endif
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: No names yet.
+// Purpose: Contrib. demo
+// Author: Aleksandras Gluchovas
+// Modified by:
+// Created: 22/09/98
+// RCS-ID: $Id$
+// Copyright: (c) Aleskandars Gluchovas
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __SOURCEPAINTER_G__
+#define __SOURCEPAINTER_G__
+
+#ifndef ASSERT
+#define ASSERT(x) if (!(x)) throw
+#endif
+
+#if defined( wxUSE_TEMPLATE_STL )
+
+ #include <vector.h>
+ typedef vector<int> SPBlockListT;
+
+ #ifdef WIN32
+ #include <bstring.h>
+ #else
+ #include <strclass.h>
+ #include <string.h>
+ #endif
+#else
+
+ #include "wxstlvec.h"
+ #include "wx/string.h"
+
+ // FIXME:: dirty!
+ #define string wxString
+
+ typedef WXSTL_VECTOR_SHALLOW_COPY(int) SPBlockListT;
+
+#endif
+
+#include "markup.h" // import MarkupTagsT definition
+
+// "colored" codes for highlighted blocks
+
+#define RANK_BLACK 0 // common source fragments
+#define RANK_BLUE 1 // basic types
+#define RANK_RED 2 // reserved words
+#define RANK_GREEN 3 // comments
+
+// colored block description format :
+// int( ( rank << 16 ) | ( source_range_len ) )
+
+
+// FOR NOW:: no lagnguage-map selection
+
+// source code syntax heighlighter (CPP+JAVA+VB+PASCAL)
+
+class SourcePainter
+{
+protected:
+ string mResultStr;
+ SPBlockListT mBlocks;
+ bool mCollectResultsOn;
+
+ // state variables
+ bool mIsInComment;
+ bool mCommentIsMultiline;
+public:
+
+ // assembleResultString == TRUE - instructs painter
+ // to collect each chunk of srouce passed to ProcessSource(),
+ // so that results cann be futher obtained in a single string
+ // instead of vector of block descriptions
+
+ SourcePainter( bool assembleResultString = TRUE );
+ virtual ~SourcePainter() {}
+
+ // can be called multiple times (e.g. on each source line)
+ void ProcessSource( char* src, int srcLen );
+
+ // method, for manually adjusting state of source painter
+ void SetState( bool isInComment,
+ bool commentIsMultiline );
+
+ // reinitializes object - clears results of previouse processing
+ void Init( bool assembleResultString = TRUE );
+
+ // generates string of highlighted source for the scipting
+ // language given by "tags" argument
+
+ virtual void GetResultString(string& result, MarkupTagsT tags);
+
+ // returns vector of block descriptors, see SPBlockListT definition
+ // (block descriptors can be used for fast custom hightlighted text generation)
+
+ SPBlockListT& GetBlocks();
+
+ // NOTE:: static method
+ // returns if the given word is a reserved word or basic type identifier
+ static bool IsKeyword( char* word, int wordLen );
+};
+
+#endif
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: No names yet.
+// Purpose: To provide a simple _framework_
+// for series of source code parsers with
+// compatible interfaces
+// Author: Aleksandras Gluchovas
+// Modified by: AG on 28/12/98
+// Created: 22/09/98
+// RCS-ID: $Id$
+// Copyright: (c) Aleskandars Gluchovas
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __SRCPARSER_G__
+#define __SRCPARSER_G__
+
+#if defined( wxUSE_TEMPLATE_STL )
+ #include <vector>
+
+ #ifdef WIN32
+ #include <bstring.h>
+ #else
+
+ #include <strclass.h>
+ #include <string.h>
+
+ #endif
+
+#else
+ #include "wx/string.h"
+ #include "wxstlvec.h"
+
+ // FOR NOW:: quick n' dirty:
+
+ #define string wxString
+
+#endif
+
+#include "markup.h" // markup tags used in spOperator::GetFullName()
+
+// these methods are used for debugging only and disappear in the release build
+#ifdef __WXDEBUG__
+ #define DECLARE_DUMP virtual void DumpThis(const wxString& indent) const;
+#else
+ #define DECLARE_DUMP
+#endif
+
+// context class list in "inside-out" order :
+
+class spContext;
+
+class spParameter;
+class spAttribute;
+class spOperation;
+class spEnumeration;
+class spTypeDef;
+class spPreprocessorLine;
+class spClass;
+class spNameSpace;
+class spFile;
+
+// source context visibilities
+enum SRC_VISIBLITY_TYPES
+{
+ SP_VIS_PUBLIC,
+ SP_VIS_PROTECTED,
+ SP_VIS_PRIVATE
+};
+
+// class types
+enum SP_CLASS_TYPES
+{
+ SP_CLTYPE_INVALID,
+ SP_CLTYPE_CLASS,
+ SP_CLTYPE_TEMPLATE_CLASS,
+ SP_CLTYPE_STRUCTURE,
+ SP_CLTYPE_UNION,
+ SP_CLTYPE_INTERFACE
+};
+
+// inheritance types
+enum SP_INHERITANCE_TYPES
+{
+ SP_INHERIT_VIRTUAL,
+ SP_INHERIT_PUBLIC,
+ SP_INHERIT_PRIVATE
+};
+
+// proprocessor definitions types (specific to C++ code)
+
+enum SP_PREP_DEFINITION_TYPES
+{
+ SP_PREP_DEF_DEFINE_SYMBOL,
+ SP_PREP_DEF_REDEFINE_SYMBOL,
+ SP_PREP_DEF_INCLUDE_FILE,
+ SP_PREP_DEF_OTHER
+};
+
+// common context types
+
+#define SP_CTX_UNKNOWN 0x000
+#define SP_CTX_FILE 0x001
+#define SP_CTX_NAMESPACE 0x002
+#define SP_CTX_CLASS 0x004
+#define SP_CTX_TYPEDEF 0x008
+#define SP_CTX_PREPROCESSOR 0x010
+#define SP_CTX_ENUMERATION 0x020
+#define SP_CTX_ATTRIBUTE 0x040
+#define SP_CTX_OPERATION 0x080
+#define SP_CTX_PARAMETER 0x100
+
+// other (custom) context codes may be defined elsewere, however they should
+// not clash with above codes for common type and also should not
+// exceed 16-bits of in value
+
+// masks all context types (up to 16 custom context can be defined)
+
+#define SP_CTX_ANY 0xFFFF
+
+class spComment;
+
+
+
+#if defined( wxUSE_TEMPLATE_STL )
+
+ // context members
+ typedef vector<spContext*> MMemberListT;
+ // comments list
+ typedef vector<spComment*> MCommentListT;
+ // list of parameters
+ typedef vector<spParameter*> MParamListT;
+ // string list
+ typedef vector<string> StrListT;
+
+#else
+
+ typedef spContext* spContextPtrT;
+ typedef spComment* spCommentPtrT;
+ typedef spParameter* spParameterPtrT;
+ typedef WXSTL_VECTOR_SHALLOW_COPY(spContextPtrT) MMemberListT;
+ typedef WXSTL_VECTOR_SHALLOW_COPY(spCommentPtrT) MCommentListT;
+ typedef WXSTL_VECTOR_SHALLOW_COPY(spParameterPtrT) MParamListT;
+ typedef WXSTL_VECTOR_SHALLOW_COPY(string) StrListT;
+
+#endif;
+// base class for all visitors of source code contents
+
+class spVisitor
+{
+protected:
+ bool mSiblingSkipped;
+ bool mChildSkipped;
+ int mContextMask;
+
+ spContext* mpCurCxt;
+
+public:
+ // methods invoked by context
+
+ // method invoked from user's controling code
+ // to visit all nodes staring at the given context.
+ // Content is sorted if requrired, see comments
+ // spClass on sorting the class members
+
+ void VisitAll( spContext& atContext,
+ bool sortContent = TRUE
+ );
+
+ // methods invoked by visitor
+
+ // goes to the next context in the outter scope
+ // NOTE:: should not be invoked more than once while
+ // visiting certain context
+
+ void SkipSiblings();
+
+ // prevents going down into the contexts contained by
+ // the current context
+ // NOTE:: the same as above
+
+ void SkipChildren();
+
+ // can be called only in from visiting procedure
+ void RemoveCurrentContext();
+
+ // method enables fast filtered traversal
+ // of source content, e.g. collecting only classes,
+ // or only global functions
+
+ // arg. context - can contain combination of contexts concatinated
+ // with bitwise OR, e.g. SP_CTX_CLASS | SP_CTX_NAMESPACE
+ //
+ // method can be invoked from the user's controling as well as
+ // from within the visting procedure
+
+ void SetFilter( int contextMask );
+
+ // methods should be implemneted by specific visitor:
+
+ // NOTE:: Do not confuse visiting with parsing, first
+ // the source is parsed, and than can be visited
+ // multiple times by variouse visitors (there can
+ // be more the one visitor visiting content at a time)
+
+ virtual void VisitFile( spFile& fl ) {}
+
+ virtual void VisitNameSpace( spNameSpace& ns ) {}
+
+ virtual void VisitClass( spClass& cl ) {}
+
+ virtual void VisitEnumeration( spEnumeration& en ) {}
+
+ virtual void VisitTypeDef( spTypeDef& td ) {}
+
+ virtual void VisitPreprocessorLine( spPreprocessorLine& pd ) {}
+
+ virtual void VisitAttribute( spAttribute& attr ) {}
+
+ virtual void VisitOperation( spOperation& op ) {}
+
+ virtual void VisitParameter( spParameter& param ) {}
+
+ virtual void VisitCustomContext( spContext& ctx ) {}
+};
+
+// stores one section of comments,
+// multiple sections can be put to geather
+// and attached to some context
+
+class spComment
+{
+public:
+ string mText;
+ bool mIsMultiline; // multiline comments ar those with /**/'s
+
+ // TRUE, if these was an empty empty
+ // line above single line comment
+
+ bool mStartsPar;
+
+public:
+
+ bool IsMultiline() const;
+ bool StartsParagraph() const;
+
+ string& GetText();
+
+ // contstant version of GetText()
+ string GetText() const;
+};
+
+// abstract base class for common (to most languages) code
+// contexts (constructs), e.g file, namespace, class, operation,
+// etc
+
+class spContext
+{
+protected:
+ // "linked" list of comments belonging to this context
+ MCommentListT mComments;
+
+ // NULL, if this is file context
+ MMemberListT mMembers;
+
+ // NULL, if this is top-most context
+ spContext* mpParent;
+
+ // points to context object, where the this context
+ // was originally declared, meaning that this object
+ // is redeclaration (or if in the case of operation
+ // this context object most probably referres to the
+ // implemnetation in .cpp file for example)
+
+ // is NULL, if this object referres to the first occurence
+ // of the context
+
+ spContext* mpFirstOccurence;
+
+ // used, to avoid excessive sorting of context's agreggates
+ bool mAlreadySorted;
+
+public:
+
+ // source line number, (-1) if unknown
+ int mSrcLineNo;
+
+ // offset of context in the source file, (-1) if unknown
+ int mSrcOffset;
+
+ // lentgh of the context in characters, (-1) if unknown
+ int mContextLength;
+
+ // source line number, in which this cotext ends, (-1) if unknown
+ int mLastScrLineNo;
+
+ // fields are valid, if the may contain other contexts nested inside
+ int mHeaderLength;
+ int mFooterLength;
+
+ // zero-based index of the first character of
+ // this context in the source line, (-1) if unknown
+ int mFirstCharPos;
+
+ // zero-based index of the first character of
+ // this context in the last source line of this context, (-1) if unknown
+ int mLastCharPos;
+
+ // see SRC_VISIBLITY_TYPES enumeration
+ int mVisibility;
+
+ // TRUE, if context does not really exist in the source
+ // but was created by external tools (e.g. forward engineering)
+
+ bool mIsVirtualContext;
+ bool mVirtualContextHasChildren;
+
+ // body of the context in case (mIsVirtual == TRUE)
+ string mVirtualContextBody;
+ string mVittualContextFooter;
+
+ // e.g. can be used by documentation generator to store
+ // reference to section object
+ void* mpUserData;
+
+public:
+ // universal identifier of the context (e.g. class name)
+ string mName;
+
+public:
+ // default constructor
+ spContext();
+
+ // automatically destorys all aggregated contexts
+ // (thus, it's enought to call destructor of root-context)
+ virtual ~spContext();
+
+ // see mUererData member;
+ void* GetUserData() { return mpUserData; }
+
+ // sets untyped pointer to user data
+ void SetUserData( void* pUserData )
+ { mpUserData = pUserData; }
+
+ // searches the whole context tree for the cotnexts
+ // which match given masks, pust results into lst array
+ void GetContextList( MMemberListT& lst, int contextMask );
+
+ // used by default visitor's implementation
+ bool IsSorted();
+
+ /*** forward/reverse ingineering fecilities ***/
+
+ bool PositionIsKnown();
+
+ bool IsVirtualContext();
+
+ bool VitualContextHasChildren();
+
+ void SetVirtualContextBody( const string& body,
+ bool hasChildren = FALSE,
+ const string& footer = "" );
+
+ string GetVirtualContextBody();
+ string GetFooterOfVirtualContextBody();
+
+ // can be overriden by top-level context classes
+ // to find-out ot the source-fragment of this
+ // context using it's position information
+ virtual string GetBody( spContext* pCtx = NULL );
+
+ virtual string GetHeader( spContext* pCtx = NULL );
+
+ // TRUE, if there is at least one entry
+ // in the comment list of this context
+ bool HasComments();
+ MCommentListT& GetCommentList() { return mComments; }
+ const MCommentListT& GetCommentList() const { return mComments; }
+
+ // should be overriden, if the context supports sorting
+ // of it's members
+ virtual void SortMembers() {}
+
+ // returns identifier of this context
+ inline string& GetName() { return mName; }
+
+ // returns -1, if souce line # is unknow
+ inline int GetSourceLineNo() { return mSrcLineNo; }
+
+ // see comments on mpFirstOccurence member variable
+ bool IsFirstOccurence();
+ spContext* GetFirstOccurence();
+
+ // returns not-NULL value if this context
+ // is aggregated by another cotnext
+ spContext* GetOutterContext();
+
+ // perhaps more intuitive alias for `GetOutterContext()'
+ inline spContext* GetParent() { return mpParent; }
+
+ bool HasOutterContext();
+
+ // add one aggregate (or child) into this context
+ void AddMember ( spContext* pMember );
+ MMemberListT& GetMembers();
+
+ // append comment to the comment list decribing
+ // this context
+ void AddComment( spComment* pComment );
+
+ // returns NULL, if the context with the given
+ // name and type is not contained by this context
+ // and it's children. Children's children are not
+ // searched recursivelly if searchSubMembers is FALSE
+
+ spContext* FindContext( const string& identifier,
+ int contextType = SP_CTX_ANY,
+ bool searchSubMembers = TRUE
+ );
+
+ // removes this context from it's parent
+ // (NOTE:: context should have an outter cotnext
+ // to when this method is called, otherwise removal
+ // will result assertion failure)
+ void RemoveThisContext();
+
+ // returns TRUE, if this object is aggregated in the file
+ bool IsInFile();
+
+ // TRUE, if outter context is a namespace
+ bool IsInNameSpace();
+
+ // TRUE, if outter context is a class
+ bool IsInClass();
+
+ // TRUE, if outter cotext is an operation (TRUE for "spParameter"s)
+ bool IsInOperation();
+
+ // TRUE if the context is public
+ bool IsPublic() const { return mVisibility == SP_VIS_PUBLIC; }
+
+ // NOTE:: method returns not the type of this object
+ // but the file/namespace/class/operation or file in which this
+ // attribute is contained. First, check for the type of
+ // context using the above method.
+
+ // Requiering container which does not exist, will result
+ // in assertion failure
+
+ spClass& GetClass();
+ spFile& GetFile();
+ spNameSpace& GetNameSpace();
+ spOperation& GetOperation();
+
+ // each new context should override this method
+ // to return it's specific type
+ virtual int GetContextType() const { return SP_CTX_UNKNOWN; }
+
+ // perhaps more intuitive short-cut
+ inline int GetType() { return GetContextType(); }
+
+ // cast this context to the desired type - returns NULL if type is wrong
+ spAttribute *CastToAttribute()
+ {
+ return GetContextType() == SP_CTX_ATTRIBUTE ? (spAttribute *)this
+ : NULL;
+ }
+
+ // derived classes override this to invoke VisitXXX method
+ // which corresponds to the class of specific context,
+ // - this is what the "Visitor" pattern told us ^)
+
+ // if method is not overriden, then it's probably user-defined
+ // custom context
+
+ virtual void AcceptVisitor( spVisitor& visitor )
+
+ { visitor.VisitCustomContext( *this ); };
+
+ // called by visitors, to remove given subcontext
+ // of this context object
+ void RemoveChild( spContext* pChild );
+
+ void RemoveChildren();
+
+ spContext* GetEnclosingContext( int mask = SP_CTX_ANY );
+
+#ifdef __WXDEBUG__
+ virtual void Dump(const wxString& indent) const;
+#endif // __WXDEBUG__
+
+ DECLARE_DUMP
+};
+
+// stores information about single argument of operation
+
+class spParameter : public spContext
+{
+public:
+ // type of argument (parameter)
+ string mType;
+
+ // "stringified" initial value
+ string mInitVal;
+
+public:
+ virtual int GetContextType() const { return SP_CTX_PARAMETER; }
+
+ virtual void AcceptVisitor( spVisitor& visitor )
+ { visitor.VisitParameter( *this ); }
+
+ DECLARE_DUMP
+};
+
+
+// stores information about member(or global) variable
+
+class spAttribute : public spContext
+{
+public:
+ // type of the attribute
+ string mType;
+
+ // it's initial value
+ string mInitVal;
+
+ // constantness
+ bool mIsConstant;
+public:
+
+ virtual int GetContextType() const { return SP_CTX_ATTRIBUTE; }
+
+ virtual void AcceptVisitor( spVisitor& visitor )
+ { visitor.VisitAttribute( *this ); }
+
+ DECLARE_DUMP
+};
+
+class spOperation : public spContext
+{
+public:
+ // type of return value
+ string mRetType;
+
+ // argument list
+ //MParamListT mParams;
+
+ // TRUE, if operation does not modify
+ // the content of the object
+ bool mIsConstant;
+
+ // flag, specific to C++
+ bool mIsVirtual;
+
+ // TRUE, if definition follows the declaration immediatelly
+ bool mHasDefinition;
+
+ // scope if any (e.g. MyClass::MyFunction(), scope stirng is "MyClass" )
+ // usually found along with implementation of the method, which is now skipped
+
+ string mScope;
+
+public:
+ spOperation();
+
+ // returns full declaration of the operations
+ // (ret val., identifier, arg. list),
+
+ // arguments are marked up with italic,
+ // default values marked up with bold-italic,
+ // all the rest is marked as bold
+
+ // NOTE:: this method may be overriden by class
+ // specific to concrete parser, to provide
+ // language-dependent reperesnetation of
+ // operation and it's argumetn list
+ //
+ // the default implementation outputs name in
+ // C++/Java syntax
+
+ virtual string GetFullName(MarkupTagsT tags);
+
+ virtual int GetContextType() const { return SP_CTX_OPERATION; }
+
+ virtual void AcceptVisitor( spVisitor& visitor )
+ { visitor.VisitOperation( *this ); }
+
+ DECLARE_DUMP
+};
+
+// stores infromation about preprocessor directive
+
+class spPreprocessorLine : public spContext
+{
+
+public:
+
+ // prepocessor statement including '#' and
+ // attached multiple lines with '\' character
+ string mLine;
+
+ int mDefType; // see SP_PREP_DEFINITION_TYPES enumeration
+
+public:
+
+ virtual int GetContextType() const { return SP_CTX_PREPROCESSOR; }
+
+ virtual int GetStatementType() const { return mDefType; }
+
+ string CPP_GetIncludedFileNeme() const;
+
+ virtual void AcceptVisitor( spVisitor& visitor )
+ { visitor.VisitPreprocessorLine( *this ); }
+
+ DECLARE_DUMP
+};
+
+// stores information about the class
+
+class spClass : public spContext
+{
+public:
+ // list of superclasses/interfaces
+ StrListT mSuperClassNames;
+
+ // see SP_CLASS_TYPES enumeration
+ int mClassSubType;
+
+ // see SP_INHERITANCE_TYPES enumeration
+ int mInheritanceType;
+
+ // valid if mClassSubType is SP_CLTYPE_TEMPLATE_CLASS
+ string mTemplateTypes;
+
+ // TRUE, if it's and interface of abstract base class
+ bool mIsAbstract;
+
+public:
+ // sorts class members in the following order:
+ //
+ // (by "privacy level" - first private, than protected, public)
+ //
+ // within above set
+ //
+ // (by member type - attributes first, than methods, nested classes)
+ //
+ // within above set
+ //
+ // (by identifier of the member)
+
+ virtual void SortMembers();
+
+ virtual int GetContextType() const { return SP_CTX_CLASS; }
+
+ virtual void AcceptVisitor( spVisitor& visitor )
+ { visitor.VisitClass( *this ); }
+
+ DECLARE_DUMP
+};
+
+// stores information about enum statement
+
+class spEnumeration : public spContext
+{
+public:
+ string mEnumContent; // full-text content of enumeration
+
+public:
+ virtual int GetContextType() const { return SP_CTX_ENUMERATION; }
+
+ virtual void AcceptVisitor( spVisitor& visitor )
+ { visitor.VisitEnumeration( *this ); }
+
+ DECLARE_DUMP
+};
+
+class spTypeDef : public spContext
+{
+public:
+ // the original type which is redefined
+ // by this type definition
+ string mOriginalType;
+
+public:
+ virtual int GetContextType() const { return SP_CTX_TYPEDEF; }
+
+ virtual void AcceptVisitor( spVisitor& visitor )
+ { visitor.VisitTypeDef( *this ); }
+
+ DECLARE_DUMP
+};
+
+// NOTE:: files context may be put to other
+// file context, resulting in a collection
+// of parsed file contexts, with a virtual "superfile"
+
+class spFile : public spContext
+{
+public:
+ // since file name cannot be determined from
+ // source code, filling in this field is optional
+ string mFileName;
+
+public:
+ virtual int GetContextType() const { return SP_CTX_FILE; }
+
+ virtual void AcceptVisitor( spVisitor& visitor )
+ { visitor.VisitFile( *this ); }
+
+ DECLARE_DUMP
+};
+
+//TODO:: comments.
+
+class SourceParserPlugin
+{
+public:
+ virtual bool CanUnderstandContext( char* cur, char* end, spContext* pOuttterCtx ) = 0;
+ virtual void ParseContext( char* start, char*& cur, char* end, spContext* pOuttterCtx ) = 0;
+};
+
+// abstract interface for source parsers
+// which can output parsing results in the
+// form of context-tree, where each node
+// should be derivative of spContext, (see
+// above classes)
+
+class SourceParserBase
+{
+private:
+ // auto-resizing file buffer, created in ParseFile()
+ // to reuse large heap block for multiple parsings
+
+ char* mpFileBuf;
+ int mFileBufSz;
+
+protected:
+ SourceParserPlugin* mpPlugin;
+
+protected:
+ // value is set in the derived parser classes
+ int mParserStatus;
+
+public:
+ SourceParserBase();
+ virtual ~SourceParserBase();
+
+ // loads entier source file(as text) into memory,
+ // and passes it's contents to ParseAll() method,
+ // memory occupied by source text is released after
+ // parsing is done
+ //
+ // (NOTE:: this is the default implementation),
+
+ virtual spFile* ParseFile( const char* fname );
+
+ // should returns the root-node of the created context tree
+ // (user is responsible for releasing it from the heep)
+ // "end" should point to the (last character + 1) of the
+ // source text area
+
+ virtual spFile* Parse( char* start, char* end ) = 0;
+
+ // returns parser "status word" (specific to concrete parser)
+ int GetParserStatus() { return mParserStatus; }
+
+ void SetPlugin( SourceParserPlugin* pPlugin );
+};
+
+#endif
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: No names yet.
+// Purpose: Contrib. demo
+// Author: Aleksandras Gluchovas
+// Modified by:
+// Created: 27/09/98
+// RCS-ID: $Id$
+// Copyright: (c) Aleskandars Gluchovas
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __WXSTLAC_G__
+#define __WXSTLAC_G__
+
+#ifdef new
+#undef new
+#endif
+
+#include <stddef.h>
+#include <sys/types.h>
+#include <memory.h>
+#include <limits.h>
+#include <new.h>
+
+// the below macro used internally (see actual interface after this macro)
+
+// arguments:
+//
+// ARG_IS_UNIQUE
+// ASSOC_CONT_CLASS_NAME
+//
+// ARG_VALUE_TYPE
+// ARG_KEY_TYPE
+// ARG_ACTUAL_VALUE_TYPE
+//
+// _KEY_NAME
+// _VALUE_NAME
+//
+// _X_KEY_NAME
+// _X_VALUE_NAME
+//
+// _INSERT_METHOD_DEFINITION
+
+#define __DEFINE_ASOC_CLASS( ARG_IS_UNIQUE, \
+FUNCTOR,\
+ASSOC_CONT_CLASS_NAME, \
+ARG_VALUE_TYPE, \
+ARG_KEY_TYPE, \
+ARG_ACTUAL_VALUE_TYPE, \
+_KEY_NAME, \
+_VALUE_NAME, \
+_X_KEY_NAME, \
+_X_VALUE_NAME, \
+_INSERT_METHOD_DEFINITION \
+) class \
+ASSOC_CONT_CLASS_NAME\
+{\
+protected:\
+\
+public:\
+ typedef ARG_VALUE_TYPE value_type;\
+ typedef ARG_KEY_TYPE key_type;\
+ typedef ARG_ACTUAL_VALUE_TYPE actual_value_type;\
+\
+ typedef value_type* pointer;\
+ typedef value_type& reference;\
+\
+ typedef const value_type& const_reference;\
+\
+ typedef FUNCTOR key_compare;\
+ typedef key_compare Compare;\
+\
+protected:\
+\
+ struct tree_node \
+ {\
+ tree_node* mpParent;\
+ tree_node* mpLeft;\
+ tree_node* mpRight;\
+\
+ value_type mData;\
+ };\
+\
+ typedef tree_node* node_ref_type;\
+\
+ node_ref_type mpRoot;\
+ node_ref_type mpLeftMost;\
+ node_ref_type mpRightMost;\
+\
+ node_ref_type mpFreeListHead;\
+ int mKeyIsUnique;\
+\
+ key_compare mCmpFunctorObj;\
+\
+public:\
+\
+ static inline node_ref_type next( node_ref_type pNode )\
+ {\
+ if ( pNode->mpRight ) \
+ {\
+ pNode = pNode->mpRight;\
+\
+ while ( pNode->mpLeft ) pNode = pNode->mpLeft;\
+\
+ return pNode;\
+ }\
+ else\
+ if ( pNode->mpParent )\
+ {\
+ if ( pNode == pNode->mpParent->mpLeft )\
+\
+ return pNode->mpParent;\
+\
+ pNode = pNode->mpParent;\
+\
+ node_ref_type prevNode = pNode;\
+ pNode = pNode->mpParent;\
+\
+ while(pNode)\
+ {\
+ if ( pNode->mpRight &&\
+ pNode->mpRight != prevNode\
+ ) return pNode;\
+\
+ prevNode = pNode;\
+ pNode= pNode->mpParent;\
+ }\
+\
+ return 0;\
+ }\
+ else\
+ return 0;\
+ }\
+\
+ static inline node_ref_type prev( node_ref_type pNode )\
+ {\
+ if ( pNode->mpLeft ) \
+ {\
+ pNode = pNode->mpLeft;\
+\
+ while ( pNode->mpRight ) pNode = pNode->mpRight;\
+\
+ return pNode;\
+ }\
+ else\
+ if ( pNode->mpParent )\
+ {\
+ if ( pNode == pNode->mpParent->mpRight )\
+ return pNode->mpParent;\
+\
+ pNode = pNode->mpParent;\
+\
+ node_ref_type prevNode = pNode;\
+ pNode = pNode->mpParent;\
+\
+ while(pNode)\
+ {\
+ if ( pNode->mpLeft &&\
+ pNode->mpLeft != prevNode\
+ ) return pNode;\
+\
+ prevNode = pNode;\
+ pNode= pNode->mpParent;\
+ }\
+\
+ return 0;\
+ }\
+ else \
+ return 0;\
+ }\
+\
+protected:\
+\
+ inline int are_equel( const key_type& x, const key_type& y )\
+ {\
+ return ( !mCmpFunctorObj(x,y) && !mCmpFunctorObj(y,x) );\
+ }\
+\
+ inline int is_less( const key_type& x, const key_type& y )\
+ {\
+ return mCmpFunctorObj(x,y);\
+ }\
+\
+ static inline const actual_value_type& value( node_ref_type pNode )\
+ {\
+ return pNode->_VALUE_NAME;\
+ }\
+\
+ static inline const key_type& key( node_ref_type pNode )\
+ {\
+ return pNode->_KEY_NAME;\
+ }\
+\
+ inline node_ref_type AllocNode() \
+ { \
+ if ( mpFreeListHead ) \
+ {\
+ node_ref_type pFreeNode = mpFreeListHead;\
+ mpFreeListHead = mpFreeListHead->mpLeft;\
+\
+ return pFreeNode;\
+ }\
+ else\
+ {\
+ char* pHeapBlock = new char[sizeof(tree_node)];\
+\
+ return (node_ref_type)pHeapBlock;\
+ }\
+ }\
+\
+ inline void DestroyFreeList()\
+ {\
+ while ( mpFreeListHead )\
+ {\
+ node_ref_type tmp = mpFreeListHead;\
+ mpFreeListHead = mpFreeListHead->mpLeft;\
+\
+ delete [](char*)tmp;\
+ }\
+ }\
+\
+ inline void RecycleNode( node_ref_type pNode ) \
+ {\
+ pNode->mpLeft = mpFreeListHead;\
+ mpFreeListHead = pNode;\
+ }\
+\
+ inline node_ref_type do_insert(const value_type& x = value_type() )\
+ {\
+ node_ref_type pNewNode = AllocNode();\
+\
+ pNewNode->mpParent = \
+ pNewNode->mpLeft =\
+ pNewNode->mpRight = 0;\
+\
+ node_ref_type pCurrent = mpRoot;\
+ node_ref_type pParent = 0;\
+ \
+ while (pCurrent) \
+ {\
+ if ( mKeyIsUnique && are_equel( _X_KEY_NAME, value(pCurrent) ) )\
+ {\
+ RecycleNode(pNewNode);\
+ return 0;\
+ }\
+\
+ pParent = pCurrent;\
+\
+ pCurrent = is_less( _X_KEY_NAME, value(pCurrent) ) \
+ ? pCurrent->mpLeft \
+ : pCurrent->mpRight;\
+ }\
+ \
+ pNewNode->mpParent = pParent;\
+\
+ if(pParent)\
+\
+ if( is_less(_X_KEY_NAME, value(pParent) ) )\
+ \
+ pParent->mpLeft = pNewNode;\
+ else\
+ pParent->mpRight = pNewNode;\
+ else\
+ mpRoot = pNewNode;\
+\
+ new ( &pNewNode->_KEY_NAME ) key_type(_X_KEY_NAME);\
+ new ( &pNewNode->_VALUE_NAME ) actual_value_type(_X_VALUE_NAME);\
+\
+ if ( prev(pNewNode) == 0 ) mpLeftMost = pNewNode;\
+ if ( next(pNewNode) == 0 ) mpRightMost = pNewNode;\
+\
+ return pNewNode;\
+ }\
+\
+ friend class iterator;\
+\
+public:\
+\
+ class iterator;\
+ class const_iterator;\
+\
+ class iterator \
+ {\
+ public:\
+ node_ref_type mpNode;\
+ friend class CONT_CLASS_NAME;\
+ friend class const_iterator;\
+ friend class const_reverse_iterator;\
+\
+ inline iterator( node_ref_type pNode )\
+ {\
+ mpNode = pNode;\
+ }\
+ \
+ public:\
+ inline iterator() {}\
+ inline int operator==( const iterator& rhs ) const { return (mpNode == rhs.mpNode); }\
+ inline int operator!=( const iterator& rhs ) const { return (mpNode != rhs.mpNode); }\
+\
+ inline iterator( const iterator& other )\
+ {\
+ mpNode = other.mpNode;\
+ }\
+\
+ inline const iterator& operator=( const iterator& other )\
+ {\
+ mpNode = other.mpNode;\
+ return *this;\
+ }\
+\
+ inline const iterator& operator--() \
+ {\
+ mpNode = ASSOC_CONT_CLASS_NAME::prev(mpNode);\
+ return *this;\
+ }\
+\
+ inline iterator operator--(int)\
+ {\
+ iterator tmp = *this;\
+ mpNode = ASSOC_CONT_CLASS_NAME::prev(mpNode);\
+ return tmp;\
+ }\
+\
+ inline const iterator& operator++() \
+ {\
+ mpNode = ASSOC_CONT_CLASS_NAME::next(mpNode);\
+ return *this;\
+ }\
+\
+ inline iterator operator++(int)\
+ {\
+ iterator tmp = *this;\
+ mpNode = ASSOC_CONT_CLASS_NAME::next(mpNode);\
+ return tmp;\
+ }\
+\
+ inline reference operator*() const { return mpNode->mData; }\
+ };\
+\
+\
+ class const_iterator \
+ {\
+ public:\
+ node_ref_type mpNode;\
+ friend class CONT_CLASS_NAME;\
+ friend class const_reverse_iterator;\
+\
+ inline const_iterator( node_ref_type pNode )\
+ {\
+ mpNode = pNode;\
+ }\
+ \
+ public:\
+ inline const_iterator() {}\
+\
+ inline int operator==( const const_iterator& rhs ) const { return (mpNode == rhs.mpNode); }\
+ inline int operator!=( const const_iterator& rhs ) const { return (mpNode != rhs.mpNode); }\
+\
+ inline const_iterator( const iterator& other )\
+ {\
+ mpNode = other.mpNode;\
+ }\
+\
+ inline const_iterator( const const_iterator& other )\
+ {\
+ mpNode = other.mpNode;\
+ }\
+\
+ inline const const_iterator& operator=( const const_iterator& other )\
+ {\
+ mpNode = other.mpNode;\
+ return *this;\
+ }\
+\
+ inline const const_iterator& operator--() \
+ {\
+ mpNode = ASSOC_CONT_CLASS_NAME::prev(mpNode);\
+ return *this;\
+ }\
+\
+ inline const_iterator operator--(int)\
+ {\
+ const_iterator tmp = *this;\
+ mpNode = ASSOC_CONT_CLASS_NAME::prev(mpNode);\
+ return tmp;\
+ }\
+\
+ inline const const_iterator& operator++() \
+ {\
+ mpNode = ASSOC_CONT_CLASS_NAME::next(mpNode);\
+ return *this;\
+ }\
+\
+ inline const_iterator operator++(int)\
+ {\
+ const_iterator tmp = *this;\
+ mpNode = ASSOC_CONT_CLASS_NAME::next(mpNode);\
+ return tmp;\
+ }\
+\
+ inline const_reference operator*() const { return mpNode->mData; }\
+ };\
+\
+public:\
+\
+ inline ASSOC_CONT_CLASS_NAME( key_compare cmpFunctorObj = key_compare(),\
+ int keyIsUnique = ARG_IS_UNIQUE )\
+ : mpFreeListHead( 0 ),\
+ mKeyIsUnique( keyIsUnique ),\
+ mCmpFunctorObj( cmpFunctorObj )\
+ {\
+ mpLeftMost = 0;\
+ mpRightMost = 0;\
+ mpRoot = 0;\
+ }\
+\
+ inline ~ASSOC_CONT_CLASS_NAME() \
+ { \
+ erase( begin(), end() ); \
+\
+ DestroyFreeList();\
+ }\
+\
+ inline iterator begin() { return mpLeftMost; }\
+ inline iterator end() { return 0; }\
+\
+ inline const_iterator begin() const { return mpLeftMost; }\
+ inline const_iterator end() const { return 0; }\
+\
+ inline iterator lower_bound( const key_type& x )\
+ { \
+ node_ref_type pCurrent = mpRoot;\
+ \
+ while( pCurrent )\
+ {\
+ node_ref_type pParent = pCurrent;\
+\
+ if( are_equel( x, key(pCurrent) ) )\
+ \
+ return (pCurrent);\
+ else\
+ pCurrent = is_less( x, key(pCurrent) ) \
+ ? pCurrent->mpLeft \
+ : pCurrent->mpRight;\
+\
+ if ( !pCurrent ) return (pParent);\
+ }\
+\
+ return begin();\
+ }\
+\
+ inline const_iterator lower_bound( const key_type& x ) const\
+\
+ { return const_iterator( lower_bound(x).mpNode ); }\
+\
+ inline iterator upper_bound( const key_type& x )\
+ {\
+ node_ref_type pCurrent = mpRoot;\
+ \
+ while( pCurrent )\
+ {\
+ node_ref_type pParent = pCurrent;\
+\
+ if( are_equel( x, key(pCurrent) ) )\
+ \
+ return (pCurrent);\
+ else\
+ pCurrent = is_less( x, key(pCurrent) ) \
+ ? pCurrent->mpLeft \
+ : pCurrent->mpRight;\
+\
+ if ( !pCurrent ) return next(pParent);\
+ }\
+\
+ return end();\
+ }\
+\
+ inline const_iterator upper_bound( const key_type& x ) const\
+\
+ { return const_iterator( upper_bound(x).mpNode ); }\
+\
+ inline iterator find( const key_type& x )\
+ {\
+ node_ref_type pCurrent = mpRoot;\
+ \
+ while( pCurrent )\
+ {\
+ if( are_equel( x, key(pCurrent) ) )\
+ \
+ return (pCurrent);\
+ else\
+ pCurrent = is_less( x, key(pCurrent) ) \
+ ? pCurrent->mpLeft \
+ : pCurrent->mpRight;\
+ }\
+\
+ return end();\
+ }\
+\
+ inline const_iterator find( const key_type& x ) const\
+\
+ { return const_iterator( find(x).mpNode ); }\
+\
+ inline void erase(iterator first, iterator last)\
+ {\
+ if ( first.mpNode == 0 ) return;\
+\
+ while( first != last ) \
+ {\
+ iterator next = first;\
+ ++next;\
+ erase( first );\
+ first = next;\
+ }\
+ }\
+\
+ inline void erase(iterator position)\
+ {\
+ if ( position.mpNode == 0 ) return;\
+\
+ node_ref_type pZ = position.mpNode;\
+ node_ref_type pX, pY;\
+\
+ if ( pZ == mpLeftMost ) mpLeftMost = next(pZ);\
+ if ( pZ == mpRightMost ) mpRightMost = prev( pZ );\
+\
+ if ( !pZ->mpLeft || !pZ->mpRight )\
+ \
+ pY = pZ;\
+ else \
+ {\
+ pY = pZ->mpRight;\
+ \
+ while (pY->mpLeft) \
+ \
+ pY = pY->mpLeft;\
+ }\
+ \
+ if ( pY->mpLeft)\
+ \
+ pX = pY->mpLeft;\
+ else\
+ pX = pY->mpRight;\
+ \
+ if ( pX ) pX->mpParent = pY->mpParent;\
+ \
+ if (pY->mpParent)\
+ \
+ if (pY == pY->mpParent->mpLeft )\
+ \
+ pY->mpParent->mpLeft = pX;\
+ else\
+ pY->mpParent->mpRight = pX;\
+ else\
+ mpRoot = pX;\
+ \
+ node_ref_type toRemove = 0;\
+ \
+ if (pY != pZ) {\
+ \
+ pY->mpLeft = pZ->mpLeft;\
+ \
+ if (pY->mpLeft) pY->mpLeft->mpParent = pY;\
+ \
+ pY->mpRight = pZ->mpRight;\
+ \
+ if ( pY->mpRight ) \
+ \
+ pY->mpRight->mpParent = pY;\
+ \
+ pY->mpParent = pZ->mpParent;\
+ \
+ if (pZ->mpParent)\
+ \
+ if (pZ == pZ->mpParent->mpLeft)\
+ \
+ pZ->mpParent->mpLeft = pY;\
+ else\
+ pZ->mpParent->mpRight = pY;\
+ else\
+ mpRoot = pY;\
+ \
+ toRemove = pZ;\
+ } \
+ else \
+ toRemove = pY;\
+ \
+ value(toRemove).~actual_value_type();\
+ key(toRemove).~actual_value_type();\
+\
+ RecycleNode( toRemove );\
+ }\
+\
+ _INSERT_METHOD_DEFINITION\
+}
+
+// do not undefine ___WXSTL_COMMA, where associated containers are defined!
+// (it is used as workaround for constraints of C-Preprocessor's nested macros)
+
+#define ___WXSTL_COMMA ,
+
+#define __DEFINE_MAP(ARG_IS_UNIQUE, KEY_TYPE, VAL_TYPE, FUNCTOR ) __DEFINE_ASOC_CLASS( ARG_IS_UNIQUE,\
+FUNCTOR,\
+__WXSTLMAP_##KEY_TYPE##VAL_TYPE##ARG_IS_UNIQUE, \
+struct key_value_pair { KEY_TYPE first ; \
+ VAL_TYPE second;\
+ key_value_pair() {}\
+ key_value_pair( const KEY_TYPE& key ___WXSTL_COMMA const VAL_TYPE& value ) \
+ : first(key) ___WXSTL_COMMA second( value ) {} \
+ } , \
+KEY_TYPE,\
+VAL_TYPE,\
+mData.first, mData.second, x.first, x.second, \
+struct insert_result_iterator\
+{\
+ iterator first;\
+ int second;\
+};\
+inline insert_result_iterator insert( const value_type& x )\
+{\
+ insert_result_iterator result;\
+\
+ result.first = do_insert(x);\
+ result.second = ( result.first == end() ) ? 0 : 1;\
+\
+ return result;\
+} )
+
+#define __DEFINE_SET(ARG_IS_UNIQUE, KEY_TYPE, FUNCTOR ) __DEFINE_ASOC_CLASS( ARG_IS_UNIQUE,\
+FUNCTOR,\
+__WXSTLSET_##TYPE##ARG_IS_UNIQUE, \
+KEY_TYPE,\
+KEY_TYPE,\
+KEY_TYPE,\
+mData, mData, x, x, \
+struct insert_result_iterator\
+{\
+ iterator first;\
+ int second;\
+};\
+inline insert_result_iterator insert( const value_type& x )\
+{\
+ insert_result_iterator result;\
+\
+ result.first = do_insert(x);\
+ result.second = ( result.first == end() ) ? 0 : 1;\
+\
+ return result;\
+} )
+
+// helper macros to create functor objects for associative containers of the given type
+
+#define LESS_THEN_FUNCTOR(TYPE) struct \
+{ inline int operator()(const TYPE& x, const TYPE& y ) const { return x < y; } }
+
+#define GREATER_THEN_FUNCTOR(TYPE) struct \
+{ inline int operator()(const TYPE& x, const TYPE& y ) const { return x > y; } }
+
+// functor argument should be created using the two above macros
+// or passing own class with method "operator()(const TYPE&,cosnt TYPE&)" defined in it
+
+#define WXSTL_MAP( KEY_TYPE, VALUE_TYPE, FUNCTOR ) __DEFINE_MAP( 1 ,KEY_TYPE, VALUE_TYPE, FUNCTOR)
+#define WXSTL_MULTIMAP( KEY_TYPE, VALUE_TYPE, FUNCTOR ) __DEFINE_MAP( 0 ,KEY_TYPE, VALUE_TYPE, FUNCTOR)
+#define WXSTL_SET( KEY_TYPE, FUNCTOR ) __DEFINE_SET( 1 ,KEY_TYPE, FUNCTOR )
+#define WXSTL_MULTISET( KEY_TYPE, FUNCTOR ) __DEFINE_SET( 0 ,KEY_TYPE, FUNCTOR )
+
+#endif
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: No names yet.
+// Purpose: Contrib. demo
+// Author: Aleksandras Gluchovas
+// Modified by:
+// Created: 27/09/98
+// RCS-ID: $Id$
+// Copyright: (c) Aleskandars Gluchovas
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __WXSTLLST_G__
+#define __WXSTLLST_G__
+
+#ifdef new
+#undef new
+#endif
+
+#include <stddef.h>
+#include <sys/types.h>
+#include <memory.h>
+#include <limits.h>
+#include <new.h>
+
+// VERSION:: 0.2 (copy-constructor/adign-op added)
+
+// FOR NOW:: class-member operators "new" and "delete"
+// are ignored by list class, memory allocated
+// and freed using global operators
+
+typedef int Type;
+
+
+// the below macro used internally (see actual interface after this macro)
+
+#define __DEFINE_STL_LIST(listClass,Type) class \
+ listClass \
+{\
+public:\
+\
+ typedef Type value_type;\
+ typedef value_type* pointer;\
+ typedef const value_type* const_pointer;\
+ typedef value_type& reference;\
+ typedef const value_type& const_reference;\
+ typedef size_t size_type;\
+ typedef ptrdiff_t difference_type;\
+\
+protected:\
+ struct list_node\
+ {\
+ list_node* mpNext;\
+ list_node* mpPrev;\
+ value_type mData;\
+ };\
+\
+ typedef list_node* node_ref_type;\
+\
+ node_ref_type mpFreeListHead;\
+ node_ref_type mpTerminator;\
+ size_type mSize;\
+\
+ inline node_ref_type AllocNode() \
+ { \
+ if ( mpFreeListHead ) \
+ {\
+ node_ref_type pFreeNode = mpFreeListHead;\
+ mpFreeListHead = mpFreeListHead->mpPrev;\
+\
+ return pFreeNode;\
+ }\
+ else\
+ {\
+ char* pHeapBlock = new char[sizeof(list_node)];\
+\
+ return (node_ref_type)pHeapBlock;\
+ }\
+ }\
+\
+ inline void DestroyFreeList()\
+ {\
+ while ( mpFreeListHead )\
+ {\
+ node_ref_type tmp = mpFreeListHead;\
+ mpFreeListHead = mpFreeListHead->mpPrev;\
+\
+ delete [](char*)tmp;\
+ }\
+ }\
+\
+ inline void RecycleNode( node_ref_type pNode ) \
+ {\
+ pNode->mpPrev = mpFreeListHead;\
+ mpFreeListHead = pNode;\
+ }\
+\
+public:\
+\
+ class iterator \
+ {\
+ public:\
+ node_ref_type mpNode;\
+ friend class listClass;\
+ friend class const_iterator;\
+ friend class const_reverse_iterator;\
+\
+ protected:\
+ iterator( node_ref_type pNode )\
+ {\
+ mpNode = pNode;\
+ }\
+ \
+ public:\
+ iterator() {}\
+ int operator==( const iterator& rhs ) const { return (mpNode == rhs.mpNode); }\
+ int operator!=( const iterator& rhs ) const { return (mpNode != rhs.mpNode); }\
+\
+ inline iterator( const iterator& other )\
+ {\
+ mpNode = other.mpNode;\
+ }\
+\
+ inline const iterator& operator--() \
+ {\
+ mpNode = mpNode->mpPrev;\
+ return *this;\
+ }\
+\
+ inline iterator operator--(int)\
+ {\
+ iterator tmp = *this;\
+ mpNode = mpNode->mpPrev;\
+ return tmp;\
+ }\
+\
+ inline const iterator& operator++() \
+ {\
+ mpNode = mpNode->mpNext;\
+ return *this;\
+ }\
+\
+ inline iterator operator++(int)\
+ {\
+ iterator tmp = *this;\
+ mpNode = mpNode->mpNext;\
+ return tmp;\
+ }\
+\
+ inline reference operator*() const { return mpNode->mData; }\
+ };\
+\
+\
+ class const_iterator \
+ {\
+ protected:\
+ node_ref_type mpNode;\
+ friend class listClass;\
+\
+ protected:\
+ const_iterator( node_ref_type pNode )\
+ {\
+ mpNode = pNode;\
+ }\
+ \
+ public:\
+ \
+ const_iterator() {}\
+ int operator==( const const_iterator& rhs ) const { return (mpNode == rhs.mpNode); }\
+ int operator!=( const const_iterator& rhs ) const { return (mpNode != rhs.mpNode); }\
+\
+\
+ inline const_iterator( const iterator& other )\
+ {\
+ mpNode = other.mpNode;\
+ }\
+\
+ inline const const_iterator& operator--() \
+ {\
+ mpNode = mpNode->mpPrev;\
+ return *this;\
+ }\
+\
+ inline const_iterator operator--(int)\
+ {\
+ const_iterator tmp = *this;\
+ mpNode = mpNode->mpPrev;\
+ return tmp;\
+ }\
+\
+ inline const const_iterator& operator++() \
+ {\
+ mpNode = mpNode->mpNext;\
+ return *this;\
+ }\
+\
+ inline const_iterator operator++(int)\
+ {\
+ const_iterator tmp = *this;\
+ mpNode = mpNode->mpNext;\
+ return tmp;\
+ }\
+\
+ inline const_reference operator*() const { return mpNode->mData; }\
+ };\
+\
+ typedef iterator OutputIterator;\
+ typedef const_iterator InputIterator;\
+\
+ class reverse_iterator \
+ {\
+ public:\
+ node_ref_type mpNode;\
+ friend class listClass;\
+ friend class const_reverse_iterator;\
+\
+ protected:\
+ reverse_iterator ( node_ref_type pNode )\
+ {\
+ mpNode = pNode;\
+ }\
+ \
+ public:\
+\
+ reverse_iterator() {}\
+ int operator==( const reverse_iterator& rhs ) const { return (mpNode == rhs.mpNode); }\
+ int operator!=( const reverse_iterator& rhs ) const { return (mpNode != rhs.mpNode); }\
+\
+ inline reverse_iterator( const reverse_iterator& other )\
+ {\
+ mpNode = other.mpNode;\
+ }\
+\
+ inline const reverse_iterator& operator--() \
+ {\
+ mpNode = mpNode->mpNext;\
+ return *this;\
+ }\
+\
+ inline reverse_iterator operator--(int)\
+ {\
+ reverse_iterator tmp = *this;\
+ mpNode = mpNode->mpPrev;\
+ return tmp;\
+ }\
+\
+ inline const reverse_iterator & operator++() \
+ {\
+ mpNode = mpNode->mpNext;\
+ return *this;\
+ }\
+\
+ inline reverse_iterator operator++(int)\
+ {\
+ reverse_iterator tmp = *this;\
+ mpNode = mpNode->mpPrev;\
+ return tmp;\
+ }\
+\
+ inline const_reference operator*() const { return mpNode->mData; }\
+ };\
+\
+\
+ class const_reverse_iterator \
+ {\
+ protected:\
+ node_ref_type mpNode;\
+ friend class listClass;\
+\
+ protected:\
+ const_reverse_iterator( node_ref_type pNode )\
+ {\
+ mpNode = pNode;\
+ }\
+ \
+ public:\
+\
+ const_reverse_iterator() {}\
+ int operator==( const const_reverse_iterator& rhs ) const { return (mpNode == rhs.mpNode); }\
+ int operator!=( const const_reverse_iterator& rhs ) const { return (mpNode != rhs.mpNode); }\
+\
+ inline const_reverse_iterator( const reverse_iterator& other )\
+ {\
+ mpNode = other.mpNode;\
+ }\
+\
+ inline const const_reverse_iterator& operator--() \
+ {\
+ mpNode = mpNode->mpNext;\
+ return *this;\
+ }\
+\
+ inline const_reverse_iterator operator--(int)\
+ {\
+ const_reverse_iterator tmp = *this;\
+ mpNode = mpNode->mpNext;\
+ return tmp;\
+ }\
+\
+ inline const const_reverse_iterator& operator++() \
+ {\
+ mpNode = mpNode->mpPrev;\
+ return *this;\
+ }\
+\
+ inline const_reverse_iterator operator++(int)\
+ {\
+ const_reverse_iterator tmp = *this;\
+ mpNode = mpNode->mpPrev;\
+ return tmp;\
+ }\
+\
+ inline const_reference operator*() const { return mpNode->mData; }\
+ };\
+\
+public:\
+\
+ inline listClass()\
+ : mpFreeListHead( 0 ),\
+ mSize(0)\
+ {\
+ mpTerminator = AllocNode();\
+ mpTerminator->mpPrev = mpTerminator->mpNext = mpTerminator;\
+ }\
+\
+ listClass( const listClass& other )\
+ {\
+ mpTerminator = AllocNode();\
+ mpTerminator->mpPrev = mpTerminator->mpNext = mpTerminator;\
+\
+ for( listClass::const_iterator i = other.begin(); i != other.end(); ++i )\
+\
+ push_back( (*i) );\
+ }\
+\
+ inline const listClass& operator=( const listClass& rhs ) \
+ {\
+ erase( begin(), end() );\
+\
+ for( listClass::const_iterator i = rhs.begin(); i != rhs.end(); ++i )\
+\
+ push_back( (*i) );\
+\
+ return *this;\
+ }\
+\
+ inline listClass(const_iterator first, const_iterator last)\
+ : mpFreeListHead( 0 ),\
+ mSize(0)\
+ \
+ { while( first != last ) push_back( *first++ ); }\
+\
+ inline listClass( size_type n, const value_type& value = value_type() )\
+ \
+ { for( size_t i = 0; i != n; ++n ) push_back( value ); }\
+\
+ inline ~listClass() \
+ { \
+ erase( begin(), end() ); \
+\
+ RecycleNode( mpTerminator );\
+ DestroyFreeList();\
+ }\
+\
+ inline iterator begin() { return iterator(mpTerminator->mpNext); }\
+ \
+ inline const_iterator begin() const \
+ { return const_iterator(mpTerminator->mpNext); }\
+ \
+ inline iterator end() { return iterator(mpTerminator); }\
+\
+ inline const_iterator end() const { return const_iterator(mpTerminator); }\
+\
+ inline reverse_iterator rbegin() \
+ { return reverse_iterator(mpTerminator->mpPrev); }\
+\
+ inline reverse_iterator rend() \
+ { return reverse_iterator(mpTerminator); }\
+\
+ inline const_reverse_iterator rbegin() const\
+ { return const_reverse_iterator(mpTerminator->mpPrev); }\
+\
+ inline const_reverse_iterator rend() const\
+ { return const_reverse_iterator(mpTerminator); }\
+\
+ inline int empty() const { return (mSize == 0); }\
+\
+ inline size_type size() const { return mSize; }\
+\
+ inline size_type max_size() const { return UINT_MAX/sizeof(list_node); }\
+\
+ inline reference front() { return mpTerminator->mData; }\
+\
+ inline const_reference front() const { return mpTerminator->mData; }\
+\
+ inline reference back() { return mpTerminator->mpPrev->mData; }\
+\
+ inline const_reference back() const { return mpTerminator->mpPrev->mData; }\
+\
+ inline void push_front(const value_type& x) { insert( begin(), x ); }\
+\
+ inline void push_back(const value_type& x) { insert( end(), x ); }\
+\
+ iterator insert(iterator position, const value_type& x = value_type())\
+ {\
+ node_ref_type pNew = AllocNode();\
+\
+ node_ref_type pos = *((node_ref_type*)&position);\
+\
+ pNew->mpNext = pos;\
+ pNew->mpPrev = pos->mpPrev;\
+ pos->mpPrev->mpNext = pNew;\
+ pos->mpPrev = pNew;\
+\
+ new (&pNew->mData) value_type(x);\
+\
+ ++mSize;\
+\
+ return iterator(pNew);\
+ }\
+\
+ inline void insert(iterator position, const_iterator first, const_iterator last )\
+ {\
+ while( first != last ) insert( position, *first++ );\
+ }\
+\
+ inline void splice( iterator position, listClass& other )\
+ {\
+ if ( other.begin() == other.end() ) return;\
+\
+ node_ref_type pTill = other.mpTerminator->mpPrev;\
+ node_ref_type pFrom = other.begin().mpNode;\
+\
+ mpTerminator->mpPrev->mpNext = pFrom;\
+ pFrom->mpPrev = mpTerminator->mpPrev->mpNext;\
+\
+ pTill->mpNext = mpTerminator;\
+ mpTerminator->mpPrev = pTill;\
+\
+ other.mpTerminator->mpNext = \
+ other.mpTerminator->mpPrev = other.mpTerminator;\
+\
+ mSize += other.mSize;\
+ other.mSize = 0;\
+ }\
+\
+ inline void splice( iterator position, listClass& other, iterator first, iterator last )\
+ {\
+ if ( first == last ) return;\
+\
+ size_type sz = 0;\
+ iterator tmp = first;\
+ while( tmp != last ) \
+ {\
+ ++tmp;\
+ ++sz;\
+ }\
+\
+ mSize += sz;\
+ other.mSize -= sz;\
+\
+ node_ref_type pPos = position.mpNode;\
+ node_ref_type pFirst = first.mpNode;\
+ node_ref_type pLast = last.mpNode;\
+ node_ref_type pTill = last.mpNode->mpPrev;\
+\
+ pPos->mpPrev->mpNext = pFirst;\
+ pPos->mpPrev = pTill;\
+\
+ pFirst->mpPrev->mpNext = last.mpNode;\
+ pLast->mpPrev = pTill;\
+\
+ pFirst->mpPrev = pPos->mpPrev;\
+ pTill->mpNext = pPos;\
+ }\
+\
+ inline void pop_front() { erase( begin() ); }\
+ inline void pop_back() { erase( --end() ); }\
+ \
+ inline void erase(iterator position)\
+ {\
+ erase( position, ++position );\
+ }\
+ \
+ inline void erase(iterator first, iterator last)\
+ {\
+ node_ref_type firstNode = *((node_ref_type*)&first);\
+ node_ref_type lastNode = *((node_ref_type*)&last);\
+\
+ firstNode->mpPrev->mpNext = lastNode;\
+ lastNode->mpPrev = firstNode->mpPrev;\
+\
+ while( firstNode != lastNode )\
+ {\
+ node_ref_type next = firstNode->mpNext;\
+\
+ typedef value_type value_type_local;\
+ firstNode->mData.value_type_local::~value_type_local();\
+\
+ RecycleNode( firstNode );\
+\
+ firstNode = next;\
+\
+ --mSize;\
+ }\
+ }\
+\
+ inline void remove(const value_type& value)\
+ {\
+ for( iterator i = begin(); i != end(); ++i )\
+ \
+ if ( (*i) == value ) \
+ {\
+ erase( i ); break;\
+ }\
+ }\
+\
+ void sort()\
+ {\
+ if ( mSize < 2 ) return;\
+\
+ iterator from = begin();\
+ iterator other_end = end();\
+ --other_end;\
+\
+ for( size_type i = 0; i != mSize; ++i )\
+ {\
+ size_type nSwaps = 0;\
+\
+ iterator next = begin();\
+ ++next;\
+\
+ for( iterator j = begin(); j != other_end; ++j )\
+ {\
+\
+ if ( (*next) < (*j) )\
+ {\
+ value_type tmp = (*j);\
+ (*j) = (*next);\
+ (*next) = tmp;\
+\
+ ++nSwaps;\
+ }\
+\
+ ++next;\
+ }\
+\
+ if ( !nSwaps) break;\
+\
+ --other_end;\
+ }\
+ }\
+}
+
+// defines list class with the given element type
+#define WXSTL_LIST(ELEMENT_CLASS) __DEFINE_STL_LIST(\
+\
+_WXSTL_LIST_##ELEMENT_CLASS, ELEMENT_CLASS )
+
+#endif
\ No newline at end of file
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: No names yet.
+// Purpose: Contrib. demo
+// Author: Aleksandras Gluchovas
+// Modified by:
+// Created: 27/09/98
+// RCS-ID: $Id$
+// Copyright: (c) Aleskandars Gluchovas
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __WXSTLVEC_G__
+#define __WXSTLVEC_G__
+
+#ifdef new
+#undef new
+#endif
+
+#include <memory.h>
+#include <string.h> // imports memmove()
+#include <stddef.h>
+#include <sys/types.h>
+#include <limits.h>
+#include <new>
+
+// the below macro used internally (see actual interface after this macro)
+
+#define __DEFINE_STL_VECTOR_DEEP( vectorClass, Type ) class vectorClass {\
+\
+public:\
+ typedef Type value_type;\
+ typedef value_type* iterator;\
+ typedef const value_type* const_iterator;\
+ typedef iterator pointer;\
+ typedef const iterator const_pointer;\
+ typedef value_type& reference;\
+ typedef const value_type& const_reference;\
+ typedef size_t size_type;\
+ typedef ptrdiff_t difference_type;\
+\
+ typedef iterator OutputIterator;\
+ typedef const_iterator InputIterator;\
+\
+protected:\
+\
+ inline void PlacementCopy( const_iterator first, const_iterator last, iterator result )\
+ {\
+ while ( first != last ) \
+ new (result++) value_type(*first++);\
+ }\
+\
+ inline void ConstructObjects( iterator first, iterator last, const value_type& pattern )\
+ {\
+ while( first != last ) \
+ new (first++) value_type(pattern);\
+ }\
+\
+ inline void CopyObjects( iterator first, iterator last, iterator result )\
+ {\
+ while( first != last ) \
+ *result++ = *first++;\
+ }\
+\
+ inline void CopyObjectsBack( iterator first, iterator last, iterator result )\
+ {\
+ result += difference_type(last,first);\
+\
+ while( first != last ) \
+ *(--result) = *(--last);\
+ }\
+\
+public:\
+\
+ class reverse_iterator \
+ {\
+ friend class vectorClass;\
+ friend class const_reverse_iterator;\
+\
+ public:\
+ iterator mpPos;\
+\
+ public:\
+\
+ reverse_iterator() {}\
+\
+ reverse_iterator ( iterator pPos )\
+ {\
+ mpPos = pPos;\
+ }\
+ \
+ int operator==( const reverse_iterator& rhs ) const { return (mpPos == rhs.mpPos); }\
+ int operator!=( const reverse_iterator& rhs ) const { return (mpPos != rhs.mpPos); }\
+\
+ inline reverse_iterator( const reverse_iterator& other )\
+ {\
+ mpPos = other.mpPos;\
+ }\
+\
+ inline const reverse_iterator& operator--() \
+ {\
+ --mpPos;\
+ return *this;\
+ }\
+\
+ inline reverse_iterator operator--(int)\
+ {\
+ reverse_iterator tmp = *this;\
+ --mpPos;\
+ return tmp;\
+ }\
+\
+ inline const reverse_iterator & operator++() \
+ {\
+ ++mpPos;\
+ return *this;\
+ }\
+\
+ inline reverse_iterator operator++(int)\
+ {\
+ reverse_iterator tmp = *this;\
+ ++mpPos;\
+ return tmp;\
+ }\
+\
+ inline const_reference operator*() const { return *mpPos; }\
+ };\
+\
+\
+ class const_reverse_iterator \
+ {\
+ protected:\
+ iterator mpPos;\
+ public:\
+\
+ const_reverse_iterator() {}\
+\
+ const_reverse_iterator( const iterator pPos )\
+ {\
+ mpPos = pPos;\
+ }\
+ \
+ int operator==( const const_reverse_iterator& rhs ) const { return (mpPos == rhs.mpPos); }\
+ int operator!=( const const_reverse_iterator& rhs ) const { return (mpPos != rhs.mpPos); }\
+\
+ inline const_reverse_iterator( const reverse_iterator& other )\
+ {\
+ mpPos = other.mpPos;\
+ }\
+\
+ inline const const_reverse_iterator& operator--() \
+ {\
+ --mpPos;\
+ return *this;\
+ }\
+\
+ inline const_reverse_iterator operator--(int)\
+ {\
+ const_reverse_iterator tmp = *this;\
+ --mpPos;\
+ return tmp;\
+ }\
+\
+ inline const const_reverse_iterator & operator++() \
+ {\
+ ++mpPos;\
+ return *this;\
+ }\
+\
+ inline const_reverse_iterator operator++(int)\
+ {\
+ const_reverse_iterator tmp = *this;\
+ ++mpPos;\
+ return tmp;\
+ }\
+\
+ inline const_reference operator*() const { return *mpPos; }\
+ };\
+\
+protected:\
+ \
+ pointer mpStart;\
+ pointer mpEnd;\
+ pointer mpEndOfBuf;\
+\
+protected:\
+\
+ inline void quick_sort(int low, int hi) \
+ {\
+ }\
+\
+ inline void DestructRange( iterator first, iterator last )\
+ {\
+ typedef value_type value_type_local;\
+\
+ while ( first != last ) \
+ {\
+ first->value_type_local::~value_type_local();\
+ ++first;\
+ }\
+ }\
+\
+ inline iterator DoInsert(iterator position, const value_type& x)\
+ {\
+ if ( mpEnd < mpEndOfBuf )\
+ {\
+ new (mpEnd) value_type(*(mpEnd-1) );\
+ \
+ CopyObjectsBack( position, mpEnd, position + 1 );\
+ \
+ *position = x;\
+ \
+ ++mpEnd;\
+ \
+ return position;\
+ }\
+ \
+ size_type minBufLen = WXSTL_VECTOR_MIN_BUF_SIZE/sizeof(value_type);\
+ \
+ size_type doubledSize = size()*2;\
+ \
+ size_type newLen = ( doubledSize < minBufLen ) ? minBufLen : doubledSize;\
+ \
+ iterator pNewStart = (iterator)( new char[newLen*sizeof(value_type)] );\
+ \
+ PlacementCopy( mpStart, position, pNewStart );\
+ \
+ iterator atPosition = pNewStart + difference_type( position - mpStart );\
+ \
+ new (atPosition) value_type(x);\
+ \
+ iterator newPos = atPosition;\
+ \
+ ++atPosition;\
+ \
+ if ( mpStart ) \
+ {\
+ PlacementCopy( position, mpEnd, atPosition );\
+ DestructRange( mpStart, mpEnd );\
+ delete [](char*)mpStart;\
+ }\
+ \
+ mpEnd = atPosition + difference_type( mpEnd - position );\
+ \
+ mpStart = pNewStart;\
+ mpEndOfBuf = pNewStart + newLen;\
+ \
+ return newPos;\
+ }\
+\
+public:\
+\
+ inline vectorClass() : mpStart(0), \
+ mpEnd(0),\
+ mpEndOfBuf(0)\
+ {}\
+\
+ inline vectorClass( const_iterator first, const_iterator last )\
+ : mpStart(0),\
+ mpEnd(0),\
+ mpEndOfBuf(0)\
+ \
+ { while( first != last ) push_back( *first++ ); }\
+\
+ inline vectorClass( size_type n, const value_type& value = value_type() )\
+ : mpStart(0),\
+ mpEnd(0),\
+ mpEndOfBuf(0)\
+ \
+ { for( size_type i = 0; i != n; ++i ) push_back( value ); }\
+\
+ inline const vectorClass& operator=( const vectorClass& other )\
+ {\
+ if (mpStart) \
+ {\
+ DestructRange( begin(), end() );\
+ delete [](char*)mpStart; \
+ }\
+\
+ size_t newLen = difference_type( other.mpEndOfBuf - other.mpStart );\
+\
+ mpStart = (iterator)( new char[newLen*sizeof(value_type)] );\
+\
+ PlacementCopy( other.begin(), other.end(), mpStart );\
+\
+ mpEnd = mpStart + other.size();\
+\
+ mpEndOfBuf = mpStart + newLen;\
+\
+ return *this;\
+ }\
+\
+ inline vectorClass( const vectorClass& other )\
+ : mpStart(0),\
+ mpEnd(0),\
+ mpEndOfBuf(0)\
+ {\
+ this->operator=( other );\
+ }\
+\
+ inline ~vectorClass() \
+ { \
+ if (mpStart) \
+ {\
+ DestructRange( begin(), end() );\
+ delete [](char*)mpStart; \
+ }\
+ }\
+\
+ inline iterator begin() { return mpStart; }\
+\
+ inline const_iterator begin() const { return mpStart; }\
+\
+ inline iterator end() { return mpEnd; }\
+\
+ inline const_iterator end() const { return mpEnd; }\
+\
+ inline size_type size() const { return (size_type)difference_type(mpEnd-mpStart); }\
+\
+ inline size_type max_size() const { return UINT_MAX/sizeof(value_type); }\
+\
+ inline size_type capacity() const \
+ { return difference_type(mpEndOfBuf-mpStart)/sizeof(value_type); }\
+\
+ inline int empty() const { return mpStart == mpEnd; }\
+\
+ inline reference operator[](size_type n) { return *(mpStart+n); }\
+\
+ inline const_reference operator[](size_type n) const { return *(mpStart+n); }\
+\
+ inline reference front() { return (*mpStart); }\
+ \
+ inline const_reference front() const { return (*mpStart); }\
+\
+ inline reference back() { return (*(mpEnd-1)); }\
+\
+ inline const_reference back() const { return (*(mpEnd-1)); }\
+\
+ inline void reserve(size_type n) {}\
+\
+ inline void push_back(const value_type& x)\
+ {\
+ if ( mpEnd != mpEndOfBuf ) \
+ {\
+ new (mpEnd) value_type(x);\
+ ++mpEnd;\
+ }\
+ else\
+ DoInsert( mpEnd, x );\
+ }\
+\
+ inline iterator insert(iterator position, const value_type& x = value_type())\
+ {\
+ if ( position == mpEnd && mpEnd != mpEndOfBuf )\
+ {\
+ new (mpEnd) value_type(x);\
+ ++mpEnd;\
+ return (mpEnd-1);\
+ }\
+ else return DoInsert( position, x );\
+ }\
+\
+ inline void pop_back()\
+ {\
+ DestructRange( mpEnd-1, mpEnd );\
+\
+ --mpEnd;\
+ }\
+\
+ inline void erase(iterator first, iterator last)\
+ {\
+ if ( last == mpEnd )\
+ {\
+ DestructRange( first, last );\
+ mpEnd = first;\
+ return;\
+ }\
+ \
+ CopyObjects( last, last + difference_type( mpEnd - last ), first );\
+ \
+ iterator newEnd = mpEnd - difference_type( last - first );\
+ DestructRange( newEnd, mpEnd );\
+ \
+ mpEnd = newEnd;\
+ }\
+\
+ inline void erase( iterator position )\
+ {\
+ erase( position, position + 1 );\
+ }\
+\
+ inline void sort()\
+ {\
+ if ( size() < 2 ) return;\
+ quick_sort( 0, size()-1 );\
+ }\
+}
+
+/////////////////////////////// shallow-copy container ///////////////////////
+
+#define __DEFINE_STL_VECTOR_SHALLOW( vectorClass, Type ) class vectorClass {\
+\
+public:\
+ typedef Type value_type;\
+ typedef value_type* iterator;\
+ typedef const value_type* const_iterator;\
+ typedef iterator pointer;\
+ typedef const iterator const_pointer;\
+ typedef value_type& reference;\
+ typedef const value_type& const_reference;\
+ typedef size_t size_type;\
+ typedef ptrdiff_t difference_type;\
+\
+ typedef iterator OutputIterator;\
+ typedef const_iterator InputIterator;\
+\
+protected:\
+\
+ inline void PlacementCopy( const_iterator first, const_iterator last, iterator result )\
+ {\
+ memcpy(result, first, int(difference_type(last-first)*sizeof(value_type)) );\
+ }\
+\
+ inline void ConstructObjects( iterator first, iterator last, const value_type& pattern )\
+ {\
+ if ( sizeof(pattern) == 1 )\
+ \
+ memset( first, int(difference_type(last-first)/sizeof(value_type)), \
+ int(*((char*)&pattern)) );\
+ else\
+ while( first != last ) \
+ *first++ = pattern;\
+ }\
+\
+ inline void CopyObjects( iterator first, iterator last, iterator result )\
+ {\
+ memcpy(result, first, int(difference_type(last-first)*sizeof(value_type)) );\
+ }\
+\
+ inline void CopyObjectsBack( iterator first, iterator last, iterator result )\
+ {\
+ memmove(result, first, int(difference_type(last-first)*sizeof(value_type)) );\
+ }\
+\
+public:\
+\
+ class reverse_iterator \
+ {\
+ friend class vectorClass;\
+ friend class const_reverse_iterator;\
+\
+ public:\
+ iterator mpPos;\
+\
+ public:\
+\
+ reverse_iterator() {}\
+\
+ reverse_iterator ( iterator pPos )\
+ {\
+ mpPos = pPos;\
+ }\
+ \
+ int operator==( const reverse_iterator& rhs ) const { return (mpPos == rhs.mpPos); }\
+ int operator!=( const reverse_iterator& rhs ) const { return (mpPos != rhs.mpPos); }\
+\
+ inline reverse_iterator( const reverse_iterator& other )\
+ {\
+ mpPos = other.mpPos;\
+ }\
+\
+ inline const reverse_iterator& operator--() \
+ {\
+ --mpPos;\
+ return *this;\
+ }\
+\
+ inline reverse_iterator operator--(int)\
+ {\
+ reverse_iterator tmp = *this;\
+ --mpPos;\
+ return tmp;\
+ }\
+\
+ inline const reverse_iterator & operator++() \
+ {\
+ ++mpPos;\
+ return *this;\
+ }\
+\
+ inline reverse_iterator operator++(int)\
+ {\
+ reverse_iterator tmp = *this;\
+ ++mpPos;\
+ return tmp;\
+ }\
+\
+ inline const_reference operator*() const { return *mpPos; }\
+ };\
+\
+\
+ class const_reverse_iterator \
+ {\
+ protected:\
+ iterator mpPos;\
+ public:\
+\
+ const_reverse_iterator() {}\
+\
+ const_reverse_iterator( const iterator pPos )\
+ {\
+ mpPos = pPos;\
+ }\
+ \
+ int operator==( const const_reverse_iterator& rhs ) const { return (mpPos == rhs.mpPos); }\
+ int operator!=( const const_reverse_iterator& rhs ) const { return (mpPos != rhs.mpPos); }\
+\
+ inline const_reverse_iterator( const reverse_iterator& other )\
+ {\
+ mpPos = other.mpPos;\
+ }\
+\
+ inline const const_reverse_iterator& operator--() \
+ {\
+ --mpPos;\
+ return *this;\
+ }\
+\
+ inline const_reverse_iterator operator--(int)\
+ {\
+ const_reverse_iterator tmp = *this;\
+ --mpPos;\
+ return tmp;\
+ }\
+\
+ inline const const_reverse_iterator & operator++() \
+ {\
+ ++mpPos;\
+ return *this;\
+ }\
+\
+ inline const_reverse_iterator operator++(int)\
+ {\
+ const_reverse_iterator tmp = *this;\
+ ++mpPos;\
+ return tmp;\
+ }\
+\
+ inline const_reference operator*() const { return *mpPos; }\
+ };\
+\
+protected:\
+ \
+ pointer mpStart;\
+ pointer mpEnd;\
+ pointer mpEndOfBuf;\
+\
+protected:\
+\
+ inline void quick_sort(int low, int hi) \
+ {\
+ }\
+\
+ inline void DestructRange( iterator first, iterator last )\
+ {\
+ }\
+\
+ inline iterator DoInsert(iterator position, const value_type& x)\
+ {\
+ if ( mpEnd < mpEndOfBuf )\
+ {\
+ new (mpEnd) value_type(*(mpEnd-1) );\
+ \
+ CopyObjectsBack( position, mpEnd, position + 1 );\
+ \
+ *position = x;\
+ \
+ ++mpEnd;\
+ \
+ return position;\
+ }\
+ \
+ size_type minBufLen = WXSTL_VECTOR_MIN_BUF_SIZE/sizeof(value_type);\
+ \
+ size_type doubledSize = size()*2;\
+ \
+ size_type newLen = ( doubledSize < minBufLen ) ? minBufLen : doubledSize;\
+ \
+ iterator pNewStart = (iterator)( new char[newLen*sizeof(value_type)] );\
+ \
+ PlacementCopy( mpStart, position, pNewStart );\
+ \
+ iterator atPosition = pNewStart + difference_type( position - mpStart );\
+ \
+ new (atPosition) value_type(x);\
+ \
+ iterator newPos = atPosition;\
+ \
+ ++atPosition;\
+ \
+ if ( mpStart ) \
+ {\
+ PlacementCopy( position, mpEnd, atPosition );\
+ DestructRange( mpStart, mpEnd );\
+ delete [](char*)mpStart;\
+ }\
+ \
+ mpEnd = atPosition + difference_type( mpEnd - position );\
+ \
+ mpStart = pNewStart;\
+ mpEndOfBuf = pNewStart + newLen;\
+ \
+ return newPos;\
+ }\
+\
+public:\
+\
+ inline vectorClass() : mpStart(0), \
+ mpEnd(0),\
+ mpEndOfBuf(0)\
+ {}\
+\
+ inline vectorClass( const_iterator first, const_iterator last )\
+ : mpStart(0),\
+ mpEnd(0),\
+ mpEndOfBuf(0)\
+ \
+ { while( first != last ) push_back( *first++ ); }\
+\
+ inline vectorClass( size_type n, const value_type& value = value_type() )\
+ : mpStart(0),\
+ mpEnd(0),\
+ mpEndOfBuf(0)\
+ \
+ { for( size_type i = 0; i != n; ++i ) push_back( value ); }\
+\
+ inline const vectorClass& operator=( const vectorClass& other )\
+ {\
+ if (mpStart) \
+ {\
+ DestructRange( begin(), end() );\
+ delete [](char*)mpStart; \
+ }\
+\
+ size_t newLen = difference_type( other.mpEndOfBuf - other.mpStart );\
+\
+ mpStart = (iterator)( new char[newLen*sizeof(value_type)] );\
+\
+ PlacementCopy( other.begin(), other.end(), mpStart );\
+\
+ mpEnd = mpStart + other.size();\
+\
+ mpEndOfBuf = mpStart + newLen;\
+\
+ return *this;\
+ }\
+\
+ inline vectorClass( const vectorClass& other )\
+ : mpStart(0),\
+ mpEnd(0),\
+ mpEndOfBuf(0)\
+ {\
+ this->operator=( other );\
+ }\
+\
+ inline ~vectorClass() \
+ { \
+ if (mpStart) \
+ {\
+ DestructRange( begin(), end() );\
+ delete [](char*)mpStart; \
+ }\
+ }\
+\
+ inline iterator begin() { return mpStart; }\
+\
+ inline const_iterator begin() const { return mpStart; }\
+\
+ inline iterator end() { return mpEnd; }\
+\
+ inline const_iterator end() const { return mpEnd; }\
+\
+ inline size_type size() const { return (size_type)difference_type(mpEnd-mpStart); }\
+\
+ inline size_type max_size() const { return UINT_MAX/sizeof(value_type); }\
+\
+ inline size_type capacity() const \
+ { return difference_type(mpEndOfBuf-mpStart)/sizeof(value_type); }\
+\
+ inline int empty() const { return mpStart == mpEnd; }\
+\
+ inline reference operator[](size_type n) { return *(mpStart+n); }\
+\
+ inline const_reference operator[](size_type n) const { return *(mpStart+n); }\
+\
+ inline reference front() { return (*mpStart); }\
+ \
+ inline const_reference front() const { return (*mpStart); }\
+\
+ inline reference back() { return (*(mpEnd-1)); }\
+\
+ inline const_reference back() const { return (*(mpEnd-1)); }\
+\
+ inline void reserve(size_type n) {}\
+\
+ inline void push_back(const value_type& x)\
+ {\
+ if ( mpEnd != mpEndOfBuf ) \
+ {\
+ new (mpEnd) value_type(x);\
+ ++mpEnd;\
+ }\
+ else\
+ DoInsert( mpEnd, x );\
+ }\
+\
+ inline iterator insert(iterator position, const value_type& x = value_type())\
+ {\
+ if ( position == mpEnd && mpEnd != mpEndOfBuf )\
+ {\
+ new (mpEnd) value_type(x);\
+ ++mpEnd;\
+ return (mpEnd-1);\
+ }\
+ else return DoInsert( position, x );\
+ }\
+\
+ inline void pop_back()\
+ {\
+ DestructRange( mpEnd-1, mpEnd );\
+\
+ --mpEnd;\
+ }\
+\
+ inline void erase(iterator first, iterator last)\
+ {\
+ if ( last == mpEnd )\
+ {\
+ DestructRange( first, last );\
+ mpEnd = first;\
+ return;\
+ }\
+ \
+ CopyObjects( last, last + difference_type( mpEnd - last ), first );\
+ \
+ iterator newEnd = mpEnd - difference_type( last - first );\
+ DestructRange( newEnd, mpEnd );\
+ \
+ mpEnd = newEnd;\
+ }\
+\
+ inline void erase( iterator position )\
+ {\
+ erase( position, position + 1 );\
+ }\
+\
+ inline void sort()\
+ {\
+ if ( size() < 2 ) return;\
+ quick_sort( 0, size()-1 );\
+ }\
+}
+
+
+
+// redefine below symbol to change the default allocation unit of vector content buffer
+#define WXSTL_VECTOR_MIN_BUF_SIZE 64
+
+// defines vector class, where objects are copied
+// using "deep-copy" sematics (i.e. by calling their copy constructors)
+
+#define WXSTL_VECTOR(ELEMENT_CLASS) \
+__DEFINE_STL_VECTOR_DEEP(_WXSTL_VECTOR_##ELEMENT_CLASS, ELEMENT_CLASS)
+
+// defines vector class, where objects are copied
+// using "shallow-copy" sematics (i.e. instead of calling
+// their constructors, memcpy() and memmove() are used to copy their raw data)
+
+
+#define WXSTL_VECTOR_SHALLOW_COPY(ELEMENT_CLASS) __DEFINE_STL_VECTOR_SHALLOW(_WXSTL_VECTORSC_##ELEMENT_CLASS, ELEMENT_CLASS)
+
+#endif