Click here to Skip to main content
15,890,438 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problem with MPR.lib/MFC90.DLL Pin
Richard MacCutchan20-Oct-11 23:01
mveRichard MacCutchan20-Oct-11 23:01 
GeneralRe: Problem with MPR.lib/MFC90.DLL Pin
tasumisra24-Oct-11 2:03
tasumisra24-Oct-11 2:03 
GeneralRe: Problem with MPR.lib/MFC90.DLL Pin
Richard MacCutchan24-Oct-11 3:46
mveRichard MacCutchan24-Oct-11 3:46 
AnswerRe: Fix the registry Pin
Goto_Label_21-Oct-11 6:59
Goto_Label_21-Oct-11 6:59 
QuestionvString Pin
Tyler Elric20-Oct-11 16:48
Tyler Elric20-Oct-11 16:48 
AnswerRe: vString Pin
Tyler Elric20-Oct-11 16:57
Tyler Elric20-Oct-11 16:57 
AnswerRe: vString Pin
Richard Andrew x6420-Oct-11 18:02
professionalRichard Andrew x6420-Oct-11 18:02 
GeneralRe: vString Pin
Tyler Elric21-Oct-11 1:50
Tyler Elric21-Oct-11 1:50 
Oh, okay. My apologies!

C++
class Range{
        private:
                int mStart,mSize,myID;
        public:
                Range(int aStart,int aSize):mStart(aStart),mSize(aSize){}
                Range(Range& r):mStart(r.mStart),mSize(r.mSize){}
                Range(const Range& r):mStart(r.mStart),mSize(r.mSize){} //needed to return 'by value'
                bool operator () (int x){
                        return x>=0? (x<mSize || mSize==0):(-x <= mSize || mSize==0);
                }
                int operator [] ( int x ) {
                        if(!operator()(x)) throw std::range_error("Range throwing exception; invalid indice number.");
                        return x + mStart;
                }
                int Size( ){ return mSize; }
                int Size( int aSize ){ return mSize = aSize; }
                int Start( ) { return mStart; }
                int Start( int aStart ){ return mStart = aStart; }
};


Inside Vector<> Class:
C++
Range All( int size = -1 ) {
        if(size==-1) size = arraySize;
        const Range ret(0,size);
        return ret;
}


And the problematic code:
C++
T& Add(const T& nElement, int indice = -1){
        Allocate();
        ++arraySize;
        Range ran = All();
        indice = ran[indice];
        if ( indice < 0 ) indice = arraySize + indice;
        if(sizeof(T)<=sizeof(T*)){
                if(static_cast<unsigned int>(indice+1)!=arraySize) memcpy(&(((T*)tElements)[indice+1]),&(((T*)tElements)[indice]),sizeof(T)*(arraySize-indice-1));
                memcpy(&(((T*)tElements)[indice]),&nElement,sizeof(T));
                return (((T*)tElements)[indice]);
        } else {
                memcpy( &(tElements[indice+1]),&(tElements[indice]),sizeof(T*)*(arraySize-indice));
                if(construct) return *(tElements[indice] = new T(nElement));
                else{
                        T* nPtr = (T*)new char[sizeof(T)];
                        memcpy(nPtr,&nElement,sizeof(T));
                        return *(tElements[indice] = nPtr);
                }
        }
}


