|
Hi
Fine... Iterators themself are not hte problem and using stl is not the problem too.
But I like to know to manage my special QUEUE double linked template class with my own special ITERATOR for dynamic queues holding about 3.000.000 entries (each QUEUE) no arrays used!!!
Please tell my how to manage.
Ein Synonym für "kann ich nicht" lautet "trivial" oder "das bleibt dem Leser überlassen" ...
CU T
|
|
|
|
|
Sry, this has to be written in German. There was an musunderstanding.
Hallo tbrake,
Das ist auf keinen Fall trivial. Aber das wollte ich auch nicht ausdrücken. Was ich dir mitteilen wollte war: warum schaust du dir die STL nicht an? Es gibt genug C++ Standard Libraries, die im Quelltext verfügbar sind.
Ich wollte auf keinen Fall den Eindruck vermitteln, ich hielte mich für etwas Besseres. Ich hatte einfach unglaublich gute Laune (und dachte, das käme so rüber, sorry) und wollte dir vermitteln, dass du genug Quellen hast, um dein Problem zu lösen. Deswegen kam die Abkürzung STL auch so häufig in meinen Posts vor.
Das war nicht böse gemeint, und es tut mir leid, das du es so verstanden hast.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Hi
1.
my Solution for Iterator...
<br />
template <class T><br />
class TQueue <br />
{<br />
public:<br />
<br />
typedef struct tqueue<br />
{<br />
struct tqueue *next;<br />
T eintrag;<br />
struct tqueue *prev;<br />
}tqueue;<br />
<br />
<br />
<br />
class Iterator<br />
{<br />
public:<br />
Iterator(TQueue<T> &tq):q(tq) {}<br />
~Iterator() {}<br />
void reset() {aktuell = q.getfirst();}<br />
void next()<br />
{<br />
if(aktuell)<br />
{<br />
tqueue *alt=aktuell;<br />
aktuell = alt->next;<br />
}<br />
}<br />
void prev()<br />
{<br />
if(aktuell)<br />
{<br />
tqueue *alt=aktuell;<br />
aktuell = alt->prev;<br />
}<br />
}<br />
T* get()<br />
{<br />
if(aktuell)<br />
return &(aktuell->eintrag);<br />
return NULL;<br />
}<br />
private:<br />
TQueue<T> &q;<br />
tqueue* aktuell;<br />
};<br />
<br />
<br />
<br />
TQueue();<br />
virtual ~TQueue();<br />
<br />
void gethead();<br />
void gettail();<br />
void push(T*);<br />
T* getnext();<br />
T* getprev();<br />
T* prev();<br />
T* get();<br />
void destroy();<br />
<br />
<br />
tqueue *getfirst(){return first;}<br />
<br />
long counter(){return m_count;}<br />
public:<br />
long m_count;<br />
tqueue *curr;<br />
tqueue *last;<br />
protected:<br />
tqueue *first;<br />
};<br />
This is working :->
Not written the way i like to have it .. but working (so far)
2.
MeTo in orefull german
Wollte Dir auch nicht Deine Laune miesmachen ... sitze jetzt aber schon ein paar Stunden an diesem Problem ... Leider kann ich auch nicht so einfach auf stl umsteigen ... Habe hier ca 300 Klassen mit je 1000 Zeilen Code ... und dann ist es am einfachsten wenn Du es einfach nur erweiterst ...
Schwamm darüber ... es funst !!!
THX
CU
Timen
|
|
|
|
|
Yeah, sponge over...
I am closing on the solution to my problem, too.
The funny thing is: If I remove everything else from the sourcefile in question and just leave the structs and the predicate in place, all works well. There HAS to be some freak-up in the sourcefile. Maybe I forgot to remove one of my predecessors jumps - or I made a mistake when I refactored the output to print to a file instead of the screen (which, when printing 400000 lines, DOES make a difference.
Anyway, I am glad you were able to solve your problem.
:-DJust dont break it again, I might not always be here to help you... SCNR, just kidding, I hope its obvious this time
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Hi everybody.
It seems that I am unable to solve a problem I recently encountered while trying to use STLs generic "sort(RanIt First, RanIt Last, Pr Pred)". I have a class which evaluates a range of datasets coming from a lower level of one of our plants (I am doing a performance evaluation).
The product-data is stored in a binary file, which is read and fed to my application by a legacy-tool on which I have no modification privileges. Since that tool works well and is blazingly fast (inflating, reading and forwarding up to 10000 datasets per second, each sized around 100 KB) I am OK with that. There is one catch, though: The data has to be written after the final production step of each product is finished. Products no not necessarily take the same path, so they are stored "unsorted". And try to find a single entry in an ascii-log which holds 10000 products, with IDs being 16 digits, where the first 10 digits refers to a certain product attribute and the last 6 digits are auto-incremented.
Basically, I do the evaluation on a "per product" basis and then store the results (just a couple of integer values) in a struct (which contains 2 vectors). I then push that struct into another vector, e.g.:
<br />
typedef struct example<br />
{<br />
int test1;<br />
int test2;<br />
vector<int> Data;<br />
}Example;<br />
and a class ExClass containing a vector<Example> m_Products;
Hell, I figured, I successfully used sort before, so why not use it this time. I #included <algorithm> and wrote a binary predicate:
<br />
bool ExClass::lessProduct(Example &e1, Example &e2)<br />
{<br />
return ( e1.test2 < e2.test2 )<br />
} <br /> (
with the appropiate prototype in the header. Originally, this even was inlined for speed, but I got the same error.)
And I get C2064 claiming: "C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1863): error C2064: term does not evaluate to a function taking 2 arguments."
I need help here.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
looking at the error message, i would tend to say that the prototype of the comparator should be better bool ExClass::lessProduct(Example& e);
because the other parameter is this
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|
|
toxcct: Sorry, I believe you misunderstood my example. My mistake.
The Class I am referring to contains both the struct (protected) and the vector_of_struct (private).
STL's sort template offers two prototypes, one takes the start and end iterator, the other one additionally takes a binary predicate.
In that predicate (which also is a member of my class) this would refer to the class, not a second structure.
As I mentioned before, I did exactly the same in another class (and it worked). That's why I am so confused.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
-- modified at 6:51 Thursday 22nd December, 2005
|
|
|
|
|
|
Thanks it worked and gave me an idea:
I removed everything else from the header and just left the structs and predicate in place. It compiled and worked correctly. If I add the remaining header, the compile fails again.
Now I just need to find out why.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Hi All,
i am intending to save double array values to blob fiels in MySql database. So i need to convert double value in to BYTE array.
Can anyone help me to convert a double value (8byte) to BYTE array and vice versa.
Thanks in advance
Basheer
|
|
|
|
|
double d = ;
char tab[8];
tab[0] = ((d >> 0) & 0xFF);
tab[1] = ((d >> 8) & 0xFF);
tab[2] = ((d >> 16) & 0xFF);
tab[3] = ((d >> 24) & 0xFF);
tab[4] = ((d >> 32) & 0xFF);
tab[5] = ((d >> 40) & 0xFF);
tab[6] = ((d >> 48) & 0xFF);
tab[7] = ((d >> 56) & 0xFF);
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|
|
unsigned char bArray[sizeof(double)];
double d;
memcpy(bArray,&d, sizeof(double));
reverse:
memcpy(&d, bArray, sizeof(double));
|
|
|
|
|
kakan wrote: unsigned char bArray[sizeof(double)];
won't compile. you have to do it this way :
unsigned char* bArray = new unsigned char[sizeof(double)];
which is why i directly put [8] to ease the code (standard C++ tell that the size of a double is fixed to 8 bytes, so doesn't vary).
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|
|
Hello.
You are right (of course).
But the memcpy is neat, isn't it?
|
|
|
|
|
|
Thanks.
|
|
|
|
|
Actually you are incorrect. sizeof(double) is a compile time constant, and so it will compile. (Just to double check, I tried and it did.)
|
|
|
|
|
Obviously the best wat to do this is to not do it, viz:
union MyConvert
{
double d;
BYTE bytes[sizeof(double)];
};
Thus for some function storeBytes(BYTE*p, size_t size)
to get a double called myVal stored do this:
MyConvert mc;
mc.d = myVal;
storeBytes(mc.bytes, sizeof(myVal);
or if you want to go nuts and save the copy:
storeBytes(((MyConvert*)(&myVal))->bytes, sizeof(myVal));
Though that might not work if the alignment requirements are different between double and unions.
|
|
|
|
|
Hi,
Could someone point me to the problem.
When I use this:
<br />
m_Edit.SetWindowText(str+"W");<br />
I get one "W" character displayed before str and two displayed after.
If str is "----------", I get "W----------WW".
Thank you,
|
|
|
|
|
Does SetWindowText take a CString? I dont know where that SetWindowText comes from, but I will just assume it takes a LPSTR* or a const char*. In that case, you need to make sure that SetWindowText gets what it needs. I am not familiar with CString, but I suspect that (as of now) it is an alias for std::string? In that case, try
<br />
str += W;<br />
m_Edit.SetWindowText(str.c_str());<br />
Cheers
Seb
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Try to construct the CString before passing it to SetWindowText:
CString Temp = str + "W";<br />
m_Edit.SetWindowText(Temp);
|
|
|
|
|
Is the m_edit box object of CEdit
i tried it and did not get any error
the str was dispalyed ad "---------W"
CString str;<br />
str.Format ("----------");<br />
m_memorystatus.SetWindowText (str+'W');
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
bachirzantou wrote: m_Edit.SetWindowText(str+"W");
CString str =="Whatever text";
str+="W";
m_Edit.SetWindowText(str);
or
m_Edit.SetWindowText(str.GetBuffer(0));
or
m_Edit.SetWindowText(str.operator LPCTSTR());
Happy christmas friends. May the Love of My Lord and Saviour Jesus bring forth Joy and Happiness into your life too.
<marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" hspace="2" vspace="2">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
SetWindowText() is waiting for a CString, so there's no reason for casting back into a C-style string (LPCTSTR).
moreover, when somebody took time to design a cast operator, it should be used properly, in the C style too. so, instead of writing str.operator LPCTSTR() , simply write (LPCTSTR)str
one last thing. when you .GetBuffer() a CString, you should release it then (which you seemed to forget here...)
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|
|
Game over;P
Happy christmas friends. May the Love of My Lord and Saviour Jesus bring forth Joy and Happiness into your life too.
<marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" hspace="2" vspace="2">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|