PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: PB PowerCollection  (Read 1598 times)

Richard Kelly

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 318
PB PowerCollection
« on: October 23, 2016, 06:12: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?
Logged

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • Josť Roca Software
Re: PB PowerCollection
« Reply #1 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.

Richard Kelly

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 318
Re: PB PowerCollection
« Reply #2 on: October 23, 2016, 08:00:29 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.
Logged

ganlinlao

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 23
Re: PB PowerCollection
« Reply #3 on: October 24, 2016, 12:08: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.
Logged

Richard Kelly

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 318
Re: PB PowerCollection
« Reply #4 on: January 14, 2017, 01:09:00 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?
Logged

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • Josť Roca Software
Re: PB PowerCollection
« Reply #5 on: January 14, 2017, 02:34: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.
« Last Edit: January 14, 2017, 06:20:35 PM by Josť Roca »
Logged

Richard Kelly

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 318
Re: PB PowerCollection
« Reply #6 on: January 14, 2017, 05:28:15 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
« Last Edit: January 14, 2017, 05:31:40 PM by Richard Kelly »
Logged

Richard Kelly

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 318
Re: PB PowerCollection
« Reply #7 on: January 15, 2017, 01:07: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?
Logged

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • Josť Roca Software
Re: PB PowerCollection
« Reply #8 on: January 15, 2017, 03:27: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.

Richard Kelly

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 318
Re: PB PowerCollection
« Reply #9 on: January 15, 2017, 04:20: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
Logged

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • Josť Roca Software
Re: PB PowerCollection
« Reply #10 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.

Richard Kelly

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 318
Re: PB PowerCollection
« Reply #11 on: January 15, 2017, 06:10:17 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
Logged

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • Josť Roca Software
Re: PB PowerCollection
« Reply #12 on: January 15, 2017, 06:28:06 PM »

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

Richard Kelly

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 318
Re: PB PowerCollection
« Reply #13 on: January 17, 2017, 12:43: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.

Code: [Select]

#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).
« Last Edit: January 17, 2017, 02:29:28 AM by Richard Kelly »
Logged

Richard Kelly

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 318
Re: PB PowerCollection
« Reply #14 on: January 22, 2017, 06:59: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?
Logged
Pages: [1] 2