More problematic code is:
C++
vString& vString::Insert(char* str,Range& ran){
        if(!str) throw std::runtime_error("vString::Insert(const char*,Range&) - Invalid first argument.");
        int end = (ran.Size())?ran.Size():strlen(str)+1;
        Allocate( end );
        if(arraySize == 0 ) // first string...
                memcpy(&(((char*)tElements)[0]),str,arraySize = end);
        else memcpy()
        for(int i=0;i<end;i++,str++) Vector<char>::Add(*str,ran.Start());
        arraySize--;
        return *this;
}
vString& vString::Insert(const char* str,Range& ran){
        if(!str) throw std::runtime_error("vString::Insert(const char*,Range&) - Invalid first argument.");
        int end = (ran.Size())?ran.Size():strlen(str)+1;
        Allocate( end );
        if(arraySize == 0 ) // first string...
                memcpy(&(((char*)tElements)[0]),str,arraySize = end);
        else{
                Range& all = All();
                int indice = ran.Start();
                indice = all[indice];
                if(indice<0)indice+=arraySize;
                if(indice<0)indice=0;
                memcpy(&(((char*)tElements)[indice+end-1]),&(((char*)tElements)[indice]),end-1)
        }
        arraySize--;
        return *this;
}


Specific issues:
Not sure if I should rely on my Vector<>::Add() method to handle everything, or if I should make the vString::Insert() method take care of things.
I am also getting trouble getting my Prepend() method to perform expected results. It passes it's first argument as-is, then the second argument as a Range(0,0) ( 0 size = indefinite size, 0 start = first element ). Append() seems to work alright, but Prepend() seems to 'erase' the old string, and replace with only one character of the new string. ( I only test with the 'const char*' and const T& functions -- the char* overload was included to show you what the function used to look like )
The roof's on fire,
but keeps out the rain,
so clench your fists,
and enjoy the pain.

QuestionRe: vString Pin
Niklas L21-Oct-11 3:21
Niklas L21-Oct-11 3:21 
AnswerRe: vString Pin
Tyler Elric21-Oct-11 4:20
Tyler Elric21-Oct-11 4:20 
GeneralRe: vString Pin
Niklas L23-Oct-11 8:14
Niklas L23-Oct-11 8:14 
GeneralRe: vString Pin
Tyler Elric23-Oct-11 8:39
Tyler Elric23-Oct-11 8:39 
GeneralRe: vString Pin
Niklas L24-Oct-11 22:28
Niklas L24-Oct-11 22:28 
QuestionRegarding IntelliTrace equivalent tool in C++ Pin
ramana.g20-Oct-11 12:54
ramana.g20-Oct-11 12:54 
AnswerRe: Regarding IntelliTrace equivalent tool in C++ Pin
Luc Pattyn20-Oct-11 14:19
sitebuilderLuc Pattyn20-Oct-11 14:19 
GeneralRe: Regarding IntelliTrace equivalent tool in C++ Pin
Philippe Mori20-Oct-11 16:24
Philippe Mori20-Oct-11 16:24 
AnswerRe: Regarding IntelliTrace equivalent tool in C++ Pin
Erudite_Eric20-Oct-11 20:20
Erudite_Eric20-Oct-11 20:20 
AnswerRe: Regarding IntelliTrace equivalent tool in C++ Pin
Stefan_Lang21-Oct-11 2:37
Stefan_Lang21-Oct-11 2:37 
AnswerRe: Regarding IntelliTrace equivalent tool in C++ Pin
Bram van Kampen21-Oct-11 16:14
Bram van Kampen21-Oct-11 16:14 
Questionprogramming in c++ Pin
maheen zahra20-Oct-11 6:09
maheen zahra20-Oct-11 6:09 
AnswerRe: programming in c++ Pin
Richard MacCutchan20-Oct-11 7:17
mveRichard MacCutchan20-Oct-11 7:17 
AnswerRe: programming in c++ Pin
Albert Holguin20-Oct-11 7:18
professionalAlbert Holguin20-Oct-11 7:18 
AnswerRe: programming in c++ Pin
Erudite_Eric20-Oct-11 7:28
Erudite_Eric20-Oct-11 7:28 
GeneralRe: programming in c++ Pin
Albert Holguin20-Oct-11 9:30
professionalAlbert Holguin20-Oct-11 9:30 
GeneralRe: programming in c++ Pin
Erudite_Eric20-Oct-11 20:17
Erudite_Eric20-Oct-11 20:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.