objects: hierarchies: listing/comparing objects
objects: hierarchies: listing/comparing objects
What are the best links currently, for listing all the keys in an object/checking if two objects match. That recurse through hierarchies. Thanks.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
-
- Posts: 4309
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: objects: hierarchies: listing/comparing objects
To compare two objects I'd transform objects to buffers and then compare buffers through memcmp.
Re: objects: hierarchies: listing/comparing objects
- @teadrinker: Great link, many thinks.
- Any other simple scripts to just list in text form, all of the keys and values in an object, indented?
- Any other simple scripts to just list in text form, all of the keys and values in an object, indented?
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: objects: hierarchies: listing/comparing objects
- Anyone? I'd be interested in multiple scripts for listing object keys/values, for the following reasons.
- A lot of the more complicated scripts I use involve hierarchies, and I'm wanting to try and streamline all of my hierarchy/recursion/family tree/ancestry scripts to work within one model, and to be as efficient as possible.
- Also, when I recently did my Acc script to retrieve text from all GUI elements, I intended to base it on another script, but because of differences in how things are structured, I had to rewrite the script completely.
- E.g. areas:
registry keys/values
files/folders
Acc GUI elements
treeview controls
JSON
object (array) keys/values
webpage elements
window controls
(ini files)
- A lot of the more complicated scripts I use involve hierarchies, and I'm wanting to try and streamline all of my hierarchy/recursion/family tree/ancestry scripts to work within one model, and to be as efficient as possible.
- Also, when I recently did my Acc script to retrieve text from all GUI elements, I intended to base it on another script, but because of differences in how things are structured, I had to rewrite the script completely.
- E.g. areas:
registry keys/values
files/folders
Acc GUI elements
treeview controls
JSON
object (array) keys/values
webpage elements
window controls
(ini files)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: objects: hierarchies: listing/comparing objects
- Well, I had a go at a function, it seems to be working pretty well.
- Many thanks to GeekDude, for his 'array defined like JSON text' example, that I was lucky enough to come across the other day, which I used as the basis for the example below, used for testing the function. (I removed the OTB style of bracing, added indentation and rearranged everything to be in alphabetical order to match the function's output.)
- I haven't done too many recursive functions before, a bit of a first.
- [EDIT:][examples: define an array JSON-style]
GeekDude's tips and tricks - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=7190
Object declaration syntax - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 37&t=43154
- Many thanks to GeekDude, for his 'array defined like JSON text' example, that I was lucky enough to come across the other day, which I used as the basis for the example below, used for testing the function. (I removed the OTB style of bracing, added indentation and rearranged everything to be in alphabetical order to match the function's output.)
- I haven't done too many recursive functions before, a bit of a first.
Code: Select all
q:: ;object - list keys/values
;object example based on:
;GeekDude's tips and tricks - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=7&t=7190
;note: to make this work in AHK v2
;replace: (LTrim Join
;with: (LTrim Join Q
;http://www.json.org/example.html
oArray :=
(LTrim Join
{
"glossary":
{
"GlossDiv":
{
"GlossList":
{
"GlossEntry":
{
"Abbrev": "ISO 8879:1986",
"Acronym": "SGML",
"GlossDef":
{
"GlossSeeAlso":
[
"GML",
"XML"
],
"para": "A meta-markup language, used to create markup languages such as DocBook."
},
"GlossSee": "markup",
"GlossTerm": "Standard Generalized Markup Language",
"ID": "SGML",
"SortAs": "SGML"
}
},
"title": "S"
},
"title": "example glossary"
}
}
)
MsgBox, % Clipboard := JEE_ObjList(oArray)
oArray := ["a", "b", "c"]
MsgBox, % Clipboard := JEE_ObjList(oArray)
return
JEE_ObjList(oArray, vSep:=" ", vRecurse:=1)
{
if !vRecurse
{
for vKey, vValue in oArray
vOutput .= vKey vSep vValue "`r`n"
return SubStr(vOutput, 1, -2)
}
for vKey, vValue in oArray
{
;note: vRecurse is used to indicate depth, i.e. how many tabs to use
if IsObject(vValue)
vOutput .= JEE_StrRept("`t", vRecurse-1) vKey vSep "OBJECT`r`n" %A_ThisFunc%(vValue, vSep, vRecurse+1) "`r`n"
else
vOutput .= JEE_StrRept("`t", vRecurse-1) vKey vSep vValue "`r`n"
}
return SubStr(vOutput, 1, -2)
}
JEE_StrRept(vText, vNum)
{
if (vNum <= 0)
return
return StrReplace(Format("{:" vNum "}", ""), " ", vText)
;return StrReplace(Format("{:0" vNum "}", 0), 0, vText)
}
GeekDude's tips and tricks - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=7190
Object declaration syntax - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 37&t=43154
Last edited by jeeswg on 22 Jan 2018, 13:04, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: objects: hierarchies: listing/comparing objects
- Many thanks for the links Helgef. I'd probably have to simplify the 3 scripts to get any code that lists the keys/values. More stuff for the to-do list, it's so long now.
- Re. circular references, I asked about them on the other thread, any good threads relating to them? I've come across almost every object issue imaginable while going through links, but not that one curiously. To be honest though, object classes, and bugs, the number is gigantic. A difficult question, but, any key bug issues to be aware of, that I haven't already mentioned, I'm probably not aware of them, so you're welcome to expand my object bug horizons at any point.
- Btw I don't put circular references into my scripts hehe, so how am I supposed to help users who do?
- Re. circular references, I asked about them on the other thread, any good threads relating to them? I've come across almost every object issue imaginable while going through links, but not that one curiously. To be honest though, object classes, and bugs, the number is gigantic. A difficult question, but, any key bug issues to be aware of, that I haven't already mentioned, I'm probably not aware of them, so you're welcome to expand my object bug horizons at any point.
- Btw I don't put circular references into my scripts hehe, so how am I supposed to help users who do?
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: objects: hierarchies: listing/comparing objects
You can specify a max recursion depth. Also, you can look how HotKeyIt does in the link teadrinker (hello ) provided.how am I supposed to help users who do?
Cheers.
Who is online
Users browsing this forum: Google [Bot], JoeWinograd and 165 guests