Automatically show properties of C++ objects in Xcode debugger - c++

The Xcode debug area can sometimes show a summary of the most important variables inside of an object that's in the list, without the need to expand the object to see it's individual members.
Is there a way for me to teach the debugger about my own C++ objects to do the same? Let's say I have a simple class with a single member variable:
class Foo
{
int bar;
};
And the debug area should show something like the following:
aVariableOfTypeFoo = (Foo) bar=123
I know that some C++ objects are able to do this (for example std::vector shows it's size), but I wasn't able to figure out if this is somehow configurable, or if it's built-in in the debugger/Xcode itself.
I'm using Xcode 5.0.1
Thanks

You can change the summary description for a given type selecting Edit Summary Format... by right clicking on a variable of that type.
The format in your case is pretty simple and will look like this: bar = {$VAR.bar}
For more information about formats check the "Using Data Formatters" section in the Xcode User Guide (pages 42 & 43).

Related

How to modify and update Visual Studio Object

I want to delete all the object that is not used now.
I used Visual Studio 2019.
When I search Object Browser, It gets to me some strange struct or class that I modified of name.
For example, first I define a structure as
typedef struct stOutput
{
double dDirtyPrice_CumInt;
double dDM;
//...
double dYield;
} stOutput
Later I changed this definition to
typedef struct stOutput_New
{
double dAI;
//...
long lObservStartDate;
} stOutput_New
However, the object browser shows to me just
stOutput.
There is no stOutput_New.
Also I put my cursor on 'stOutput_New' and push 'F12' then it locates my view some strange area.
There are even no 'stOutput_New'
Now, below picture is describing my real situation
This is 'Class View'
Actually I just use One stOutput, but there are so many stOutput that has same file path
Also below picture is my 'Object Browser'
As you can see the two stOutput have different member variables.
And I changed the name from stOutput to stOutput_new the latter.
But it seems my object browser didn't reflect it.
I tried
Project Unload and Reload it
Organize the code of Solution and Project
Re-Build Solution.
But everything doesn't work.
Please help me
In vs2019, I defined the structure exactly like yours according to your description, and then changed the structure according to your description. My object browser did not have the problem you described. If you are sure that your code does not repeat the definition of structure and other problems, I suggest you reinstall or repair VS.
enter image description here

Initialization of wxColourDataBase while creating a new wxColourPickerCtrl

This is my first question ever posted, so please let me know if there is anything that needs changes in my post :)
I am currently working on a dialog that is supposed to let the user change the background-color for some signal plotting. The "wxColourPickerCtrl" seems to do exactly what I need. Since there are multiple plots/pictures to be manipulated, the ColourPickerCtrls are initialized in a loop with the chosen background color as the default value:
for (const auto& [signalName, signalProperties] : properties)
{
wxColourPickerCtrl* selectBackgroundColor = new wxColourPickerCtrl(this, signalProperties.first, signalProperties.second.backgroundColor, wxDefaultPosition, wxDefaultSize);
}
"this" is an object of type SignalPropertiesDialog, which is directly inherited from wxDialog.
I have left out all the necessary sizer stuff, since it's not relevant for the problem (at least imo). "properties" is structured as follows:
std::map<std::string, std::pair<int, GraphPicture::Properties>> signalProperties_;
where GraphPicture::Properties contains the properties I want to manipulate:
struct Properties
{
wxColour backgroundColor{ *wxWHITE };
wxColour lineColor{ *wxBLACK };
int linewidth_px{ 1 };
bool isShown{ true };
};
The application successfully builds but immediately crashes on startup while generating those color picker objects.
wxIshiko has uploaded multiple tutorials and code snippets as examples for various wxWidgets controls, including the wxColourPickerCtrl. So I downloaded the sample code and tried to run it. Surprisingly, it worked.
While running through the code step by step I noticed the following difference:
The wxColourPickerCtrl is based on wxPickerBase. The wxPickerBase is created by calling the constructor of wxColourPickerCtrl (what I am actually doing in my code). During the construction of the wxPickerBase, the desired color is called by the name wxColourDataBase::FindName(const wxColour& color) const where the wxColourBase itself is instantiated. This is where the difference is:
When running the code snippet by wxIshiko, wxColourDataBase is instantiated correctly including the member m_map of type wxStringToColourHashMap* which is set to be NULL.
When running the code written by myself, wxColourDataBase is not correctly instantiated, and thus the member m_map is not set to be NULL, which leads to to the crash.
I have the feeling that there is nothing wrong with the way I set up the wxColourPickerCtrls. I somehow think there is a difference in the solution properties of the projects. I checked those but was not able to find any relevant differences.
I would really appreciate any hint or help since I am completely stuck on that problem.
Thank you very much in advance and have a good one,
Alex
EDIT:
I attached a screeny of the call stack.
Call stack
When does this code run exactly? If it is done after the library initialization (which would be the case, for example, for any code executed in your overridden wxApp::OnInit()), then wxTheColourDatabase really should be already initialized and what you observe should be impossible, i.e. if it happens it means that something is seriously wrong with your library build (e.g. it doesn't match the compiler options used when compiling your applications).
As always with such "impossible" bugs, starting with a known working code and doing bisection by copying parts of your code into the working version until it stops working will usually end up by finding a bug in your code.

C++ - Using a variable without knowing what it is called

I have a program that uses plug-ins. As I'm in development, these plug-ins are currently just .h and .cpp files that I add or remove from my project before re-compiling, but eventually they will be libraries.
Each plug-in contains lists of data in vectors, and I need to dynamically load data from the plug-ins without knowing which plug-ins are present. For instance:
// plugin1.h
extern vector<int> plugin1Data;
// plugin2.h
extern vector<int> plugin2Data;
// main.cpp
vector<vector<int>> pluginDataList;
int CountPlugins () {
// Some function that counts how many plug-ins are present, got this bit covered ;)
}
int main() {
int numPlugins = CountPlugins();
for (int i = 0; i < numPlugins; i++) {
vector<int> newPluginData = /***WAY TO ADD PLUGIN DATA!!!***/;
pluginDataList.push_back(newPluginData);
}
}
I already access the names of each plugin present during my CountPlugins() function, and have a list of names, so my first gut feeling was to use the name from each plugin to create a variable name like:
vector<string> pluginNames = /*filled by CountPlugins*/;
string pluginDataName = pluginNames.at(i) + "Data";
// Use pluginDataName to locate plugin1Data or plugin2Data
That's something I've done before in c# when I used to mess around with unity, but I've read a few stackoverflow posts clearly stating that it's not possible in c++. It's also a fairly messy solution in C# anyway as far as I remember.
If each plugin was a class instead of just a group of vectors, I could access the specific data doing something like plugin2.data... but then I still need to be able to reference the object stored within each plugin, and that'll mean that when I get round to compiling the plugins as libraries, I'll always have to link to class declaration and definition, which isn't ideal (though not out of the question if it'll give a nicer solution over all).
I'm all out of ideas after that, any help you can offer will be most welcome!
Thanks! Pete
Why dont you save the data as JSON between the application and the plugins ? That way you will also allow other types of tech to plug-into your app, like javascript based plugins via an embedded version of v8 or c#/.net plugins via mono.'

