How can I get the name of a node? - yaml-cpp

Is there a way to get the name of a node? For example:
Fruits:
- apple
- orange
- pear
and in C++:
YAML::Node fruit = parser["Fruits"];
cout << fruit.name() << endl; // should print "Fruits"
is there something like YAML::Node::name()? I don't see anything in Node.h that fits the bill.
If there isn't, any suggestions on a simple way to modify the code to record this information?
Thanks!

What you're really looking for is the key associated with a value in a map. You're right, there's no link back from a value to its key, but you can store one, when you're navigating the node in the first place.
If all of your keys are string keys, then whenever you pass a value to some function, just pass along the string key as well:
// Instead of:
doSomething(node[key]);
// Call:
doSomething(key, node[key]);

Fruits:
- apple
- orange
- pear
This is one key-value-pair
"Fruits" is the key
" -apple
-orange
-pear " is the value
YAML::Node fruit = parser["Fruits"];
This command use one key to query the value
So the node "fruit" just keep information about value.

Related

How to use input string, to call variable name in c++

so I just have what seems like a rudimentary problem.
But for some reason I can't wrap my mind around it.
So given the code:
int Red = 1;
int Blue = 2;
int Green = 3;
main (){
cout << "Enter your keyword";
cin >> str1;
If the user inputs the word Red, i want it to return the value of the variable "Red", without using an if statement for every variable (I have 200+ variables).
To be more specific:
If the user inputs Red, I want my program to read the first item in my array. To do that I need red to represent a number value.
Thanks in advance for any help.
Updated: Question misunderstood.
You cannot ref to a variable based on a string value.
But you can setup a list of structure who contain a combination of key and value. You should look at map

objective c group array

I have array like this:
{
toNumber = +79995840405;
type = 9;
}
{
toNumber = +79995840405;
type = 65;
}
{
toNumber = +79995840405;
type = 9;
}
{
toNumber = +79995840405;
type = 65;
}
How can I group items by toNumber & type? thanks
You have provided little detail, which makes it hard for people to help you; and haven't shown what you have tried yourself and explained where you got stuck, which is the SO approach - people here will help you, not do the work for you.
The above is why you are getting close votes.
That said let's see if we can point you in the right direction, but understand this is based on guesswork about what you have and your problem.
So it sounds like you have an array (NSArray) of dictionaries (NSDictionary) and wish to produce a dictionary of arrays. A straightforward iteration can be used for that:
Create an empty result dictionary (NSMutableDictionary)
Iterate over your array looking at each element (foreach)
Using the type value of your element as the key value of your result dictionary:
3.1. If there is no entry in your result dictionary for the key create a new array (NSMutableArray), add the element's toNumber value to it, and add the array to your result dictionary.
3.2 Otherwise simply add to toNumber value to the existing array at the key entry of your result dictionary.
That's it, each bullet is a line or two of code.
If you get stuck as a new question, providing details, showing your code, and explaining what you problem is. Someone will undoubtedly help you from there.
HTH

How to use Get command in Monkey talk?

Does anybody know how to use the Get command in monkey talk?
In monkey talk guide only the command is written but no syntax is present.
Here is an example for you,
var x = app.label("label1").get("x","value")
Above line will get the value of label1 and store it in variable x. You can change the second parameter "value" to ".text" or ".size" depending on your needs
since the question is not marked Answered and For the future reference i am answering this.
‘GET’ ACTION RETRIEVES COMPONENT PROPERTY VALUES
Syntax:
ComponenType MonkeyId Get varName propName
Works like an assignment statement (varName= propName)
The default property is “value”
// Get label value currently displayed
Label lastname Get name
// Enter name into input field
Input query EnterText ${name}
// Get the first table item
Table countries Get country items1
// Enter into input field
Input * EnterText ${country}
you can refer this document here, thanqs
I will try to explain using example. Suppose there is a ListView(Table) and you want to scroll till its last item.
//Define a variable
Vars * Define row
//Store size of list in variable row using Get. Check use of "Get" here
Table * Get row size %thinktime=20000
//Now stored variable can be used as per need. here I am using for scrolling
Table * ScrollToRow ${row} %thinktime=2000
Hope it helps you !!

How to view, find and remove key value pairs in CFMutable Dictionary

How do i find and remove the key value pairs of a particular key using CFMutableDictionaryRef.
I have added a value using CFMutableDictionary but i need to know how to search ,view and delete a keyvalue pair.
The value i have created is a structure pointer and key is an integer value.
Beata,
The CFMutableDictionaryRef documentation shown Here will guide you.
In the order of your question:
For finding an element, see CFDictionaryGetValue
For removing an element, see CFDictionaryRemoveValue
Note that the CFDictionary types are a 'toll-free-bridge' with NSDictionary.
Frank

In Rebol how to get the Parent in an Object Path?

Is there a function to get the parent of an object for example
parent-of system/console/history
would give
system/console
It seems that you don't realise that a path! value is a type of series! value:
>> path: 'system/console/history
== system/console/history
>> type? path
== path!
>> series? path
== true
So just remove the last value in the series:
>> path: head remove back tail path
== system/console
Peter is right if the history object has just one parent. But it may have others:
my-block: copy []
append my-block system/console/history
my-object: make object! [history: system/console/history]
history is now has three legitimate parents:
system/console
my-block
my-object/history
Which you consider to the the real parent is really up to you. There is no easy way that I know of to find all the contexts an object (or block) is part of.