PlanetSquires Forums

Support Forums => José Roca Software => Topic started by: Richard Kelly on October 23, 2016, 06:42:22 PM

Title: PB PowerCollection
Post by: Richard Kelly on October 23, 2016, 06:42:22 PM
I'm looking at creating a drop-in replacement for the PB PowerCollection/Stack objects using Jose's objects. Is the SafeArrary with variant types the best way to go?
Title: Re: PB PowerCollection
Post by: José Roca on October 23, 2016, 06:57:33 PM
For the collection, the best way is the Dictionary object. Earlier versions of my framework included the file CDicObj.inc.
Title: Re: PB PowerCollection
Post by: Richard Kelly on October 23, 2016, 08:30:29 PM
Quote from: Jose Roca on October 23, 2016, 06:57:33 PM
For the collection, the best way is the Dictionary object. Earlier versions of my framework included the file CDicObj.inc.

Nice...I found the include file and will put a wrapper that maps to the PB equivalent.
Title: Re: PB PowerCollection
Post by: ganlinlao on October 24, 2016, 12:38:53 AM
Maybe we need a freebasic JSON parsing library, the JSON string or file parsing into collection. JSON files can be used as a program configuration or other kinds of occasions to use json.
Title: Re: PB PowerCollection
Post by: Richard Kelly on January 14, 2017, 01:39:00 PM
Quote from: Jose Roca on October 23, 2016, 06:57:33 PM
For the collection, the best way is the Dictionary object. Earlier versions of my framework included the file CDicObj.inc.

RC 26 has CWstrDic.inc. Is that the way to go with the current cWindows status?
Title: Re: PB PowerCollection
Post by: José Roca on January 14, 2017, 03:04:54 PM
CWstrDic is a collection, but only supports unicode strings, not variants. I was not fully satisfied with the implementation of the BSTRings and VARIANTs classes and, therefore, I stopped using them.
Title: Re: PB PowerCollection
Post by: Richard Kelly on January 14, 2017, 05:58:15 PM
Quote from: Jose Roca on January 14, 2017, 03:04:54 PM
CWstrDic is a collection, but only supports unicode strings, not variants. I was not fully satisfed with the implementation of the BSTRings and VARIANTs classes and, therefore, I stopped using them.

Thanks...more thinking to do on a FB implementation of ILinkListCollection...maybe a safearray....or B24 encode everything for CWstrDic...

Rick
Title: Re: PB PowerCollection
Post by: Richard Kelly on January 15, 2017, 01:37:18 PM
Thought I'd float this by my more learned colleagues.

Let's wrap Jose's CWstrDic object with a class that takes a unsigned ubyte pointer, length, and maybe type. B24 encode that (non string types) and use the resulting string as input. It would seem that anything that you can get a pointer to with a fixed size could then be stored in CWstrDic. That would be the PB PowerCollection. Wrapping that one could also emulate the other collections such as LinkListCollection, QueueCollection, and, StackCollection.

Thoughts?
Title: Re: PB PowerCollection
Post by: José Roca on January 15, 2017, 03:57:51 PM
Sorry, but I don't follow you. CWstrDic has been designed as an associative array for CWSTRings. Internally, they are stored as VT_BSTR variants and the wrapper methods do the conversions. For linked lists, I think that Paul wrote a class some time ago.
Title: Re: PB PowerCollection
Post by: Richard Kelly on January 15, 2017, 04:50:02 PM
I'm probably not following the examples properly.

Instead of:

pDic.Add "a", "Athens"

I wanted to do:

DIM nAny as Long

pDic.Add "a", nAny

or even a UDT...and get back what the associated value in the same type as it was originally.

Rick
Title: Re: PB PowerCollection
Post by: José Roca on January 15, 2017, 05:45:44 PM
You can't do that with CWstrDic, that is only for unicode strings. A way to store any kind of data, although not in the way you want to, is to use variants, but I still don't have a satisfactory implementation of a variant class.
Title: Re: PB PowerCollection
Post by: Richard Kelly on January 15, 2017, 06:40:17 PM
Quote from: Jose Roca on January 15, 2017, 05:45:44 PM
You can't do that with CWstrDic, that is only for unicode strings. A way to store any kind of data, although not in the way you want to, is to use variants, but I still don't have a satisfactory implementation of a variant class.

This was my understanding of your work. I thought a way around it all without using variants was to take a byte ptr and length and B24 encode it to a string that was passed to CWstrDic class and reverse it on the way out.

Rick
Title: Re: PB PowerCollection
Post by: José Roca on January 15, 2017, 06:58:06 PM
Well, you can store unicode strings. What you do with its content is up to you.
Title: Re: PB PowerCollection
Post by: Richard Kelly on January 17, 2017, 01:13:55 AM
I'll give it a shot. I know that the function below is the heart of it all...take something and B64 encode it. B64 encoding only gets used on non string types.



#Pragma Once

#Include "win/wincrypt.bi"
#IncLib "Crypt32"

Function cmBin2B64(ByVal pbBinary as Const UByte Ptr, _
                               ByVal cbBinary as DWORD) as String

Dim iB64Size      as DWORD
Dim sB64          as String

    If cbBinary > 0 Then

' Get encoded string size

       CryptBinaryToStringA(pbBinary, _
                           cbBinary, _
                           CRYPT_STRING_BASE64 + CRYPT_STRING_NOCRLF, _
                           Null, _
                           VarPtr(iB64Size))


       sB64 = Space$(iB64Size)

       CryptBinaryToStringA(pbBinary, _
                           cbBinary, _
                           CRYPT_STRING_BASE64 + CRYPT_STRING_NOCRLF, _
                           StrPtr(sB64), _
                           VarPtr(iB64Size))

       Function = Left$(sB64,iB64Size)
       
    Else
   
       Function = ""

    End If

End Function


I think that CWsrDic will work for PB PowerCollection directly, and, with some work PB LinkList, Queue, and Stack classes (Maybe using WStrArray).
Title: Re: PB PowerCollection
Post by: Richard Kelly on January 22, 2017, 07:29:48 PM
Jose:

If I retrieve the keys and items separately using pDic.Keys and pDic.Items, is Index 1 in the Items array always associated with index 1 in the Keys array?
Title: Re: PB PowerCollection
Post by: José Roca on January 22, 2017, 09:57:11 PM
I don't know how the Dictionary object works internally. The proper way to get an item is to use pDic.Item(key).
Title: Re: PB PowerCollection
Post by: Richard Kelly on January 23, 2017, 04:11:20 AM
Quote from: Jose Roca on January 22, 2017, 09:57:11 PM
I don't know how the Dictionary object works internally. The proper way to get an item is to use pDic.Item(key).

The wrapper I'm working on not only wraps your class, but includes, as best as I can design, the PB PowerCollection methods, and, one of the PB methods is Sort. I can retrieve all the keys, sort them either ascending or descending, retrieve the items, RemoveAll and Add them all back in. I'll use the crt.bi include and qsort.

Rick