Convert Blitzcode to C++?

Blitz3D Forums/Blitz3D Beginners Area/Convert Blitzcode to C++?

fdfederation(Posted 2016) [#1]
I have a Blitz project that I'd like to transfer to C++ with Irrlicht. Is there a chart showing C++ equivalent algorithms to Blitz code (at least the non-graphics part)? For example, the type declaration:

Type Typename
Field stuff1
Field stuff2
End Type

seems to be similar to the C++ equivalent:

class Typename
{
public:
Typename(); //Constructor for initializing stuff1 and stuff2 in new instances of Typename
int stuff1; //Assumed int
int stuff2; //Assumed int
};
std::list< Typename > listOfTypenameInstances;

So, then, the Blitz code:

pType.Typename = New Typename

seems to be equivalent to the C++ equivalent:

Typename tempVar;
listOfTypenameInstances.push_back( tempVar );
Typename *pType = &listOfTypenameInstances.back();

And then, the Blitz code:

pType\stuff1 = 101

seems to be equivalent to the C++ code:

pType->stuff1 = 101;


Kryzon(Posted 2016) [#2]
Here's a suggestion: instead of making the list a global, why not make it a private static member of that class. If other classes need access to that list, use a public, static accessor function for that:

In the .h header:
#include blablabla

class Typename
{
public:
	explicit Typename( int stuff1, int stuff2 );

	inline static std::list< Typename >* getTypenameList()
	{ return s_typenameList; }

private:
	static std::list< Typename >* s_typenameList;
	int m_stuff1;
	int m_stuff2;
};
In the .cpp implementation:
std::list< Typename >* Typename::s_typenameList = new std::list< Typename >

Typename::Typename( int stuff1, int stuff2 )
	: m_stuff1( stuff1 )
	, m_stuff2( stuff2 )
{
	s_typenameList.push_back( this ); // Add itself into its list, automatically.
}

// It then becomes...

Typename* me = new Typename();
std::list< Typename >* list = me->getTypenameList();

// list->front() == *me;
It's been a while since I last played with C++ so there might be a syntax error somewhere.


fdfederation(Posted 2016) [#3]
I like it.


Kryzon(Posted 2016) [#4]
Unless it's a requirement to use C++, doing the same Blitz3D-like behaviour in BlitzMax would require much less code.

Type Typename

	Method New()
	
		typenameList.AddLast( Self )

	End Method

	Function getList:TList() 'Considered a "static" function.
		
		Return typenameList

	End Function

	Global typenameList:TList = New TList 'Considered a "static" member.

End Type

Local obj1:Typename = New Typename
Local obj2:Typename = New Typename

Print( Typename.getList().Count() ) 'Prints '2'.



fdfederation(Posted 2016) [#5]
C++ is a requirement.