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

More string API updates #3006

Merged
merged 13 commits into from
Oct 30, 2024
30 changes: 14 additions & 16 deletions cpp/include/Ice/Communicator.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
// Copyright (c) ZeroC, Inc.

#ifndef ICE_COMMUNICATOR_H
#define ICE_COMMUNICATOR_H
Expand Down Expand Up @@ -86,7 +84,7 @@ namespace Ice
* @see #proxyToString
*/
template<typename Prx = ObjectPrx, std::enable_if_t<std::is_base_of<ObjectPrx, Prx>::value, bool> = true>
std::optional<Prx> stringToProxy(const std::string& str) const
std::optional<Prx> stringToProxy(std::string_view str) const
{
auto reference = _stringToProxy(str);
if (reference)
Expand Down Expand Up @@ -118,7 +116,7 @@ namespace Ice
* @return The proxy, or nullopt if the property is not set.
*/
template<typename Prx = ObjectPrx, std::enable_if_t<std::is_base_of<ObjectPrx, Prx>::value, bool> = true>
std::optional<Prx> propertyToProxy(const std::string& property) const
std::optional<Prx> propertyToProxy(std::string_view property) const
{
auto reference = _propertyToProxy(property);
if (reference)
Expand All @@ -137,7 +135,7 @@ namespace Ice
* @param property The base property name.
* @return The property set.
*/
PropertyDict proxyToProperty(const std::optional<ObjectPrx>& proxy, const std::string& property) const;
PropertyDict proxyToProperty(const std::optional<ObjectPrx>& proxy, std::string property) const;

/**
* Convert an identity into a string.
Expand Down Expand Up @@ -167,8 +165,8 @@ namespace Ice

*/
ObjectAdapterPtr createObjectAdapter(
const std::string& name,
const std::optional<SSL::ServerAuthenticationOptions>& serverAuthenticationOptions = std::nullopt);
std::string name,
std::optional<SSL::ServerAuthenticationOptions> serverAuthenticationOptions = std::nullopt);

/**
* Create a new object adapter with endpoints. This operation sets the property
Expand All @@ -189,9 +187,9 @@ namespace Ice
* @see SSL::SchannelServerAuthenticationOptions
*/
ObjectAdapterPtr createObjectAdapterWithEndpoints(
const std::string& name,
const std::string& endpoints,
const std::optional<SSL::ServerAuthenticationOptions>& serverAuthenticationOptions = std::nullopt);
std::string name,
std::string_view endpoints,
std::optional<SSL::ServerAuthenticationOptions> serverAuthenticationOptions = std::nullopt);

/**
* Create a new object adapter with a router. This operation creates a routed object adapter.
Expand All @@ -203,7 +201,7 @@ namespace Ice
* @see ObjectAdapter
* @see Properties
*/
ObjectAdapterPtr createObjectAdapterWithRouter(const std::string& name, const RouterPrx& rtr);
ObjectAdapterPtr createObjectAdapterWithRouter(std::string name, RouterPrx rtr);

/**
* Gets the object adapter that is associated by default with new outgoing connections created by this
Expand Down Expand Up @@ -367,22 +365,22 @@ namespace Ice
* @param servant The servant that implements the new Admin facet.
* @param facet The name of the new Admin facet.
*/
void addAdminFacet(const ObjectPtr& servant, const std::string& facet);
void addAdminFacet(ObjectPtr servant, std::string facet);

/**
* Remove the following facet to the Admin object. Removing a facet that was not previously registered throws
* NotRegisteredException.
* @param facet The name of the Admin facet.
* @return The servant associated with this Admin facet.
*/
ObjectPtr removeAdminFacet(const std::string& facet);
ObjectPtr removeAdminFacet(std::string_view facet);

/**
* Returns a facet of the Admin object.
* @param facet The name of the Admin facet.
* @return The servant associated with this Admin facet, or null if no facet is registered with the given name.
*/
ObjectPtr findAdminFacet(const std::string& facet);
ObjectPtr findAdminFacet(std::string_view facet);

/**
* Returns a map of all facets of the Admin object.
Expand All @@ -403,7 +401,7 @@ namespace Ice
void finishSetup(int&, const char*[]);

IceInternal::ReferencePtr _stringToProxy(std::string_view str) const;
IceInternal::ReferencePtr _propertyToProxy(const std::string& property) const;
IceInternal::ReferencePtr _propertyToProxy(std::string_view property) const;

friend ICE_API CommunicatorPtr initialize(int&, const char*[], const InitializationData&);
friend ICE_API CommunicatorPtr initialize(StringSeq&, const InitializationData&);
Expand Down
8 changes: 4 additions & 4 deletions cpp/include/Ice/ImplicitContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace Ice
* @param key The key.
* @return True if the key has an associated value, False otherwise.
*/
bool containsKey(const std::string& key) const;
bool containsKey(std::string_view key) const;