A descendant of TStyledPresentationProxy has not been registered for class

I have a custom grid control that inherits from TGrid called TFmGrid. This control was working fine in Rad Studio 10 Seattle Update One. I recently upgraded to 10.1 Berlin and started noticing this error message showing up on my TFmGrid controls both when I run the application and in the designer:
A descendant of TStyledPresentationProxy has not been registered for class TFmGrid. Maybe it is necessary to add the FMX.Grid.Style module to the uses section
The image below shows how the error message shows up on my grid controls:
I started by doing as the message suggests, and adding #include <FMX.Grid.Style.hpp> to the header file of my TFmGrid control, however this seems to have done nothing.
So as far as trying to register a decendant of TStyledPresentationProxy I am not exactly sure where to start. I found this documentation about a method which:
Attempts to register the presentation proxy class with the specified name or the specified combination of control class and control type.
So I assume I need to use this method or at least something similar, but I don't understand how I am supposed to go about calling this method.
But then that brings up the question of WHERE do I call this code?
My custom control has a method in its namespace called Register() which I believe was autogenerated by the IDE when the control was created:
namespace Fmgridu
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TFmGrid)};
RegisterComponents(L"Kalos FM Controls", classes, 0);
}
}
Do I need to call something in there to register a decendant of TStyledPresentationProxy? What is the proper way to go about this?
Just override virtual method DefinePresentationName in you TfmGrid and return name of presentation name for grid:
function TfmGrid.DefinePresentationName: string;
begin
Result := 'Grid-' + GetPresentationSuffix;
end;
Fm registers presentation by string name and uses class name for it, so if you create new component (based on existed) you automatically change classname, so system cannot find presentation for you. There are two solution:
Said that you will use presentation from TGrid (DefinePresentationName)
Register existed presentation for you class (look at the initialization section of FMX.Grid.Style.pas)
P.S. Year ago i wrote article about it in common eNew approach of development of FireMonkey control “Control – Model – Presentation”. Part 1 I hope it will help you
It's simple :
Just put "StyleBook" component to your form
I had the same issue with a test component I was developing.
Complementing Yaroslav Brovin's speech, I solved the problem by adding the class register in the initialization and finalization clauses at the end of the unit, like this:
initialization
TPresentationProxyFactory.Current.Register(<COMPONENT CLASSNAME HERE>, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);
finalization
TPresentationProxyFactory.Current.Unregister(<COMPONENT CLASSNAME HERE>, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);
In my case looks like this:
initialization
TPresentationProxyFactory.Current.Register(TSGrid, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);
finalization
TPresentationProxyFactory.Current.Unregister(TSGrid, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);
PS: Don't forget to declare the FMX.Presentation.Factory,
FMX.Presentation.Style and FMX.Grid.Style units in the uses clause

Write a Method like Vector.at()

I would like to know how is that the .at() method works, like the one in the Vector class of the C++, a method that both ways returns and/or assign a value to the member of the array.
i don't know if with a macro i can do it, or declaring 2 method with same name... any help?
i have been trying to find and open the file of vector, to see how it was written, that specific method, but i have not found it.
(its for a different structure i am building, but i would like to access to them with only one method)
Example of what i mean.
vec.at(x) = value;
newValue = vec.at(x);
You have to return a reference to the value. So instead of
int at(int idx)
You just do
int& at(int idx)
References are very similar to pointers with the difference that you cannot and dont have to dereference them in order to manipulate the value they are referencing
There should be an easy way to open any source file within the IDE. I use this feature all of the time to review the Standard Library, especially when wanting to review the signature of the member functions of std::vector, std::map, std::list, etc., without having to open a browser window.
Hopefully the IDE used has something similar to "open file at cursor". Since the IDE is not known by the question content, a more generic procedure is presented.
1) Make sure the relevant header name is in a #include line. For example:
#include <vector>
2) Move the editor cursor so that the cursor is clearly shown under a section of the header file name (e.g. vector).
3) Within the IDE run the "open file at cursor" command.
4) The IDE should now show the file highlighted by the cursor in its own window / tab, and there is no need to manually navigate to the area where all header files are located on the development system.
5) Search the newly opened file as desired.