FreeBasic containers (map , vector , list , queue , stack , hashtable)

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
PeterHu
Posts: 46
Joined: Jul 24, 2022 4:57

Re: FreeBasic containers (map , vector , list , queue , stack , hashtable)

Post by PeterHu »

By the way,try to compile the test programs(two programs) from Makoto WATANABE was successfully,but both printed unrecognized characters in console in my code local(cp935).

Appreciated if let me know how to modify the programs both to print correctly.
VANYA
Posts: 1754
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: FreeBasic containers (map , vector , list , queue , stack , hashtable)

Post by VANYA »

Code: Select all

Dim As TVECTORLONG Ptr pv = New TVECTORLONG(2)  'size = 2
...
pv->insert(2,3) 'size = 3
...
v.push_back(10) 'size = 4
...
I may have misunderstood your question number 3. I thought you were asking about memory allocation. So memory allocation is carried out as needed, and the number of cells always increases with calls insert , push_back

STACK - try like this:

Code: Select all

#include "STACK.bi"
Type WSTRP as Wstring ptr
MStackTemplate(WSTRP)
Dim ps As TSTACKWSTRP
ps.push("字符串1")
ps.push("字符串2")
ps.push("字符串3")
? "Size stack="; ps.size()
? *ps.pop()
? *ps.pop()
? *ps.pop()
? "Size stack="; ps.size()
sleep
PeterHu
Posts: 46
Joined: Jul 24, 2022 4:57

Re: FreeBasic containers (map , vector , list , queue , stack , hashtable)

Post by PeterHu »

Code: Select all

Dim As TVECTORLONG Ptr pv = New TVECTORLONG(2)  'size = 2
...
pv->insert(2,3) 'size = 3
...
v.push_back(10) 'size = 4
...
I may have misunderstood your question number 3. I thought you were asking about memory allocation. So memory allocation is carried out as needed, and the number of cells always increases with calls insert , push_back
Yes,that's my question.Now I noticed the "out of range" message printed by the console indicates testvector(),not teststack() which I oversaw yesterday.

STACK - try like this:

Code: Select all

#include "STACK.bi"
Type WSTRP as Wstring ptr
MStackTemplate(WSTRP)
Dim ps As TSTACKWSTRP
ps.push("字符串1")
ps.push("字符串2")
ps.push("字符串3")
? "Size stack="; ps.size()
? *ps.pop()
? *ps.pop()
? *ps.pop()
? "Size stack="; ps.size()
sleep
The output is as below.

Code: Select all


Size stack= 3
?????????3
?????????2
?????????1
Size stack= 0


shell("chcp 65001") deosn't help neither.Just curious how come your previous small test program works very well (without shell("cp 65001") on top of the source code) but the latter on doesn't.

Code: Select all

sub adds(psz as zstring ptr)
	? Len(*psz)
	? *psz
End Sub

dim as string s 
s = "字符串1"
? Len(s)
? s
adds(strptr(s))
sleep
May I ask what is the real type of ps,ptr to any pointer(void**) or?I noticed when push(),we use ps,but when pop(),we use *ps,it is not same calling behavior.
PeterHu
Posts: 46
Joined: Jul 24, 2022 4:57

Re: FreeBasic containers (map , vector , list , queue , stack , hashtable)

Post by PeterHu »

Update:

The original code (bare string version) works well when the source file is in ansi format,not in UTF8;
The wstring ptr vesion can show asian character in the console but it seems the words are overlapped when source file is in ansi format.Changing to zstring ptr works well,still,in ansi format,not utf8.

ANSI,string version---OK

Code: Select all

#include "STACK.bi"
Type WSTRP as string
MStackTemplate(WSTRP)
Dim ps As TSTACKWSTRP
ps.push("字符串1")
ps.push("字符串2")
ps.push("字符串3")
? "Size stack="; ps.size()
? ps.pop()
? ps.pop()
? ps.pop()
? "Size stack="; ps.size()
sleep
ANSI,zstring ptr version---OK

Code: Select all

#include "STACK.bi"
Type WSTRP as zstring ptr
MStackTemplate(WSTRP)
Dim ps As TSTACKWSTRP
ps.push("字符串1")
ps.push("字符串2")
ps.push("字符串3")
? "Size stack="; ps.size()
? *ps.pop()
? *ps.pop()
? *ps.pop()
? "Size stack="; ps.size()
sleep
We'd better to find a solution for UTF8 or universal way since the majority of the source code (especially in an IDE) is UTF8.Using CodeBlocks with MinGW in C/C++ I encountered the similiar issue,providing an compiler option to the compiler helps.But I don't know how to achieve the same result in FB.

Code: Select all

-finput-charset=UTF-8
-fexec-charset=GBK
Appreciated for the great container library and for the help.
VANYA
Posts: 1754
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: FreeBasic containers (map , vector , list , queue , stack , hashtable)

Post by VANYA »

Unfortunately with encodings I can't help you. My console can't output Chinese characters. But in any case, this is a problem of encodings, not of the Containers library. A simple example (can save as UTF-16le or UTF-8 BOM ):

Code: Select all

#define unicode
#include "windows.bi"
#include "STACK.bi"
Type WSTRP as Wstring ptr
MStackTemplate(WSTRP)
Dim ps As TSTACKWSTRP
ps.push("字符串1")
messagebox(0,*ps.pop(),"",0)
D.J.Peters
Posts: 8575
Joined: May 28, 2005 3:28
Contact:

Re: FreeBasic containers (map , vector , list , queue , stack , hashtable)

Post by D.J.Peters »

Only as Info with FBTrueType you can print wstring in any language with FreeBASIC also.

Joshy
PeterHu
Posts: 46
Joined: Jul 24, 2022 4:57

Re: FreeBasic containers (map , vector , list , queue , stack , hashtable)

Post by PeterHu »

D.J.Peters wrote: Sep 29, 2022 10:06 Only as Info with FBTrueType you can print wstring in any language with FreeBASIC also.

Joshy
Thank you,will get a copy of this library and start to learn.
Post Reply