Click here to Skip to main content
15,904,653 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: UNICODE Pin
John R. Shaw8-Jul-05 8:47
John R. Shaw8-Jul-05 8:47 
GeneralRe: UNICODE Pin
Jose Lamas Rios8-Jul-05 10:10
Jose Lamas Rios8-Jul-05 10:10 
GeneralRe: UNICODE Pin
John R. Shaw8-Jul-05 10:55
John R. Shaw8-Jul-05 10:55 
GeneralRe: UNICODE Pin
toxcct7-Jul-05 20:21
toxcct7-Jul-05 20:21 
GeneralRe: UNICODE Pin
John R. Shaw8-Jul-05 7:09
John R. Shaw8-Jul-05 7:09 
GeneralRe: UNICODE Pin
Bob Stanneveld7-Jul-05 22:03
Bob Stanneveld7-Jul-05 22:03 
GeneralRe: UNICODE Pin
John R. Shaw8-Jul-05 8:39
John R. Shaw8-Jul-05 8:39 
GeneralRe: UNICODE Pin
Bob Stanneveld9-Jul-05 5:48
Bob Stanneveld9-Jul-05 5:48 
John R. Shaw wrote:
Keep in mind that a requirement of this project (my own), is to use standard C++ only. That is it must be totally compiler independent, it needs to be usable in any C++ environment, be it Windows, Unix, etc... .

That'll be hard to accomplish since not all compilers support the standard. It will be especially hard if you compile under visual studio 6.0, since the standard support is really terrible.

John R. Shaw wrote:
The templates use various algorithms to process text and I want it to be able to to show the steps it takes in processing, as visual feedback to user (this feature can be turned on at compile time.

I don't know how you implement this, but you can implement it as a policy. Read here[^] about policy based design.

This technique is supported by the standard, but I've had some troubles with partitial template specialization on VC6.0.

If you don't want this, you can always use an observer / observable[^] pattern. I think that using this pattern is the way to go, since you completely separate display of data from the core class. This also reduces the places where you use the preprocessor to disable the view of the data. Besides that, if you need to use a different UI to display the data, you don't have to change to core class, but you just write another observer.

John R. Shaw wrote:
Which is what I am trying to do, in a compiler independent way. The feedback is in the form of text strings that must be formated based on the character type passed to the template.

Overloading here is the way to go (if you use templates), since a compiler only compiles code that you use. So the overloaded functions that are not used (the wchar_t or the char overloads for example). If you use overloading without the templates, you have to rely on the optimizer and the linker to omit the dead functions.


John R. Shaw wrote:
That is only true if you're trying to pass those wchar_t strings to functions that require char strings. You can process wchar_t all you want in a non-UNICODE program, but you would need to convert them to a displayable form if you wish to display them. How they are converted for actual display is up to the user and is of no concern of the template, it assumes that the input character type is the type required for feedback. I would not (normally) mix char and wchar_t strings in this way, and do not expect users of this template to do so either, but if they did, a template does and should not care.

Overloading should be the key here. You can use protected or private overloads for displaying the data and call thos in your template. The compiler will automatically choose the right overload. You definitly don't wan't to do some heavy compiler magic here, since this is an easy way to accomplis this.

See this code example:
// this class uses a policy to turn off observers
template <typename CharType,
          class ObserverPolicy
         >
class YourAlgorithmClass
{
public:
    // ...
    void AddObserver( Observer* pObs );
    // more observer mehtods depending on your needs
protected:
    // the overloads. The compiler will choose the right overload for
    // CharType. In the overload for wchar_t, you can convert the message
    // to a char string and call the other overload.
    //
    // You don't even need the overloads here, but you can 
    // place the overloads in the observer class
    // it's a matter of your own taste.
    void SendMessageToObservers(char* pszMessage);
    void SendMessageToObservers(wchar_t* pszMessage);

private:
    std::vector<Observer*> m_Observers;
};

// In the implementation you can use the ObserverPolicy to turn off and on
// the observers.
template <typename CharType, class ObserverPolicy>
void YourAlgorithmClass<CharType, ObserverPolicy>::SendMessageToObservers(char* pszMessage)
{   // the compiler will use this method depending on the policy.
    // if the method returns false, the function does nothing and the 
    // compiler should omit the call
    // 
    // note that I used 'should' since I don't don't if every compiler 
    // is this smart
    if( !ObserverPolicy::UseObservers() )
        return; 

    // notify observers here
}

// ...
// A policy class could look like this:
class UseObservers
{
public:
    static bool UseObservers() { return true; }
}

// or for no observers
class DontUseObservers
{
public:
    static bool UseObservers() { return false; }
}


I hope this enlightens you and helps you with your problem. Big Grin | :-D




Behind every great black man...
            ... is the police. - Conspiracy brother


Blog[^]
Generalrget r, g or b value for opengl Pin
cell517-Jul-05 16:27
cell517-Jul-05 16:27 
GeneralRe: rget r, g or b value for opengl Pin
Jose Lamas Rios7-Jul-05 16:44
Jose Lamas Rios7-Jul-05 16:44 
Generalneed help on generate report to excel Pin
firebolt777-Jul-05 16:05
firebolt777-Jul-05 16:05 
GeneralRe: need help on generate report to excel Pin
Jose Lamas Rios7-Jul-05 17:09
Jose Lamas Rios7-Jul-05 17:09 
GeneralRe: need help on generate report to excel Pin
firebolt777-Jul-05 20:03
firebolt777-Jul-05 20:03 
GeneralRe: need help on generate report to excel Pin
Jose Lamas Rios7-Jul-05 20:12
Jose Lamas Rios7-Jul-05 20:12 
GeneralRe: need help on generate report to excel Pin
firebolt777-Jul-05 20:25
firebolt777-Jul-05 20:25 
GeneralRe: need help on generate report to excel Pin
firebolt778-Jul-05 3:36
firebolt778-Jul-05 3:36 
GeneralRe: need help on generate report to excel Pin
urxlnc0077-Jul-05 19:23
urxlnc0077-Jul-05 19:23 
GeneralRe: need help on generate report to excel Pin
firebolt777-Jul-05 21:36
firebolt777-Jul-05 21:36 
GeneralHelp finding wmstub.lib Pin
Lan_Zer07-Jul-05 13:20
Lan_Zer07-Jul-05 13:20 
GeneralRe: Help finding wmstub.lib Pin
Christian Graus7-Jul-05 16:45
protectorChristian Graus7-Jul-05 16:45 
Generalgetting a correct structure data Pin
Ista7-Jul-05 12:40
Ista7-Jul-05 12:40 
GeneralRe: getting a correct structure data Pin
ldaoust7-Jul-05 15:12
ldaoust7-Jul-05 15:12 
GeneralMemory for my application Pin
Ivan Cachicatari7-Jul-05 11:50
Ivan Cachicatari7-Jul-05 11:50 
GeneralRe: Memory for my application Pin
David Crow7-Jul-05 13:25
David Crow7-Jul-05 13:25 
GeneralCListCtrl problem Pin
Ivan Cachicatari7-Jul-05 11:47
Ivan Cachicatari7-Jul-05 11:47 

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.