Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue making Ice::Value the same for the Original and New mappings #1666

Merged
merged 21 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions cpp/include/Ice/DefaultValueFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
namespace IceInternal
{

#ifdef ICE_CPP11_MAPPING

template<class V>
::std::shared_ptr<::Ice::Value>
#ifdef NDEBUG
Expand All @@ -25,33 +23,5 @@ defaultValueFactory(const std::string& typeId)
return std::make_shared<V>();
}

#else

template<class V>
class DefaultValueFactory : public Ice::ValueFactory
{
public:

DefaultValueFactory(const ::std::string& typeId) :
_typeId(typeId)
{
}

#ifndef NDEBUG
virtual ::Ice::ValuePtr create(const ::std::string& typeId)
#else
virtual ::Ice::ValuePtr create(const ::std::string&)
#endif
{
assert(typeId == _typeId);
return new V;
}

private:
const ::std::string _typeId;
};

#endif

}
#endif
2 changes: 1 addition & 1 deletion cpp/include/Ice/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace IceInternal
namespace Ex
{

ICE_API void throwUOE(const ::std::string&, const ::Ice::ValuePtr&);
ICE_API void throwUOE(const ::std::string&, const std::shared_ptr<Ice::Value>&);
ICE_API void throwMemoryLimitException(const char*, int, size_t, size_t);
ICE_API void throwMarshalException(const char*, int, const std::string&);

Expand Down
6 changes: 3 additions & 3 deletions cpp/include/Ice/FactoryTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class ICE_API FactoryTable : private IceUtil::noncopyable
ICE_DELEGATE(::Ice::UserExceptionFactory) getExceptionFactory(const ::std::string&) const;
void removeExceptionFactory(const ::std::string&);

void addValueFactory(const ::std::string&, ICE_IN(ICE_DELEGATE(::Ice::ValueFactory)));
ICE_DELEGATE(::Ice::ValueFactory) getValueFactory(const ::std::string&) const;
void addValueFactory(const ::std::string&, ::Ice::ValueFactoryFunc);
::Ice::ValueFactoryFunc getValueFactory(const ::std::string&) const;
void removeValueFactory(const ::std::string&);

void addTypeId(int, const ::std::string&);
Expand All @@ -59,7 +59,7 @@ class ICE_API FactoryTable : private IceUtil::noncopyable
typedef ::std::map< ::std::string, EFPair> EFTable;
EFTable _eft;

typedef ::std::pair< ICE_DELEGATE(::Ice::ValueFactory), int> VFPair;
typedef ::std::pair<::Ice::ValueFactoryFunc, int> VFPair;
typedef ::std::map< ::std::string, VFPair> VFTable;
VFTable _vft;

Expand Down
4 changes: 0 additions & 4 deletions cpp/include/Ice/FactoryTableInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ class DefaultValueFactoryInit

DefaultValueFactoryInit(const char* tId) : typeId(tId)
{
#ifdef ICE_CPP11_MAPPING
factoryTable->addValueFactory(typeId, defaultValueFactory<O>);
#else
factoryTable->addValueFactory(typeId, new DefaultValueFactory<O>(typeId));
#endif
}

~DefaultValueFactoryInit()
Expand Down
42 changes: 20 additions & 22 deletions cpp/include/Ice/InputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,14 @@ class UserException;

/// \cond INTERNAL
template<typename T> inline void
patchHandle(void* addr, const ValuePtr& v)
patchValue(void* addr, const std::shared_ptr<Value>& v)
{
#ifdef ICE_CPP11_MAPPING
::std::shared_ptr<T>* handle = static_cast<::std::shared_ptr<T>*>(addr);
*handle = ::std::dynamic_pointer_cast<T>(v);
if(v && !(*handle))
std::shared_ptr<T>* ptr = static_cast<::std::shared_ptr<T>*>(addr);
*ptr = ::std::dynamic_pointer_cast<T>(v);
if(v && !(*ptr))
{
IceInternal::Ex::throwUOE(T::ice_staticId(), v);
}
#else
SharedPtr<T>* p = static_cast<SharedPtr<T>*>(addr);
_icePatchValuePtr(*p, v); // Generated _icePatchValuePtr function, necessary for forward declarations.
#endif
}
/// \endcond

Expand All @@ -57,7 +52,7 @@ class ICE_API InputStream : public IceInternal::Buffer
* @param addr The target address.
* @param v The unmarshaled value.
*/
typedef void (*PatchFunc)(void* addr, const ValuePtr& v);
using PatchFunc = std::function<void(void* addr, const std::shared_ptr<Value>& v)>;

/**
* Constructs a stream using the latest encoding version but without a communicator.
Expand Down Expand Up @@ -1074,21 +1069,24 @@ class ICE_API InputStream : public IceInternal::Buffer
#endif

/**
* Reads a value (instance of a Slice class) from the stream.
* Reads a value (instance of a Slice class) from the stream (New mapping).
* @param v The instance.
*/
#ifdef ICE_CPP11_MAPPING // C++11 mapping
template<typename T, typename ::std::enable_if<::std::is_base_of<Value, T>::value>::type* = nullptr>
void read(::std::shared_ptr<T>& v)
{
read(&patchHandle<T>, &v);
read(patchValue<T>, &v);
}
#else // C++98 mapping
template<typename T> void read(Ice::SharedPtr<T>& v)

/**
* Reads a value (instance of a Slice class) from the stream (Original mapping).
* @param v The instance.
*/
template<typename T, typename ::std::enable_if<::std::is_base_of<Value, T>::value>::type* = nullptr>
void read(Ice::SharedPtr<T>& v)
{
read(&patchHandle<T>, &v);
read(patchValue<T>, &v.underlying());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"addr" points the to shared_ptr inside the SharedPtr smart pointer.

}
#endif

/**
* Reads a value (instance of a Slice class) from the stream.
Expand Down Expand Up @@ -1201,7 +1199,7 @@ class ICE_API InputStream : public IceInternal::Buffer

std::string resolveCompactId(int) const;

void postUnmarshal(const ValuePtr&) const;
void postUnmarshal(const std::shared_ptr<Value>&) const;

class Encaps;
enum SliceType { NoSlice, ValueSlice, ExceptionSlice };
Expand All @@ -1218,7 +1216,7 @@ class ICE_API InputStream : public IceInternal::Buffer
CompactIdResolverPtr compactIdResolver() const;
#endif

typedef std::vector<ValuePtr> ValueList;
typedef std::vector<std::shared_ptr<Value>> ValueList;

class ICE_API EncapsDecoder : private ::IceUtil::noncopyable
{
Expand Down Expand Up @@ -1254,12 +1252,12 @@ class ICE_API InputStream : public IceInternal::Buffer
}

std::string readTypeId(bool);
ValuePtr newInstance(const std::string&);
std::shared_ptr<Value> newInstance(const std::string&);

void addPatchEntry(Int, PatchFunc, void*);
void unmarshal(Int, const ValuePtr&);
void unmarshal(Int, const std::shared_ptr<Value>&);

typedef std::map<Int, ValuePtr> IndexToPtrMap;
typedef std::map<Int, std::shared_ptr<Value>> IndexToPtrMap;
typedef std::map<Int, std::string> TypeIdMap;

struct PatchEntry
Expand Down
39 changes: 10 additions & 29 deletions cpp/include/Ice/OutputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@

#include <Ice/CommunicatorF.h>
#include <Ice/InstanceF.h>

// TODO: temporary
#ifdef ICE_CPP11_MAPPING
# include <Ice/ValueF.h>
#else
# include <Ice/Value.h>
#endif

#include <Ice/ValueF.h>
#include <Ice/ProxyF.h>
#include <Ice/Buffer.h>
#include <Ice/Protocol.h>
Expand Down Expand Up @@ -784,7 +777,6 @@ class ICE_API OutputStream : public IceInternal::Buffer
}
#endif

#ifdef ICE_CPP11_MAPPING // C++11 mapping
/**
* Writes a value instance to the stream.
* @param v The value to be written.
Expand All @@ -795,26 +787,15 @@ class ICE_API OutputStream : public IceInternal::Buffer
initEncaps();
_currentEncaps->encoder->write(v);
}
#else // C++98 mapping
/**
* Writes a value instance to the stream.
* @param v The value to be written.
*/
void write(const ValuePtr& v)
{
initEncaps();
_currentEncaps->encoder->write(v);
}

#
/**
* Writes a value instance to the stream.
* @param v The value to be written.
*/
template<typename T> void write(const Ice::SharedPtr<T>& v)
{
write(ValuePtr(v));
write(v.underlying());
}
#endif

/**
* Writes an enumerator to the stream.
Expand Down Expand Up @@ -899,15 +880,15 @@ class ICE_API OutputStream : public IceInternal::Buffer
class Encaps;
enum SliceType { NoSlice, ValueSlice, ExceptionSlice };

typedef std::vector<ValuePtr> ValueList;
typedef std::vector<std::shared_ptr<Value>> ValueList;

class ICE_API EncapsEncoder : private ::IceUtil::noncopyable
{
public:

virtual ~EncapsEncoder();

virtual void write(const ValuePtr&) = 0;
virtual void write(const std::shared_ptr<Value>&) = 0;
virtual void write(const UserException&) = 0;

virtual void startInstance(SliceType, const SlicedDataPtr&) = 0;
Expand Down Expand Up @@ -935,7 +916,7 @@ class ICE_API OutputStream : public IceInternal::Buffer
OutputStream* _stream;
Encaps* _encaps;

typedef std::map<ValuePtr, Int> PtrToIndexMap;
typedef std::map<std::shared_ptr<Value>, Int> PtrToIndexMap;
typedef std::map<std::string, Int> TypeIdMap;

// Encapsulation attributes for value marshaling.
Expand All @@ -957,7 +938,7 @@ class ICE_API OutputStream : public IceInternal::Buffer
{
}

virtual void write(const ValuePtr&);
virtual void write(const std::shared_ptr<Value>&);
virtual void write(const UserException&);

virtual void startInstance(SliceType, const SlicedDataPtr&);
Expand All @@ -969,7 +950,7 @@ class ICE_API OutputStream : public IceInternal::Buffer

private:

Int registerValue(const ValuePtr&);
Int registerValue(const std::shared_ptr<Value>&);

// Instance attributes
SliceType _sliceType;
Expand All @@ -991,7 +972,7 @@ class ICE_API OutputStream : public IceInternal::Buffer
{
}

virtual void write(const ValuePtr&);
virtual void write(const std::shared_ptr<Value>&);
virtual void write(const UserException&);

virtual void startInstance(SliceType, const SlicedDataPtr&);
Expand All @@ -1004,7 +985,7 @@ class ICE_API OutputStream : public IceInternal::Buffer
private:

void writeSlicedData(const SlicedDataPtr&);
void writeInstance(const ValuePtr&);
void writeInstance(const std::shared_ptr<Value>&);

struct InstanceData
{
Expand Down
47 changes: 11 additions & 36 deletions cpp/include/Ice/SlicedData.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ namespace Ice
* \headerfile Ice/Ice.h
*/
struct ICE_API SliceInfo
#ifndef ICE_CPP11_MAPPING
: public ::IceUtil::Shared
#endif
{
/**
* The Slice type ID for this slice.
*/
::std::string typeId;
std::string typeId;

/**
* The Slice compact type ID for this slice.
Expand All @@ -33,12 +30,12 @@ struct ICE_API SliceInfo
/**
* The encoded bytes for this slice, including the leading size integer.
*/
::std::vector<Byte> bytes;
std::vector<Byte> bytes;

/**
* The class instances referenced by this slice.
*/
::std::vector<ValuePtr> instances;
std::vector<std::shared_ptr<Value>> instances;

/**
* Whether or not the slice contains optional members.
Expand All @@ -56,16 +53,9 @@ struct ICE_API SliceInfo
* \headerfile Ice/Ice.h
*/
class ICE_API SlicedData
#ifndef ICE_CPP11_MAPPING
: public ::IceUtil::Shared
#endif
{
public:

#ifndef ICE_CPP11_MAPPING
virtual ~SlicedData();
#endif

SlicedData(const SliceInfoSeq&);

/** The slices of unknown types. */
Expand All @@ -91,7 +81,6 @@ class ICE_API UnknownSlicedValue : public Value
*/
UnknownSlicedValue(const std::string& unknownTypeId);

#ifdef ICE_CPP11_MAPPING
/**
* Obtains the sliced data associated with this instance.
* @return The sliced data if the value has a preserved-slice base class and has been sliced during
Expand All @@ -109,7 +98,14 @@ class ICE_API UnknownSlicedValue : public Value
* Clones this object.
* @return A new instance.
*/
std::shared_ptr<UnknownSlicedValue> ice_clone() const;
UnknownSlicedValuePtr ice_clone() const
{
#ifdef ICE_CPP11_MAPPING
return std::static_pointer_cast<UnknownSlicedValue>(_iceCloneImpl());
#else
return UnknownSlicedValuePtr(std::static_pointer_cast<UnknownSlicedValue>(_iceCloneImpl()));
#endif
}

/// \cond STREAM
virtual void _iceWrite(::Ice::OutputStream*) const override;
Expand All @@ -122,27 +118,6 @@ class ICE_API UnknownSlicedValue : public Value
virtual std::shared_ptr<Value> _iceCloneImpl() const override;
/// \endcond

#else

/**
* Obtains the sliced data associated with this instance.
* @return The sliced data if the value has a preserved-slice base class and has been sliced during
* unmarshaling of the value, or nil otherwise.
*/
virtual SlicedDataPtr ice_getSlicedData() const;

/**
* Determine the Slice type ID associated with this instance.
* @return The type ID supplied to the constructor.
*/
virtual std::string ice_id() const;

/// \cond STREAM
virtual void _iceWrite(::Ice::OutputStream*) const;
virtual void _iceRead(::Ice::InputStream*);
/// \endcond
#endif

private:

const std::string _unknownTypeId;
Expand Down
Loading
Loading