Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm looking for a library to manage menus. I'm looking for something which is based on configuration files. It doesn't have to manage keyboard input or display, just the menu logic. What I have in mind something like:
//menu.xml
<menu>
<Start />
<Stop />
<Configuration displayname="Configure System">
<Sound type="toggle" />
<Speed display="Speed related settings">
<Speedy type="toggle" default="on" />
<Optimizations type="toggle" />
</Speed>
</Configuration>
<Filesystem>
<SaveSnapshot />
<LoadSnapshot />
</Filesystem>
</menu>
In the code we would have:
//menu.cpp
Menu menu("menu.xml");
menu.bind("SaveSnapshot",saveSnapshotPressed);
menu.bind("LoadSnapshot",loadSnapshotPressed);
menu.bind("Sound",soundSetTo);
...
void onKeyPressed(key_t key) {
...
switch (key) {
case KEY_UP:
menu.goUp();
break;
case KEY_DOWN:
menu.goDown();
break;
case KEY_ENTER:
menu.action();
break;
}
// display.cpp
void render(...) {
for (int i=0;i<menu.items().size();++i) {
renderText(getMenuCoord(i),menu.items()[i].c_str());
}
...
}
Such a library could be very useful to display menus in embedded device.
I'll be glad to hear if such library exists, or is there a better idea for this library.
There are things like Kaleido: http://www.digitalairways.com/kaleido-engine.htm
which are very nice, but pricey.
Emwin is simpler and cheaper but nothing like as rich in terms of functionality:
http://www.segger.com/cms/emwin.html
You may want to look at the Android SDK. This too, may be more than you want to handle, but there may be value in replicating, or possibly using any tools google may have.
I know this is an old question but maybe someone else, has the same problem.
I think CLI is the solution you need.
CLI is a toolkit that allows you to easily implement C++ and Java Command Line Interfaces
It has XML configuration file and generates C++/Java source which you then link.
I haven't tested it, just found it when searching for something to create CLI menus easier.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
Okay, so I am very new to Vulkan API, as seen in my last question. I am very confused about why vkCreateSwapchainKHR results in an access denied.
I have tried re-typing the code. I have tried Minimal Viable code. I have also tried initializing the swap chain at different times, but they all seem to not work.
The variables like _sur_capab are surface capabilities were got earlier than this. And, _logicalDevice was just an instance of VkDevice.
VkSwapchainCreateInfoKHR cri = { };
cri.clipped = VK_TRUE;
cri.oldSwapchain = VK_NULL_HANDLE;
cri.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
cri.flags = VkSwapchainCreateFlagBitsKHR::VK_SWAPCHAIN_CREATE_FLAG_BITS_MAX_ENUM_KHR;
cri.imageArrayLayers = 1;
cri.imageColorSpace = VkColorSpaceKHR::VK_COLORSPACE_SRGB_NONLINEAR_KHR;
cri.imageExtent = _sur_capab.maxImageExtent;
cri.imageFormat = VkFormat::VK_FORMAT_ASTC_5x4_UNORM_BLOCK;
cri.imageSharingMode = VkSharingMode::VK_SHARING_MODE_MAX_ENUM;
cri.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
cri.minImageCount = _sur_capab.minImageCount;
cri.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
cri.preTransform = _sur_capab.currentTransform;
vkCreateSwapchainKHR(
_logicalDevice,
&cri,
nullptr,
&_swapChain);
One advice up front: Always run your applications with the validation layers enabled, they should hint you at the potential problems in your code.
Without knowing the remaining relevant code parts, I can see several potential problems with your code above:
First one is the fact that you're setting invalid values for flags and imageSharingMode. The _MAX_ENUM_ values are not be used for initialization, so you need to pass proper values there. Usually it's 0 for the flags and e.g. VK_SHARING_MODE_EXCLUSIVE for the imageSharingMode. Check the specs to see what values are valid for the members of your VkSwapchainCreateInfoKHR structure.
Next up you need to check if the imageFormat you request is actually supported on your device via vkGetPhysicalDeviceSurfaceFormatsKHR. VK_FORMAT_ASTC_5x4_UNORM_BLOCK is a pretty specific format and I can imagine that only a very few, if any at all, implementations support this as a surface format.
It also looks like you're not setting the presentMode at all, making it 0 due to initialization, which equals to VK_PRESENT_MODE_IMMEDIATE_KHR. This mode may not be supported on your target implementation, just like the image format. You need to either select a present mode that's available everywhere, or properly select one that's supported via vkGetPhysicalDeviceSurfacePresentModesKHR.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have been trying to find a way to enforce unique error messages in our application. That is, I want to know exactly which line of code produced the error, so when users contact support we know the source of the error from the message logged.
I found this question which gave me a mechanism (using guids to enforce uniqueness), but one question remains: How do I prevent copy/paste duplication? - specifically, a developer copying the logging line itself:
Log(<guid>, errorMessage);
In this case the guid would be duplicated and no longer useful for identifying the unique line which generated the error.
The one idea I have had which would actually work is writing a tool to be run by our build server which would parse the code for error message guids, keep a list, and fail the build on a duplicate. I'm wondering if there is a cleaner solution.
Other things I've considered:
There are various ideas using some sort of central listing of error messages, but I have not found one which addresses the copy/paste issue.
There are also a number of schemes which would require keeping a manual list in some way. I don't want to pursue something like this as it creates the possibility of discrepancies between the list & production code.
I've also seen suggestions to use the stack trace, but I'm a bit hesitant to do that for security & performance reasons.
I don't know if this is really what you're looking for, but you can include the file, method, line number (and other things) in your log message without needing a unique number that you would later search the source code for if you make use of the System.Diagnostics.StackTrace class. This way, even if there's a copy/paste violation, you still know exactly where the call to Log came from.
Here's a simplified example that returns the file name, method signature, and line number of a stack trace item. Note that this code finds the stack trace item for a call to the "Log" method and returns the next one. That will be more clear shortly:
using System.Diagnostics; // Needed for the StackTrace class
private static string GetStackTraceInfo()
{
var stackTrace = new StackTrace(true).GetFrames();
// Find the item just after the call to teh 'Log' method:
var item = stackTrace?
.SkipWhile(st => !st.GetMethod().Name.Equals("Log"))
.Skip(1)
.FirstOrDefault();
return item == null
? string.Empty
: string.Format("{0} => {1}, line #{2}", Path.GetFileName(item.GetFileName()),
item.GetMethod(), item.GetFileLineNumber());
}
Here's the Log method that enforces the stack trace info added to a log (and this is the method name that we were searching for in the code above):
private static void Log(int id, string message)
{
Console.WriteLine($"Error #{id}: {message} ({GetStackTraceInfo()})");
}
And an example usage:
private static void Main()
{
DoSomething();
DoSomethingElse();
GetKeyFromUser("\nDone! Press any key to exit...");
}
private static void DoSomething()
{
Log(1000, "I copied/pasted this error message from somewhere!");
}
private static void DoSomethingElse()
{
Log(1000, "I copied/pasted this error message from somewhere!");
}
Output
In my years at college I've learned to program Java, which I did in Eclipse. I loved the feature in Eclipse on how Javadoc comments were able to pop-up in a window. At the moment I'm programming C++ and I'm really starting to miss this feature.
That's why I'm asking: is there a plug-in of something that acchieves the same result. Currently I am programming c++ with Visual Studio Express 2010, that does not have anything like this except for showing a function interface in the auto completion window. I would like to read more info such as reading up on pre- and postconditions for example, either for code from existing libraries (if they exist) or otherwise only for code I wrote myself.
Now I know of Doxygen, but that it not really what I'm looking for. It is a good enough fall back mechanism, but I really like to have it readily available from the same window I'm writing my code in.
Does something like this exist for Visual Studio? Or can I start using the C++ version of Eclipse and run the Javadoc generator there (I actually haven't tried this!) to get those nice pop-up comments?
EDIT:
I've been trying to get XML style comments working, but something like:
/// <summary>This constructor takes parameters to set the
/// members of the Cow class.
/// <param name="ho">Hobby as string of the cow.</param>
/// <param name="wt">Weight of the cow as a double.</param>
/// </summary>
Cow(const char * nm, double wt);
still only gives me the string "Cow(const char * nm, double wt)" in the pop-up window. Built with the \doc option, I do have a .xml file generated (in my Debug folder).
In C# you can write
///
And it will generate a XML style comment like:
/// <summary>
///
/// </summary>
/// <param name="parameter"> </param>
/// <returns> </returns>
You can let Visual Studio generate an XML file, which can be processed to get something like javadoc. I'm 100% sure it works on C#, but it seems that C++ uses a different style. If I go to project options > Configuration Options > XML Document Generator > General, and set the "Validate IntelliSense" to Yes, you can place comments in your .h file:
class Test {
public:
// The constructor
Test(void);
// The destructor
~Test(void);
// The function description
void Function();
};
If I go to my main.cpp, and type this:
Test * test = new Test();
test->
As soon as I hit the '>', a box pops up with a list of functions (destructor and the function in this case). If I select Function for example, a tooltip pops up with "The function description":
void Test::Function();
The function description
File: test.h
I'm not sure if there are any plugins, but I hope I helped you a bit here!
If you have CodeRush/Refactor you can try the CR_Documenter plugin (use VS Extension Manager). It provides a new dockable window with such documentation.
I am with you - Eclipse is so much better for viewing documentation.
Use SandCastle to integrate with the builtin help (F1). Its not as good as inline help like you get in Eclipse, but you can hover over a type, press F1 and then you are there.
To do this, install Sandcastle and Sandcastle Help File Builder. Then in your Sandcastle Help File Builder project, make sure to tick the box for MSHelpViewer. This will generate documentation and a script you can run to integrate your custom documentation into the F1 help.
I am aware of how to get a specific file from the Resources folder in cocoa, i.e. :
NSBundle* myBundle = [NSBundle mainBundle];
NSString* myImage = [myBundle pathForResource:#"Seagull" ofType:#"jpg"];
anyways, I'd like to have a simple function that gives me the path to the Resources folder so I can use it in c++ like this.
String getResourcePath()
{
return the correct path here
}
std::ofstream theFile;
theFile.open(getResourcePath()+"test.txt");
I guess I could manually combine the main bundle name with Contents/Resources, anyways I'd like to know if there is a more robust solution!
Thanks!
If you ever wonder if an Apple-provided class has a certain method, do look up Apple's own documentation before asking the question here at SO.
In this case, the answer is this method. But let me reiterate:
If you ever wonder if an Apple-provided class has a certain method, do look up Apple's own documentation before asking the question here at SO.
And, when you do so, go over all the methods in the documentation. That way, you'll learn what kind of methods are available.
I have a Win32 C++ program that validates user input and updates the UI with status information and options. Currently it is written like this:
void ShowError() {
SetIcon(kError);
SetMessageString("There was an error");
HideButton(kButton1);
HideButton(kButton2);
ShowButton(kButton3);
}
void ShowSuccess() {
SetIcon(kError);
std::String statusText (GetStatusText());
SetMessageString(statusText);
HideButton(kButton1);
HideButton(kButton2);
ShowButton(kButton3);
}
// plus several more methods to update the UI using similar mechanisms
I do not likes this because it duplicates code and causes me to update several methods if something changes in the UI.
I am wondering if there is a design pattern or best practice to remove the duplication and make the functionality easier to understand and update.
I could consolidate the code inside a config function and pass in flags to enable/disable UI items, but I am not convinced this is the best approach.
Any suggestions and ideas?
I would recommend Observer Pattern and State Pattern, when an validation happens to be successful or unsuccessful, attached buttons can change their state according to information provided in "notify" method. Please refer to GoF's book for further details, or just google them. Hope it helps.