/**
* Get the value associated with the given key in the underlying context. Returns an empty string if no value is
Expand All @@ -61,22 +61,22 @@ namespace Ice
* @param key The key.
* @return The value associated with the key.
*/
std::string get(const std::string& key) const;
std::string get(std::string_view key) const;

/**
* Create or update a key/value entry in the underlying context.
* @param key The key.
* @param value The value.
* @return The previous value associated with the key, if any.
*/
std::string put(const std::string& key, const std::string& value);
std::string put(std::string key, std::string value);

/**
* Remove the entry for the given key in the underlying context.
* @param key The key.
* @return The value associated with the key, if any.
*/
std::string remove(const std::string& key);
std::string remove(std::string_view key);

/**
* Marshals the underlying context plus the given context. Entries in the given context overwrite entries in the
Expand Down
16 changes: 8 additions & 8 deletions cpp/include/Ice/Initialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ namespace Ice
* @param configFile The name of an Ice configuration file.
* @return The new communicator.
*/
ICE_API CommunicatorPtr initialize(int& argc, const char* argv[], const std::string& configFile);
ICE_API CommunicatorPtr initialize(int& argc, const char* argv[], std::string_view configFile);

/**
* Initializes a new communicator.
Expand All @@ -410,7 +410,7 @@ namespace Ice
* @param configFile The name of an Ice configuration file.
* @return The new communicator.
*/
inline CommunicatorPtr initialize(int& argc, char* argv[], const std::string& configFile)
inline CommunicatorPtr initialize(int& argc, char* argv[], std::string_view configFile)
{
return initialize(argc, const_cast<const char**>(argv), configFile);
}
Expand Down Expand Up @@ -464,7 +464,7 @@ namespace Ice
* @param configFile The name of an Ice configuration file.
* @return The new communicator.
*/
ICE_API CommunicatorPtr initialize(int& argc, const wchar_t* argv[], const std::string& configFile);
ICE_API CommunicatorPtr initialize(int& argc, const wchar_t* argv[], std::string_view configFile);

/**
* Initializes a new communicator.
Expand All @@ -479,7 +479,7 @@ namespace Ice
* @param configFile The name of an Ice configuration file.
* @return The new communicator.
*/
inline CommunicatorPtr initialize(int& argc, wchar_t* argv[], const std::string& configFile)
inline CommunicatorPtr initialize(int& argc, wchar_t* argv[], std::string_view configFile)
{
return initialize(argc, const_cast<const wchar_t**>(argv), configFile);
}
Expand Down Expand Up @@ -509,7 +509,7 @@ namespace Ice
* @param configFile The name of an Ice configuration file.
* @return The new communicator.
*/
ICE_API CommunicatorPtr initialize(StringSeq& seq, const std::string& configFile);
ICE_API CommunicatorPtr initialize(StringSeq& seq, std::string_view configFile);

/**
* Initializes a new communicator.
Expand All @@ -523,7 +523,7 @@ namespace Ice
* @param configFile The name of an Ice configuration file.
* @return The new communicator.
*/
ICE_API CommunicatorPtr initialize(const std::string& configFile);
ICE_API CommunicatorPtr initialize(std::string_view configFile);

/**
* Obtains the per-process logger. This logger is used by all communicators that do not have their
Expand Down Expand Up @@ -557,7 +557,7 @@ namespace Ice
* even if Ice.Plugin.name is not set. When false, the plug-in is loaded (created) during communication
* initialization only if Ice.Plugin.name is set to a non-empty value (e.g.: Ice.Plugin.IceSSL=1).
*/
ICE_API void registerPluginFactory(const std::string& name, PluginFactory factory, bool loadOnInit);
ICE_API void registerPluginFactory(std::string name, PluginFactory factory, bool loadOnInit);

/**
* A helper class that uses Resource Acquisition Is Initialization (RAII) to initialize and hold a
Expand Down Expand Up @@ -640,7 +640,7 @@ namespace Ice
* @param str The stringified identity.
* @return An Identity structure containing the name and category components.
*/
ICE_API Identity stringToIdentity(const std::string& str);
ICE_API Identity stringToIdentity(std::string_view str);

/**
* Converts an Identity structure into a string using the specified mode.
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/Ice/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ namespace Ice
* @return The plug-in.
* @throws NotRegisteredException Raised if no plug-in is found with the given name.
*/
virtual PluginPtr getPlugin(const std::string& name) = 0;
virtual PluginPtr getPlugin(std::string_view name) = 0;

/**
* Install a new plug-in.
* @param name The plug-in's name.
* @param pi The plug-in.
* @throws AlreadyRegisteredException Raised if a plug-in already exists with the given name.
*/
virtual void addPlugin(const std::string& name, const PluginPtr& pi) = 0;
virtual void addPlugin(std::string name, PluginPtr pi) = 0;

