Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 23 Jan 2010
Offline Last Active Oct 16 2012 09:57 AM

Posts I've Made

In Topic: Singleton with dynamicalli linked methods ?

18 May 2011 - 01:15 PM

The idea is to have this functions to behave like normal methods of singleton. So they can operate on protected variables etc. without using getters and setters methods. I want to have interface that will be thesame from the programmer point of view but be implemented by specific functions depending on which version or extension of OpenGL is supported. When you want to use OpenGL greater than 1.1 or any extension under Windows you first need to bind each OpenGL function to it's pointer. When you do this you check if each version or extension is supported before binding functions corresponding to it. I would like to have singleton with abstract interface that would cover all that versions and extensions with one, intermediate and abstract API supported by it's methods. Therefore for each method I want to have set of specified functions that will cover it's behavior in the best way on different OpenGL versions. This is why I am searching for such mechanism to allow external functions to work on protected stuctures and data of Rendering Context singleton (or some alternative to that singleton).

I think idea of covering all global data in some source file would be great but I think it will be too much code to hide it in only one cpp.

In Topic: Singleton with dynamicalli linked methods ?

18 May 2011 - 04:46 AM

You must "friend" individual functions, you cannot friend a function pointer. Why not write the function pointer to take a float as an argument, and have the layout pass the value to the function? Or if all possible implementations are going to add "layout::var" to some constant, you could write them to return their "modifier", and then layout::pointSizeMin could add the modifier to the "var" value.

Also consider not using singletons, they are widely considered to be a bad idea, a glorified global variable. Your layout::var could be a member variable instead of a static. Also, it could have a much better name.

This is just code sample, not the actual code implementation. Layout class is inheriting after singleton template which makes it singleton , to make it simpler I just set "var" as static to give a point of singleton. I want to create layout for my rendering context that could choose which functions to use depending on which version and/or extensions of OpenGL are supported. From the programmer way I will always have the same layout though.

In Topic: Problem with overloaded <<, endl, cout and ofstream

13 February 2011 - 08:21 AM

Isn't working means, is not making anything. There is just no new line in dumped file. Everything is glued together.

RESOLVED: I was searching error in wrong place. endl templating wasn't a problem, it was ios::binary operator during file opening :/. So your code also wouldn't work edd2.

In Topic: Problem with overloaded <<, endl, cout and ofstream

13 February 2011 - 07:48 AM

Ok, but won't it be slower to use additional buffer streambuf and performing rdbuf ? I really would like to close it into log interface to be invisible from programmer side.

The 'proper' way to do this is with a stream buffer, not a wrapper class.

#include <fstream>
// ...

std::filebuf fb;
fb.open("log.txt", std::ios::out | std::ios::app | std::ios::binary);

std::streambuf *old_clog_buf = 0;

if (fb.is_open())
   old_clog_buf = std::clog.rdbuf(&fb);

std::clog << "This should appear in log.txt" << std::endl;

if (old_clog_buf)

Also changing m_output type from ofstream to fstream that is opened like this:

m_output = new fstream(path.c_str(), ios::out | ios::binary | ios::ate);

Resolved problem with line:

*m_output << "<!>";

Which now works properly, but calling this:

*m_output << endl;


m_output->put( m_output->widen('\n') );


*m_output << '\n';


Still isn't working. Does somebody knows why?