Click here to Skip to main content
15,886,110 members
Articles / Programming Languages / C++

DynObj - C++ Cross Platform Plugin Objects

Rate me:
Please Sign up or sign in to vote.
4.95/5 (34 votes)
27 Sep 200727 min read 142.3K   3.4K   132  
DynObj is an open source library that provides a C++ application with run-time class loading facilities
#ifndef STRINGBUFFER_H_
#define STRINGBUFFER_H_

#ifndef EA_ASSERT
	#define EA_ASSERT assert
#endif
 
#define EA_IS_CLASS
#include "ExpArr.hpp"
#include "CharBuf.h"

// An array of strings (CharBuf) owned by the object
//class StringBuffer : public ExpArrObj<CharBuf,int,SBAlloc,SBFree> {
class StringBuffer : public ExpArrObj<CharBuf,int> {
public:
	StringBuffer( ){ }
	StringBuffer( const ExpArrObj<CharBuf,int>& other) : ExpArrObj<CharBuf,int>(other) { }
	StringBuffer( const ExpArrObj<CharBuf,int>& other, bool is_move ) : ExpArrObj<CharBuf,int>(other,is_move) { }
	
	StringBuffer& Push( const char *str ){
		ExpArrObj<CharBuf,int>::Push(/*cb*/);
		Top() = str;
		return *this;
	}
	StringBuffer& Push( const char *str, int sl ){
		ExpArrObj<CharBuf,int>::Push(/*cb*/);
		Top().Assign(str,sl);
		return *this;
	}

	StringBuffer& Push( const StringBuffer& other){
		ExpArrObj<CharBuf,int>::Push(other);
		return *this;
	}

	const char *Pop( ){
		// Cannot do ordinary Pop with CharBuf
		if( !Size() ) throw "StringBuffer::Pop, Empty stack";
		static CharBuf st_pop;
		st_pop = Top();
		ExpArr<CharBuf,int>::RemoveIndexUnordered( cur_size-1 );
		return st_pop;
	}

protected:
};

// A shorter version
typedef StringBuffer StrBuf;

// Split and join
StrBuf sbSplit( const char *str, const char *seps );
//StrBuf sbSplit( const char *str, const char **seps );
CharBuf sbJoin( const StrBuf &strs, const char sep=0 );

// Type registration, if typeof.h included before us
#ifdef TYPEOF_H
    #undef TYPE_REG_FILE
    #define TYPE_REG_FILE 102
    template<>
    struct IterTypes<StringBuffer> {
        typedef CharBuf e_type;
        typedef int ix_type;
    };
    TYPE_REG(StringBuffer)
#endif


#endif /*STRINGBUFFER_H_*/


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions