I have a strange need.
I want to find the structure name passed to the function "dpi_config_lcd_manager(struct omap_dss_device *)" defined at "http://lxr.free-electrons.com/source/drivers/video/omap2/dss/dpi.c?v=3.8".
I thought of doing in the following way.
1. Get the address of the structure.
A) we can get the structure address within the function.
2. Get the structure name from the address.
doubht) Is it possible to get the structure name from the structure address. I think this structure is defined as static structure, so it will store in the bss section.
Thanks in advance.
I guess there should be some other design option for you instead of using the structure variable name in the code. Because, once after compilation it becomes just an address. You might want to use a kind of map or key-pair data structure to get the key string mapping to the pointer. Worst case, simply you can have a char array inside the structure.
Related
I would like to access a variables by its literal name in string form.
So far I've found two ways:
https://stackoverflow.com/a/51090177/2330482 which doesn't let me write to the variables
Doing https://stackoverflow.com/a/44461705/2330482 which crashes the app if the key is not found (I don't want to run that risk). If there is a way to check if the key exists first, that would likely resolve my problem. I could combine this with Mirror in the first linked answer to get all keys (and therefore know they exist) before accessing them via .value(forKey) but this seems a bit unsafe. Is there another way to catch the crash if there is no key, or another way for NSObject to first make sure the key doesn't exist?
The reason why I want to do this is to make a struct fallback to default values if an incomplete JSON is fed. If I'm able to safely access variables by their name I could probably solve this problem without having to write Codable implementations for each variable in the struct.
One person in Stackover Flow gave me a hint about creating a learning page.
Using the list, save the necessary data, id and favorite variables, and call them to the index number.
I was creating a class to implement it.
However, I realized that variables could not be stored in the list...
Is there a way to save it?
And I don't make a separate class, but I'm going to make a list in the file with the following code.
But before, I heard that using global variables makes me stutter and it's bad for memory.
Shall we use "const"?
If not, wouldn't it be a problem how to make the class?
Of course, favorite variables cannot be used because they change from time to time.
const List<Function> fav_1 = [favoriteButton_0_01_01,.....];
Is it okay to use only the const list as a global variable instead of making a class?
Can I put variables in the list? Then, how?
You can only put items with a matching type in the list.
if you define a list like "List" than only functions can be saved there.
if you define a list like "List" than only Integers can be saved there.
using const as a modifier will result in an unmodifiable list and so you won't be able to put anything in there.
Suppose I want a function that takes a variable as input and returns 1 if the variable is ppform and 0 if it isn't. Since ppforms in MATLAB are structures, but not all structures are ppform, I see no way to use isa to do this.
I could of course write a function to check if a given variable is a structure, has the right fields, and that the fields themselves are of the right form, but I'm just wondering if MATLAB has a built in function that can do this? Google and the MATHWORKS website have not helped me here.
Given your variable pp, you can check that it's a structure and has the appropriate fields:
isstruct(pp) & isequal(fields(pp), {'form' 'breaks' 'coefs' 'pieces' 'order' 'dim'}.')
Note that this doesn't check that the fields' contents are of the appropriate type (for example, the field form should contain a string) or have the permitted values.
I need to analyse several sets of data which are associated with different parameter sets (one single set of parameters for each set of data). I'm currently struggling to find a good way to store these parameters such that they are readily available when analysing a specific dataset.
The first thing I tried was saving them in a script file parameters.m in the data directory and load them with run([path_to_data,'/parameters.m']). I understand, however, that this is not good coding practice and it also gave me scoping problems (I think), as changes in parameters.m were not always reflected in my workspace variables. (Workspace variables were only changed after Clear all and rerunning the code.)
A clean solution would be to define a function parameters() in each data directory, but then again I would need to add the directory to the search path. Also I fear I might run into namespace collisions if I don't give the functions unique names. Using unique names is not very practical on the other hand...
Is there a better solution?
So define a struct or cell array called parameters and store it in the data directory it belongs in. I don't know what your parameters look like, but ours might look like this:
parameters.relative_tolerance = 10e-6
parameters.absolute_tolerance = 10e-6
parameters.solver_type = 3
.
.
.
and I can write
save('parameter_file', 'parameters')
or even
save('parameter_file', '-struct', 'parameters', *fieldnames*)
The online help reveals how to use -struct to store fields from a structure as individual variables should that be useful to you.
Once you've got the parameters saved you can load them with the load command.
To sum up: create a variable (most likely a struct or cell array) called parameters and save it in the data directory for the experiment it refers to. You then have all the usual Matlab tools for reading, writing and investigating the parameters as well as the data. I don't see a need for a solution more complicated than this (though your parameters may be complicated themselves).
In xcode you can use po object to see a textual representation of a given object. Is it possible to convert from this textual representation to a real objective c object?
Thanks
I suppose you could parse out the address, assign it to a pointer, and retrieve the object from memory that way, but that IS A HORRIBLY BAD IDEA AND YOU SHOULD NEVER DO THAT.
Real question: what are you trying to do?
I have a project that may inspire you, its on GitHub and its called NDJSON. Basically it uses runtime introspection to get properties an object has and set those properties using a json key of the same value. You could do something like that but get the property values instead of set. To help in situation where the type can not be determined like the type of objects to go in a collection or to map a json key to differently named property I have defined an informal protocol that has some methods that return dictionary mapping json key to property names or class to use for property name, there are also method to return a list of json keys to ignore or alternatively the only keys to accept. If you look at my code on git hub there is a class called NDJSONDeserializer which contains this logic. There is a function called getTypeNameFromPropertyAttributes() which parses out the string result of Apples runtime method property_getAttributes() which you will want to look at.
No, the representation you see from po <instance> is the result of -[<instance> debugDescription], which by default returns -[<instance> description], as described in http://developer.apple.com/mac/library/technotes/tn2004/tn2124.html.
Unless the instance you're dealing with just happens to provide a description which is a serialized form of itself, you're SOL. Most objects don't.
The real question, as Dave points out is, what are you trying to do? po only works in the gdb console, so I assume this is a debugging issue. In that case, do you know that the gdb console supports sending messages to instances? So you can do:
po [<myInstance> methodReturningAnOtherObject]
or
po [<myInstance> valueForKeyPath:#"some.long.key.path"]
to follow the object graph from within the debugger console.