I'm using C. I have to large enums, one of menu ID's and one of window ID's. At the moment they're mapped to each other by an array, so the elements have to be put into the array perfectly and as soon as something changes work has to be done to put them all back into the right place. What would be a better way of mapping the menus to the windows? Thanks
Are you explicitly assigning values to the members of each enum? How do menu IDs map to window IDs? Can you post part of the enums as an example?
If the enums are lengthy, this might be a good candidate for a code-generating script. Store your IDs in (for example) a CSV file that lists matching pairs of Window IDs and Menu IDs. Then, write a script that parses the CSV file and generates a header containing the appropriate enum definitions. If you are building your project using makefiles (or similar), it should be fairly straightforward to integrate this type of auto-generated header into your build system.
Related
In Swift, you have views, views, and more views. and i'm trying to make a dynamic list of views that is varied by the files in a group.
Im aware that the groups are not saved on app creation
I cant use Init() in a view because that implies that the view was activated by an outside source (NavigationView for example)
Having a static variable is saved on app startup so i could probably do something like that.
But Essentially i'm trying to be lazy/clever and do something that you can do in java, like iterate through every class in a package and instantiate those objects as you need. I want a NavigationView that's Dynamic, like i can add an Annotation (attribute in this case, but probably not helpful for my problem, just an ides) to my Views, and have a for loop iterate through an array that contains all my possible view objects and give me a navigationView for that.
I COULD just make a Statically configured list of Views ie [v1(), v2(), v3(), v4()...] and just do a ForEach through that and work that way, i just don't want to have to configure that in the main file when i cold probably do it dynamically (if possible) and just write a new class, and at the top put like an annotation and have it auto add to an Array that i'm managing dynamically.
I know you can iterate through files, but files on compile are not in the same structure (no folders etc...) but even if i could i don't know how to do that, and add all vies to a large Set of views for a navigation pane. Like a ForEach of [arr of views] each becoming a navigation link. and i can get the Name of the View by doing View.name or whatever
TLDR:
I want to have my Views Automatically Add themselves to a Static data list (Array of Views probably) and be able to have a navigationView Dynamically just add it to the clickable NavViews and replace this:
With something that is just a loop of all my possible views that i've declared somehow.
Is this possible? if so how would i go about doing something like this
also, i know its probably not the best idea, but for the sake of learning id like to understand how to do this, then maybe a better way of going about what i want so i don't have a centralized place, and i can make it dynamic
In my web application, there are several classes whose instances need an image (i.e., photo). Each of these instances can have only one image. Currently, my implementation is that when user creates a new instance, I keep the name of the uploaded file as it is, and record it in the ImageUrl field of the associated table.
I feel like this is unnecessary. I can just rename the image with the unique url of the associated instance, and I can implement the programming logic accordingly. For example, if a user's id is 145, then I can record it with this name: profilephoto_145. Later, when I need to display the user's photo, all I need will be the id of the user. If user uploads a new file, I can just overwrite the existing file with the same name.
I wonder if this makes sense assuming each instance will have one associated image, and there will be no need to keep track of the previous files. What is the common approach for this? Should I keep the full path for each image and keep their original names, or should I implement this renaming files with ID?
I can just rename the image with the unique url of the associated
instance, and I can implement the programming logic accordingly. For
example, if a user's id is 145, then I can record it with this name:
profilephoto_145.
Yes, you can do that. The general search term for this kind of thing is "tight coupling" or "coupling and cohesion". The concept applies in lots of different areas of software development.
Your underlying idea is that you'll always store one profile photo per user, and you'll store it by concatenating "some kind of path" and "profilephoto_" and user's id. The main problem is that any change to that idea requires changing source code. And changing source code has ripple effects.
The common alternative is to store the image file's name in a database. In this case, most changes to that underlying idea would require only a database update.
Programmers who have been around a while cringe a little when people start using words like always and never. Because we know that, given enough time, statements that use always and never with respect to software are always never true.
I'm trying to create an iOS application where users post and image, and then someone can comment on the image. So far I've set up the a message class which contains (among other things) the image file. I want to be able to add comments to the image, so what would be the best way of doings this.
Option A:
I could add an array (or object?) column to the already existing message class, and then store in this array the comment (string) and the id of the poster (string). For this I think I would need a two-dimensional array, but I'm not sure how I would go about doing this.
Option B:
I could make an entire new class of comments which contains the user's comments (string), as well as the image file that he/she linked to (perhaps though a PFRelation)
Basically I'm leaning to Option A, because it seems easier/more efficient to implement, but I don't really know how I would go about creating a two-dimensional/array of objects - so my question is, how would I go about doing this?
The way I did it in my app is option B. I then added a count column to the photo that was incremented/decremented onSave or onDelete. I think this method is better because it keeps the data more symmetric (with option A some data could have thousands of comments while others would have 0). Additionally, it allows you to query the comments cell if you wanted to have a notification view where you showed the user what activity has been done on their photo.
I have 4 forms (beside the main form) that I would like to store in an array and called randomly. The forms contain web pages with YouTube video clips that autoplay. When I use them individually in the code they work as expected. I am having trouble getting them to play from an array.
Consider the following approaches:
If the four forms are identical except for the specific YouTube URL, consider consolidating them to a single form. You can send the URL to the new form via the constructor. An array of strings is much easier to create.
You could generate a random integer (between 1 and 4). Use as Select myRandomInteger statement with a Case to initialize and show the form for that integer value (index).
Finally, if you post the non working code, perhaps someone will have a more specific solution for you.
I am using iReport Designer to design the .jrxml file.
How can I use the for loop or if loop in .jrxml file?
Is it possible?
If yes how?
You may wish to use a scriptlet. It's basically a Java class that extends either of the following two classes:
net.sf.jasperreports.engine.JRAbstractScriptlet
net.sf.jasperreports.engine.JRDefaultScriptlet
In a scriptlet, you can indicate that a certain piece of code should be executed every time a report event occurs, e.g., report, page, or column initialization.
In a scriptlet, you may use loops. You may access fields, parameters, and variable values. You may also adjust variable values.
There is a chapter on scriptlets in the JasperReports Ultimate Guide.
Well what you can do is create a list of selected fields(which client UI selects) and pass it as a collection to JasperFillManager.fillReport and in the jrxml create a field names _THIS which will represent the value's in the List.
And as you want those field to printed in loop, place them in the detail band of the report.