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

Merge Properties and PropertiesI, switch to string_view #1914

Merged
merged 5 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"typeinfo": "cpp",
"unordered_map": "cpp",
"variant": "cpp",
"algorithm": "cpp"
"algorithm": "cpp",
"xtree": "cpp"
},
"C_Cpp.default.cppStandard": "c++20"
}
5 changes: 4 additions & 1 deletion cpp/include/Ice/Communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
#include "Initialize.h"
#include "PluginF.h"
#include "Properties.h"
#include "ProxyF.h"
#include "Proxy.h"
Copy link
Member Author

Choose a reason for hiding this comment

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

My cleanup of the headers included by Properties.h revealed a bug in this include list.


namespace Ice
{

class LocatorPrx;
class RouterPrx;

/**
* The central object in Ice. One or more communicators can be instantiated for an Ice application.
* @see Logger
Expand Down
10 changes: 5 additions & 5 deletions cpp/include/Ice/Initialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ICE_API PropertiesPtr createProperties();
* @return A new property set initialized with the property settings
* that were removed from the argument vector.
*/
ICE_API PropertiesPtr createProperties(StringSeq& seq, const PropertiesPtr& defaults = 0);
ICE_API PropertiesPtr createProperties(StringSeq& seq, const PropertiesPtr& defaults = nullptr);
Copy link
Member Author

Choose a reason for hiding this comment

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

I am wonder if we should just remove these functions that are now equivalent to a call to make_shared<Properties>(...)


/**
* Creates a property set initialized from command-line arguments
Expand All @@ -138,7 +138,7 @@ ICE_API PropertiesPtr createProperties(StringSeq& seq, const PropertiesPtr& defa
* @return A new property set initialized with the property settings
* that were removed from the argument vector.
*/
ICE_API PropertiesPtr createProperties(int& argc, const char* argv[], const PropertiesPtr& defaults = 0);
ICE_API PropertiesPtr createProperties(int& argc, const char* argv[], const PropertiesPtr& defaults = nullptr);

/**
* Creates a property set initialized from command-line arguments
Expand All @@ -159,7 +159,7 @@ ICE_API PropertiesPtr createProperties(int& argc, const char* argv[], const Prop
* @return A new property set initialized with the property settings
* that were removed from the argument vector.
*/
inline PropertiesPtr createProperties(int& argc, char* argv[], const PropertiesPtr& defaults = 0)
inline PropertiesPtr createProperties(int& argc, char* argv[], const PropertiesPtr& defaults = nullptr)
{
return createProperties(argc, const_cast<const char**>(argv), defaults);
}
Expand All @@ -184,7 +184,7 @@ inline PropertiesPtr createProperties(int& argc, char* argv[], const PropertiesP
* @return A new property set initialized with the property settings
* that were removed from the argument vector.
*/
ICE_API PropertiesPtr createProperties(int& argc, const wchar_t* argv[], const PropertiesPtr& defaults = 0);
ICE_API PropertiesPtr createProperties(int& argc, const wchar_t* argv[], const PropertiesPtr& defaults = nullptr);

/**
* Creates a property set initialized from command-line arguments
Expand All @@ -205,7 +205,7 @@ ICE_API PropertiesPtr createProperties(int& argc, const wchar_t* argv[], const P
* @return A new property set initialized with the property settings
* that were removed from the argument vector.
*/
inline PropertiesPtr createProperties(int& argc, wchar_t* argv[], const PropertiesPtr& defaults = 0)
inline PropertiesPtr createProperties(int& argc, wchar_t* argv[], const PropertiesPtr& defaults = nullptr)
{
return createProperties(argc, const_cast<const wchar_t**>(argv), defaults);
}
Expand Down
129 changes: 72 additions & 57 deletions cpp/include/Ice/Properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,60 @@
// Copyright (c) ZeroC, Inc. All rights reserved.
//

#ifndef __Ice_Properties_h__
#define __Ice_Properties_h__

#include <IceUtil/PushDisableWarnings.h>
#include <Ice/ProxyF.h>
#include <Ice/ObjectF.h>
#include <Ice/ValueF.h>
#include <Ice/Exception.h>
#include <Ice/StreamHelpers.h>
#include <Ice/Comparable.h>
#include <Ice/Proxy.h>
#include <Ice/Object.h>
#include <Ice/Value.h>
#include <Ice/FactoryTableInit.h>
#include <optional>
#include <Ice/PropertyDict.h>
#include <IceUtil/UndefSysMacros.h>

#ifndef ICE_API
# if defined(ICE_STATIC_LIBS)
# define ICE_API /**/
# elif defined(ICE_API_EXPORTS)
# define ICE_API ICE_DECLSPEC_EXPORT
# else
# define ICE_API ICE_DECLSPEC_IMPORT
# endif
#endif
#ifndef ICE_PROPERTIES_H
#define ICE_PROPERTIES_H

namespace Ice
{
#include "Config.h"
#include "Ice/BuiltinSequences.h"
#include "Ice/PropertyDict.h"
#include "StringConverter.h"

class Properties;
#include <set>
#include <string>
#include <string_view>

}

/// \cond INTERNAL
namespace Ice
{

/**
* A property set used to configure Ice and Ice applications. Properties are key/value pairs, with both keys and
* values being strings. By convention, property keys should have the form
* <em>application-name</em>[.<em>category</em>[.<em>sub-category</em>]].<em>name</em>.
* This class is thread-safe: multiple threads can safely read and write the properties without their own
* synchronization.
* \headerfile Ice/Ice.h
*/
class ICE_CLASS(ICE_API) Properties
class ICE_API Properties final
{
public:

ICE_MEMBER(ICE_API) virtual ~Properties();
/**
* Default constructor.
*/
Properties() = default;

/**
* Copy constructor.
* @param source The property set to copy.
*/
Properties(const Properties& source);

/**
* Constructs a property from command-line arguments and a default property set.
* @param args The command-line arguments. Property arguments are removed from this sequence.
* @param defaults The default property set.
*/
Properties(StringSeq& args, const std::shared_ptr<Properties>& defaults);

Properties& operator=(const Properties& rhs) = delete;

/**
* Get a property by key. If the property is not set, an empty string is returned.
* @param key The property key.
* @return The property value.
* @see #setProperty
*/
virtual ::std::string getProperty(const ::std::string& key) noexcept = 0;
std::string getProperty(std::string_view key) noexcept;

/**
* Get a property by key. If the property is not set, the given default value is returned.
Expand All @@ -68,15 +64,15 @@ class ICE_CLASS(ICE_API) Properties
* @return The property value or the default value.
* @see #setProperty
*/
virtual ::std::string getPropertyWithDefault(const ::std::string& key, const ::std::string& value) noexcept = 0;
std::string getPropertyWithDefault(std::string_view key, std::string_view value) noexcept;

/**
* Get a property as an integer. If the property is not set, 0 is returned.
* @param key The property key.
* @return The property value interpreted as an integer.
* @see #setProperty
*/
virtual int getPropertyAsInt(const ::std::string& key) noexcept = 0;
int getPropertyAsInt(std::string_view key) noexcept;

/**
* Get a property as an integer. If the property is not set, the given default value is returned.
Expand All @@ -85,7 +81,7 @@ class ICE_CLASS(ICE_API) Properties
* @return The property value interpreted as an integer, or the default value.
* @see #setProperty
*/
virtual int getPropertyAsIntWithDefault(const ::std::string& key, int value) noexcept = 0;
int getPropertyAsIntWithDefault(std::string_view key, int value) noexcept;

/**
* Get a property as a list of strings. The strings must be separated by whitespace or comma. If the property is
Expand All @@ -97,7 +93,7 @@ class ICE_CLASS(ICE_API) Properties
* @return The property value interpreted as a list of strings.
* @see #setProperty
*/
virtual ::Ice::StringSeq getPropertyAsList(const ::std::string& key) noexcept = 0;
StringSeq getPropertyAsList(std::string_view key) noexcept;

/**
* Get a property as a list of strings. The strings must be separated by whitespace or comma. If the property is
Expand All @@ -110,30 +106,30 @@ class ICE_CLASS(ICE_API) Properties
* @return The property value interpreted as list of strings, or the default value.
* @see #setProperty
*/
virtual ::Ice::StringSeq getPropertyAsListWithDefault(const ::std::string& key, const StringSeq& value) noexcept = 0;
StringSeq getPropertyAsListWithDefault(std::string_view key, const StringSeq& value) noexcept;

/**
* Get all properties whose keys begins with <em>prefix</em>. If <em>prefix</em> is an empty string, then all
* properties are returned.
* @param prefix The prefix to search for (empty string if none).
* @return The matching property set.
*/
virtual ::Ice::PropertyDict getPropertiesForPrefix(const ::std::string& prefix) noexcept = 0;
PropertyDict getPropertiesForPrefix(std::string_view prefix) noexcept;

/**
* Set a property. To unset a property, set it to the empty string.
* @param key The property key.
* @param value The property value.
* @see #getProperty
*/
virtual void setProperty(const ::std::string& key, const ::std::string& value) = 0;
void setProperty(std::string_view key, std::string_view value);

/**
* Get a sequence of command-line options that is equivalent to this property set. Each element of the returned
* sequence is a command-line option of the form <code>--<em>key</em>=<em>value</em></code>.
* @return The command line options for this property set.
*/
virtual ::Ice::StringSeq getCommandLineOptions() noexcept = 0;
StringSeq getCommandLineOptions() noexcept;

/**
* Convert a sequence of command-line options into properties. All options that begin with
Expand All @@ -143,7 +139,7 @@ class ICE_CLASS(ICE_API) Properties
* @param options The command-line options.
* @return The command-line options that do not start with the specified prefix, in their original order.
*/
virtual ::Ice::StringSeq parseCommandLineOptions(const ::std::string& prefix, const StringSeq& options) = 0;
StringSeq parseCommandLineOptions(std::string_view prefix, const StringSeq& options);

/**
* Convert a sequence of command-line options into properties. All options that begin with one of the following
Expand All @@ -152,32 +148,51 @@ class ICE_CLASS(ICE_API) Properties
* @param options The command-line options.
* @return The command-line options that do not start with one of the listed prefixes, in their original order.
*/
virtual ::Ice::StringSeq parseIceCommandLineOptions(const StringSeq& options) = 0;
StringSeq parseIceCommandLineOptions(const StringSeq& options);

/**
* Load properties from a file.
* @param file The property file.
*/
virtual void load(const ::std::string& file) = 0;
void load(std::string_view file);

/**
* Create a copy of this property set.
* @return A copy of this property set.
*/
virtual ::std::shared_ptr<::Ice::Properties> clone() noexcept = 0;
};
std::shared_ptr<Properties> clone() { return std::make_shared<Properties>(*this); }

}
/// \endcond
/**
* Get the properties that were never read.
* @return A list of unused properties.
*/
std::set<std::string> getUnusedProperties();

/// \cond INTERNAL
namespace Ice
{
private:

void parseLine(std::string_view, const StringConverterPtr&);

void loadConfig();

struct PropertyValue
{
PropertyValue() : used(false)
{
}

PropertyValue(std::string v, bool u) : value(std::move(v)), used(u)
{
}

std::string value;
bool used;
};
std::map<std::string, PropertyValue, std::less<>> _properties;
std::mutex _mutex;
};

using PropertiesPtr = ::std::shared_ptr<Properties>;
using PropertiesPtr = std::shared_ptr<Properties>;

}
/// \endcond

#include <IceUtil/PopDisableWarnings.h>
#endif
2 changes: 1 addition & 1 deletion cpp/src/Ice/IPEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <Ice/ProtocolInstance.h>
#include <Ice/Instance.h>
#include <Ice/LocalException.h>
#include <Ice/PropertiesI.h>
#include <Ice/Properties.h>
#include <Ice/LoggerUtil.h>
#include <Ice/HashUtil.h>
#include <Ice/NetworkProxy.h>
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/Ice/Initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <Ice/ArgVector.h>
#include "Ice/Communicator.h"
#include <Ice/PropertiesI.h>
#include <Ice/Properties.h>
#include <Ice/Initialize.h>
#include <Ice/LocalException.h>
#include <Ice/LoggerI.h>
Expand Down Expand Up @@ -144,13 +144,13 @@ Ice::stringSeqToArgs(const StringSeq& args, int& argc, const wchar_t* argv[])
PropertiesPtr
Ice::createProperties()
{
return make_shared<PropertiesI>();
return make_shared<Properties>();
}

PropertiesPtr
Ice::createProperties(StringSeq& args, const PropertiesPtr& defaults)
{
return make_shared<PropertiesI>(args, defaults);
return make_shared<Properties>(args, defaults);
}

PropertiesPtr
Expand Down
5 changes: 2 additions & 3 deletions cpp/src/Ice/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <Ice/LocalException.h>
#include <Ice/ObjectAdapterFactory.h>
#include <Ice/Exception.h>
#include <Ice/PropertiesI.h>
#include <Ice/Properties.h>
#include <Ice/PropertiesAdminI.h>
#include <Ice/LoggerI.h>
#include <Ice/NetworkProxy.h>
Expand All @@ -29,7 +29,6 @@
#include <Ice/PluginManagerI.h>
#include <Ice/Initialize.h>
#include <Ice/LoggerUtil.h>
#include <Ice/PropertiesI.h>
#include <Ice/Communicator.h>
#include <Ice/InstrumentationI.h>
#include <Ice/ProtocolInstance.h>
Expand Down Expand Up @@ -1691,7 +1690,7 @@ IceInternal::Instance::destroy()

if(_initData.properties->getPropertyAsInt("Ice.Warn.UnusedProperties") > 0)
{
set<string> unusedProperties = static_cast<PropertiesI*>(_initData.properties.get())->getUnusedProperties();
set<string> unusedProperties = _initData.properties.get()->getUnusedProperties();
if(unusedProperties.size() != 0)
{
Warning out(_initData.logger);
Expand Down
Loading
Loading