/**
* Called when the communicator is being destroyed.
Expand Down
7 changes: 5 additions & 2 deletions cpp/include/Ice/StringUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ namespace IceInternal
// Remove escape sequences added by escapeString. Throws std::invalid_argument
// for an invalid input string.
//
ICE_API std::string
unescapeString(const std::string&, std::string::size_type, std::string::size_type, std::string_view special);
ICE_API std::string unescapeString(
std::string_view,
std::string_view::size_type,
std::string_view::size_type,
std::string_view special);

//
// Split a string using the given delimiters. Considers single and double quotes;
Expand Down
54 changes: 29 additions & 25 deletions cpp/src/Ice/Communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ Ice::Communicator::proxyToString(const std::optional<ObjectPrx>& proxy) const
}

ReferencePtr
Ice::Communicator::_propertyToProxy(const string& p) const
Ice::Communicator::_propertyToProxy(string_view p) const
{
string proxy = _instance->initializationData().properties->getProperty(p);
return _instance->referenceFactory()->create(proxy, p);
return _instance->referenceFactory()->create(proxy, string{p});
}

PropertyDict
Ice::Communicator::proxyToProperty(const std::optional<ObjectPrx>& proxy, const string& property) const
Ice::Communicator::proxyToProperty(const std::optional<ObjectPrx>& proxy, string property) const
{
return proxy ? proxy->_getReference()->toProperty(property) : PropertyDict();
return proxy ? proxy->_getReference()->toProperty(std::move(property)) : PropertyDict();
}

string
Expand All @@ -112,44 +112,48 @@ Ice::Communicator::identityToString(const Identity& ident) const

ObjectAdapterPtr
Ice::Communicator::createObjectAdapter(
const string& name,
const optional<SSL::ServerAuthenticationOptions>& serverAuthenticationOptions)
string name,
optional<SSL::ServerAuthenticationOptions> serverAuthenticationOptions)
{
return _instance->objectAdapterFactory()->createObjectAdapter(name, nullopt, serverAuthenticationOptions);
return _instance->objectAdapterFactory()->createObjectAdapter(
std::move(name),
nullopt,
std::move(serverAuthenticationOptions));
}

ObjectAdapterPtr
Ice::Communicator::createObjectAdapterWithEndpoints(
const string& name,
const string& endpoints,
const optional<SSL::ServerAuthenticationOptions>& serverAuthenticationOptions)
string name,
string_view endpoints,
optional<SSL::ServerAuthenticationOptions> serverAuthenticationOptions)
{
string oaName = name;
if (oaName.empty())
if (name.empty())
{
oaName = Ice::generateUUID();
name = Ice::generateUUID();
}

getProperties()->setProperty(oaName + ".Endpoints", endpoints);
return _instance->objectAdapterFactory()->createObjectAdapter(oaName, nullopt, serverAuthenticationOptions);
getProperties()->setProperty(name + ".Endpoints", endpoints);
return _instance->objectAdapterFactory()->createObjectAdapter(
std::move(name),
nullopt,
std::move(serverAuthenticationOptions));
}

ObjectAdapterPtr
Ice::Communicator::createObjectAdapterWithRouter(const string& name, const RouterPrx& router)
Ice::Communicator::createObjectAdapterWithRouter(string name, RouterPrx router)
{
string oaName = name;
if (oaName.empty())
if (name.empty())
{
oaName = Ice::generateUUID();
name = Ice::generateUUID();
}

PropertyDict properties = proxyToProperty(router, oaName + ".Router");
PropertyDict properties = proxyToProperty(router, name + ".Router");
for (PropertyDict::const_iterator p = properties.begin(); p != properties.end(); ++p)
{
getProperties()->setProperty(p->first, p->second);
}

return _instance->objectAdapterFactory()->createObjectAdapter(oaName, router, nullopt);
return _instance->objectAdapterFactory()->createObjectAdapter(std::move(name), std::move(router), nullopt);
}

ObjectAdapterPtr
Expand Down Expand Up @@ -267,19 +271,19 @@ Ice::Communicator::getAdmin() const
}

void
Ice::Communicator::addAdminFacet(const ObjectPtr& servant, const string& facet)
Ice::Communicator::addAdminFacet(ObjectPtr servant, string facet)
{
_instance->addAdminFacet(servant, facet);
_instance->addAdminFacet(std::move(servant), std::move(facet));
}

ObjectPtr
Ice::Communicator::removeAdminFacet(const string& facet)
Ice::Communicator::removeAdminFacet(string_view facet)
{
return _instance->removeAdminFacet(facet);
}

ObjectPtr
Ice::Communicator::findAdminFacet(const string& facet)
Ice::Communicator::findAdminFacet(string_view facet)
{
return _instance->findAdminFacet(facet);
}
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/Ice/HashUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ namespace IceInternal
}
}

inline void hashAdd(std::size_t& hashCode, const std::map<std::string, std::string>& map)
// For Ice::Context
inline void hashAdd(std::size_t& hashCode, const std::map<std::string, std::string, std::less<>>& map)
{
for (const auto& p : map)
{
Expand Down
Loading
Loading