fb vector equivalent?

General FreeBASIC programming questions.
Post Reply
Merick
Posts: 1038
Joined: May 28, 2007 1:52

fb vector equivalent?

Post by Merick »

In some c++ source files, I've seen this include statement:

#include <vector>

Is there and FB equivalent for this?
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

No, but the FreeBASIC Extended Library enjoys implementing things like this. Vectors are really cool, but they're use templates, which FB doesn't have. You can fake this kinda thing with some Macro Hackage - Vectors are indeed beautiful.
Merick
Posts: 1038
Joined: May 28, 2007 1:52

Post by Merick »

What exactly are these vectors?
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

They're a really cool type of arrays, basically :D

http://en.wikipedia.org/wiki/Vector_%28STL%29
sir_mud
Posts: 1401
Joined: Jul 29, 2006 3:00
Location: US
Contact:

Post by sir_mud »

We have an Array implementation that is very similiar to c++ vectors in ext. It works with all built-in numerical types (maybe strings too, haven't checked) and it should easily work with a UDT also. Check the thread in Projects or see: http://fb-extended-lib.googlecode.com for more details.
Merick
Posts: 1038
Joined: May 28, 2007 1:52

Post by Merick »

Would that work for the vector stuff in this:

http://www.mediafire.com/?ddmmdgx27vd
sir_mud
Posts: 1401
Joined: Jul 29, 2006 3:00
Location: US
Contact:

Post by sir_mud »

We use more BASIC friendly terminology so a STL::Vector is ext.Array, we do have a set of Math vectors ext.math.vector2/3/4d and also an OpenGL compatible matrix class. Here: http://fb-extended-lib.googlecode.com/s ... rotate.bas is one of the examples Dr_D wrote to demonstrate using them.
Merick
Posts: 1038
Joined: May 28, 2007 1:52

Post by Merick »

I'll take a look at that and hopefully it will help me out.

*edit*

I've looked through the document page and the thread, but I can't find any explanation of how to use ext.Array
sir_mud
Posts: 1401
Joined: Jul 29, 2006 3:00
Location: US
Contact:

Post by sir_mud »

yea, sorry, the online docs are a bit old, i'm updating them now, the downloadable docs are the newest.

*edit*
Newest documentation is now online, you want Containers/Array.bi
Merick
Posts: 1038
Joined: May 28, 2007 1:52

Post by Merick »

Could you post an example? The page for array.bi lists all the functions for it, but I just can't figure out how you're supposed to create the array in the first place.
porfirio
Posts: 154
Joined: Mar 17, 2006 11:54
Location: Portugal

Post by porfirio »

In Java we have List
And all it subclasses like ArrayList
And others....

That would be a good addiction to FreeBasic
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

Java also has Vector :P
Mindless
Posts: 110
Joined: Jun 25, 2005 14:50
Location: USA

Post by Mindless »

here's as close as I've come to figuring out how these work

Code: Select all

#include once "ext/containers/array.bi"

var foo = FBEXT_ARRAY(integer)()

foo.PushBack(&hdeadbeef)
foo.PushBack(&hcafebabe)

? hex(*foo.Front())
? hex(*foo.Back())
Merick
Posts: 1038
Joined: May 28, 2007 1:52

Post by Merick »

for standard internal types that works, but not for udt's:

Code: Select all

#include once "ext/containers/array.bi"

type test
	a as integer
	b as string
end type

var t =  FBEXT_ARRAY(test)()

Code: Select all

FbTemp.bas(8) error 8: Undefined symbol, Arraytest in 'var t =  FBEXT_ARRAY(test)()'
FbTemp.bas(8) warning 12(0): Implicit variable allocation, Arraytest
Post Reply