• Welcome to PlanetSquires Forums.
 

PB PowerCollection

Started by Richard Kelly, October 23, 2016, 06:12:22 PM

Previous topic - Next topic

Richard Kelly

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?

José Roca

For the collection, the best way is the Dictionary object. Earlier versions of my framework included the file CDicObj.inc.

Richard Kelly

Quote from: Jose Roca on October 23, 2016, 06:27: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.

ganlinlao

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.

Richard Kelly

Quote from: Jose Roca on October 23, 2016, 06:27: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?

José Roca

#5
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.

Richard Kelly

#6
Quote from: Jose Roca on January 14, 2017, 02:34: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

Richard Kelly

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?

José Roca

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.

Richard Kelly

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

José Roca

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.

Richard Kelly

Quote from: Jose Roca on January 15, 2017, 05:15: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

José Roca

Well, you can store unicode strings. What you do with its content is up to you.

Richard Kelly

#13
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).

Richard Kelly

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?