|
Hi ...
Happy New Year. Hope everyone is ok. I have not been here for a while.
I have some contact lens data I'm trying to sort. I have some sort rules are static (hard-coded) followed by other rules form 'normal' rules
Here are the requirements:
1. First sort by Company and Product is a static order (hard-coded, non alphbetic)
Sample
o Company ProductName
--------------------------------------------------------------------
1. Ciba 1. Focus, 2. AirOptics, 3. Dailies, 4. then alphabetical.
2. Bausch & Lomb 1. PureVision, 2. LiquidEye, 3. Softlens then alphabetical.
2. Followed by Package size decending (80, 30 ...)
3. Followed by Base Curve decending (8.6, 8,0 ...)
4. Followed by Sphere decending (-0.5, 0.0, 1.0 ...)
In the end the result might look like the following
Sample data
CO PR PS BC Sp
-------------------------------
Ciba Focus 10 8.6 0.00
Ciba Focus 20 8.6 -0.25
Ciba Focus 20 8.6 -0.10
Ciba Focus 20 8.6 +0.25
Ciba Air 10 8.6 -0.25
Ciba Air 10 8.6 -0.10
Ciba Air 20 8.1 -0.25
Ciba Air 20 8.1 -0.10
Ciba Air 20 8.1 0.00
Ciba Air 20 8.6 +0.25
Ciba Air 20 8.6 +0.40
The data is contained in a struct with other data. The stuct is used in a map with a key. I am building a key to sort for the static requirments such as below.
The key contains a prefix at the front of the key to force the static sort (non alphabetical), followed by a suffix to make the key unique. Sample key: "1_1_Ciba_Focus Monthlys_4"
My plan to sort the other requirments is to take each of the other requirments (PackageSize, Base Curve and Sphere) and sort them against the previous element with the key.
Since I will be sorting the following agaist the Package Size (10, 20 ...) - maybe I should be using the multimap, as it might be easter to sort this stuff without having the unique ID at the end of key ??
With the key of "1_1_Ciba Focus" I would sort on the PackSize and then set the key to produce the correct sort
start: (std::multimap)
key: 1_1_Ciba Focus"
Sample data
CO PR Key
-------------------------------
Ciba Focus 1_1_Ciba Focus
Ciba Focus 1_1_Ciba Focus
Ciba Focus 1_1_Ciba Focus
Ciba Focus 1_1_Ciba Focus
Sample data
CO PR PS Key
-------------------------------
Ciba Focus 10 1_1_1_Ciba Focus
Ciba Focus 20 1_1_2_Ciba Focus
Ciba Focus 20 1_1_2_Ciba Focus
Ciba Focus 20 1_1_2_Ciba Focus
Thanks,
Chris
chris@macgowan.com
|
|
|
|
|
Maps are sorted by the key, so you cant have them stored in the static order for 1.
Depending on how often you are adding to the list and to where i would recomend either a std::vector or std::list for storing the data in the static order
Your question is a little unclear, but if i'm reading it correctly you need something like this.
cmacgowan wrote: 4. Followed by Sphere decending (-0.5, 0.0, 1.0 ...) The order there is ascending
#include <stdio.h>
#include <string>
#include <vector>
#include <map>
using std::string;
using std::map;
using std::vector;
class ProductTypeKey {
public:
ProductTypeKey() { }
ProductTypeKey(unsigned _nPackageSize, float _nBaseCurve, float _nSphere)
: nPackageSize(_nPackageSize), nBaseCurve(_nBaseCurve), nSphere(_nSphere) { }
public:
unsigned nPackageSize;
float nBaseCurve;
float nSphere;
};
typedef struct {
} ProductTypeData;
struct MyItemCompare {
bool operator()(const ProductTypeKey &mkLeft, const ProductTypeKey &mkRight) const {
if (mkLeft.nPackageSize != mkRight.nPackageSize) {
return mkLeft.nPackageSize > mkRight.nPackageSize;
}
if (mkLeft.nBaseCurve != mkRight.nBaseCurve) {
return mkLeft.nBaseCurve > mkRight.nBaseCurve;
}
if (mkLeft.nSphere != mkRight.nSphere) {
return mkLeft.nSphere < mkRight.nSphere;
}
return false;
}
};
class Product {
public:
typedef map<ProductTypeKey, ProductTypeData, MyItemCompare> TypesMap;
public:
Product() { }
Product(const string &_strCompany, const string &_strProduct)
: strCompany(_strCompany), strProduct(_strProduct) { }
void AddType(const ProductTypeKey &key, const ProductTypeData &data){
colTypes.insert(TypesMap::value_type(key, data));
}
public:
string strCompany;
string strProduct;
TypesMap colTypes;
};
int main(int argc, char *argv[]) {
Product prodCibaFocus("Ciba", "Focus");
prodCibaFocus.AddType(ProductTypeKey(10, 8.6f, +0.00f), ProductTypeData());
prodCibaFocus.AddType(ProductTypeKey(20, 8.6f, -0.25f), ProductTypeData());
prodCibaFocus.AddType(ProductTypeKey(20, 8.6f, -0.10f), ProductTypeData());
prodCibaFocus.AddType(ProductTypeKey(20, 8.6f, +0.25f), ProductTypeData());
Product prodCibaAir("Ciba", "Air");
vector<Product> colProducts;
colProducts.push_back(prodCibaFocus);
colProducts.push_back(prodCibaAir);
colProducts[1].AddType(ProductTypeKey(10, 8.6f, -0.25f), ProductTypeData());
colProducts[1].AddType(ProductTypeKey(10, 8.6f, -0.10f), ProductTypeData());
colProducts[1].AddType(ProductTypeKey(20, 8.1f, -0.25f), ProductTypeData());
colProducts[1].AddType(ProductTypeKey(20, 8.1f, -0.10f), ProductTypeData());
colProducts[1].AddType(ProductTypeKey(20, 8.1f, +0.00f), ProductTypeData());
colProducts[1].AddType(ProductTypeKey(20, 8.6f, +0.25f), ProductTypeData());
colProducts[1].AddType(ProductTypeKey(20, 8.6f, +0.40f), ProductTypeData());
for (vector<Product>::const_iterator iProduct = colProducts.begin(); iProduct != colProducts.end(); ++iProduct) {
for (Product::TypesMap::const_iterator iType = iProduct->colTypes.begin(); iType != iProduct->colTypes.end(); ++iType) {
printf("%s %s %u %.02f %.02f\n", iProduct->strCompany.c_str(), iProduct->strProduct.c_str(),
iType->first.nPackageSize, iType->first.nBaseCurve, iType->first.nSphere);
}
}
return 0;
}
|
|
|
|
|
Hi Andrew Brock,
Thanks for the response. I'll look at it and try it out.
Looks good.
I'll post a follow up.
Thanks,
Chris
|
|
|
|
|
I'm not 100% sure what you're driving at but it looks as if you only want to use a map so you can synthesise a key and then use that to control the sort. The traditional way (at least in C++) to force a sort order in a collection is to implement operator< for the key (in a map) or the value (in a vector) that you're storing.
So if you've got a class with your contact lens data in try something like:
class contact_lens_data
{
friend bool operator< (const contact_lens_data &left, const contact_lens_data &right );
};
bool operator< (const contact_lens_data &left, const contact_lens_data &right )
{
}
Then you can store them in any collection and get the collation order you want using std::sort or the inserter for std::map .
Cheers,
Ash
|
|
|
|
|
Thanks for the info
I'll check it out
Chris
|
|
|
|
|
Hello,
I was just wondering whether it was possible to connect two PCs with a USB cable and simulate a keyboard on one of them. I know I could do this with a client/server system using DirectInput, but would it still be possible without installing any software on the target machine? If possible I would like to avoid using any micro-controller between the to PCs.
Any ideas whether that's possible or not?
Ben
|
|
|
|
|
RedDragon2k wrote: without installing any software on the target machine
Obviously something must run to capture the input on the target machine and inject it into the OS. So presumably you just mean that you don't want to install it first.
Should be possible to get the USB itself to do it. You might start by looking into how one boots an OS from a memory stick. Such articles have detailed info on how USB works.
|
|
|
|
|
There is no standard for connecting PCs together with a USB cable that I know of, however if you write the driver for the computer sending the commands, you could make it appear as a keyboard to the other computer so you wont need anything on the remote computer.
I'm not too familiar with USB drivers, but if you get the Windows DDK[^] and take a look there are some sample USB drivers in the src folder.
|
|
|
|
|
Your program should send out signal through the USB port you are using to connect to the target machine exactly the same signal a keyboard would send (when you use a USB keyboard). The target computer will simply believe that a USB keyboard is being plugged to the USB port. That means it's possible to achieve what you want to do. You need to work on the details, though. I believe you need to use Windows DDK to write programs to deal with USB.
|
|
|
|
|
Alright, I have clicked through the DDK, but from what I understand it doesn't seem possible to accomplish. Apparently a PC can only act as a host control, and will identify itself as such to the other computer. Any ideas for starting points?
|
|
|
|
|
Hello Friends
When a window is minimised, it goes to taskbar at the location where the tray icon is there.
So if icon is towards right, the window is minimised to the right.
I remember there was a function with some name like setwindowanimation, but seems i am missing something.
anybody has got an idea of how to do that?
Regards
|
|
|
|
|
SoftwareDeveloperGoa wrote: When a window is minimised, it goes to taskbar at the location where the tray icon is there.
Not the "tray icon": the corresponding taskbar button.
Tray icons are other things.
SoftwareDeveloperGoa wrote: So if icon is towards right, the window is minimised to the right.
Yes, but ... what are you trying to achieve? Are you trying to change the task button relative positions?
The question is not clear.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
yes you are correct, it is taskbar
yeah i want a window to minimize to a specific location, irrespective of where it's taskbar icon is present.
it is all about that animation thing that windows displays for every window relative to taskbar icon's position
|
|
|
|
|
AnimateWindow is documented here[^].
But the animation the system uses to manage the top windows depends on the system settings and theme, not on the code of your app.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
|
Hi all,
i have an list ctrl with some items,i want to perform an action with each item of list ctrl than after performing action delete this item.
i m using this.
int count =m_List.GetItemCount();
for (int i=0;i<count;i++)
{
m_List.DeleteItem(i);
}
here items are not fetched according to its serial like if firstly i m use item 1,than next item here is item 3 than 5 and so on..
here all items are not processes by this loop
please tell me what can i do for this.
thanks in advance.
|
|
|
|
|
When you delete item 0, every other item moves up 1, so what was item 1 is now item 0.
Instead of using m_List.DeleteItem(i); , use m_List.DeleteItem(0);
The same goes for getting the data or string from each of the items, you are always using the first item in the list
|
|
|
|
|
int count =m_List.GetItemCount();
for (int i=0;i<count;i++)
{
//do msometing with item i
m_List.DeleteItem(0);
}
just like this。。
|
|
|
|
|
jixuduxing wrote: //do msometing with item i
Probably just a copy/paste mistake, but
int count =m_List.GetItemCount();
for (int i=0;i<count;i++) {
m_List.DeleteItem(0);
}
|
|
|
|
|
Or even easier to understand:
int count =m_List.GetItemCount();
for (int i=0;i<count;i++)
{
}
m_List.DeleteAllItems();
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
You should start using the MSDN documentation to learn about the classes you are implementing. Had you done so you would surely have found this[^].
I must get a clever new signature for 2011.
|
|
|
|
|
Note that reversing the loop
for (int i = count-1; i >= 0; i--)
{
m_List.DeleteItem(i);
}
would solve you problem.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
int count = m_List.GetItemCount();
for (int i = count - 1;i >= 0; i--)
{
m_List.DeleteItem(i);
}
if you delete item from a list, you should delete it from the last to the first.
|
|
|
|
|
Facing an uphill batte against OpenGL vs. Vista/Win7 ...
Seems we cannot use GDI to BitBlt to do a screenshot when Aero is turned on.
Reading a lot on the web (opengl.org,gamedev.net, ...) about this, it looks like I need to use glReadPixels to get the RGB(A) values from the OpenGL buffer.
The issue is that I'm not certain how to transfer the resulting pixel array ( RGB(A) ) to something that Windows can use.
glPushAttrib(GL_PIXEL_MODE_BIT);
glReadBuffer(GL_FRONT);
glFlush();
glFinish();
unsigned char *glBuffer = new unsigned char [width*height*4];
ASSERT( glBuffer) ;
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, glBuffer);
unsigned char* Buffer = new unsigned char [width*height*3];
unsigned char* ptmp = Buffer;
unsigned char* pbuffer = glBuffer;
for (int j=0; j<height; j++)
{
for (int i=0;i<width; i++)
{
*ptmp++ = *pbuffer++;
*ptmp++ = *pbuffer++;
*ptmp++ = *pbuffer++;
pbuffer++;
}
}
delete [] glBuffer;
HBITMAP hBitmap= ::CreateBitmap(width, height, 3, 24, Buffer);
ASSERT( hBitmap);
The array returns by glReadPixels looks ok, but creating the bitmap returns a NULL handle; at first, even if it did not work, I half expected to have a corrupted bitmap, but not just a NULL.
I'm certainly missing a lot of things, but I'm not certain what; probably mixing up context and some things ... all that I can find is that people say use glReadPixels and it works!
Any idea ?
Thanks.
Max.
Watched code never compiles.
|
|
|
|
|
I think the number of planes is supposed to be 1.
HBITMAP hBitmap= ::CreateBitmap(width, height, 1, 24, Buffer);
ASSERT( hBitmap);
modified 13-Sep-18 21:01pm.
|
|
|
|
|