Alf P. Steinbach napisal(a):
That doesn't make much sense.
Most probably you have a case of Premature Optimization, where every
which way you're turning the language rules seem to try to stop you
(because they're designed for meaningful code).
Perhaps post a small program that compiles and illustrates what you're
trying to do.
There are plenty of files, classes and interfaces. Following are the
most close to the problem, I think:
<code file="Operators.h">
Core::ILogMessage & operator << (Core::ILogMessage & msg,
const Impl::Serialization::ValueType::Byte & value);
Core::ILogMessage & operator << (Core::ILogMessage & msg,
const Impl::Serialization::ValueType::Int16 & value);
Core::ILogMessage & operator << (Core::ILogMessage & msg,
const Impl::Serialization::ValueType::Int32 & value);
Core::ILogMessage & operator << (Core::ILogMessage & msg,
const Impl::Serialization::ValueType::String & value);
Core::ILogMessage & operator << (Core::ILogMessage & msg,
const Impl::Serialization::ValueType::UInt16 & value);
Core::ILogMessage & operator << (Core::ILogMessage & msg,
const Impl::Serialization::ValueType::UInt32 & value);
</code>
There are more operators for more types - I've removed them from an
example...
<code file="Operators.cpp">
Core::ILogMessage & operator << (Core::ILogMessage & msg,
const Impl::Serialization::ValueType::Int16 & value)
{
msg.add(value);
return msg;
}
Core::ILogMessage & operator << (Core::ILogMessage & msg,
const Impl::Serialization::ValueType::Int32 & value)
{
msg.add(value);
return msg;
}
</code>
<code file="ILogMessage.h">
namespace Core
{
class ILogMessage : virtual public Core::Serialization::ISerializable
{
public:
virtual void add(const Core::Serialization::ISerializable & obj) = 0;
};
}
</code>
<code file="Int16.h">
namespace Impl
{
namespace Serialization
{
namespace ValueType
{
class Int16 : public Core::Serialization::ISerializable
{
short value;
public:
Int16(const short _value);
// Serializes object's data into a given stream
void serialize(Core::Serialization::IWriteStream *stream) const;
// Deserializes all object's data from a given stream
void deserialize(Core::Serialization::IReadStream *stream);
};
}
}
}
</code>
<code file="Int32.h>
namespace Impl
{
namespace Serialization
{
namespace ValueType
{
class Int32 : public Core::Serialization::ISerializable
{
long value;
public:
Int32(int _value);
// Serializes object's data into a given stream
void serialize(Core::Serialization::IWriteStream *stream) const;
// Deserializes all object's data from a given stream
void deserialize(Core::Serialization::IReadStream *stream);
};
}
}
}
</code>
There are also other types being defined identically as follows:
Byte - unsigned char
String - char *
UInt16 - unsigned short
UInt32 - unsigned long
Then I have a main file with following code:
<code file="Main.cpp">
Core::ILog * log = Impl::LogManager::get()->getLog("main");
for(unsigned long i = 0; i < 10000; ++i)
{
log->addLogEntry(Impl::Critical, &(Impl::Msg::ErrorMsg("Error %i, %s")
<< i )); // <=== There MUST be conversion.
}
</code>
Let me clarify the add() method in the ILogMessage interface
implementation that exists in the project. It stores passed parametes
as a pointer in the internal array of ISerializable pointers. Because
there is a constraint in the ILog interface implementation that stops
processing if the logging level is insufficient at the moment. Thus I
don't want to make any other activity than just temporarily store
passed arguments. They will be used if necessary.
Why on the stack? Because addLogEntry() method is to be invoked
extreamly often and operator new() introduces too much cost for
managing the arguments as well as it wuld introduce high heap
fragmentation.
If this description is insufficient for you I can prepare some small
demo project but it might cost some effort I want to avoid :|
Thanks for your attention