C++: Make most members private instead of protected
Use protected only for members which are actually needed by sub-classes. Declare all the rest private.
This commit is contained in:
parent
4c9208a799
commit
21d1bec60e
|
@ -1,6 +1,6 @@
|
||||||
const DataType *ConfigKey::data_type() const
|
const DataType *ConfigKey::data_type() const
|
||||||
{
|
{
|
||||||
const struct sr_key_info *info = sr_key_info_get(SR_KEY_CONFIG, _id);
|
const struct sr_key_info *info = sr_key_info_get(SR_KEY_CONFIG, id());
|
||||||
if (!info)
|
if (!info)
|
||||||
throw Error(SR_ERR_NA);
|
throw Error(SR_ERR_NA);
|
||||||
return DataType::get(info->datatype);
|
return DataType::get(info->datatype);
|
||||||
|
@ -8,7 +8,7 @@ const DataType *ConfigKey::data_type() const
|
||||||
|
|
||||||
string ConfigKey::identifier() const
|
string ConfigKey::identifier() const
|
||||||
{
|
{
|
||||||
const struct sr_key_info *info = sr_key_info_get(SR_KEY_CONFIG, _id);
|
const struct sr_key_info *info = sr_key_info_get(SR_KEY_CONFIG, id());
|
||||||
if (!info)
|
if (!info)
|
||||||
throw Error(SR_ERR_NA);
|
throw Error(SR_ERR_NA);
|
||||||
return valid_string(info->id);
|
return valid_string(info->id);
|
||||||
|
@ -16,7 +16,7 @@ string ConfigKey::identifier() const
|
||||||
|
|
||||||
string ConfigKey::description() const
|
string ConfigKey::description() const
|
||||||
{
|
{
|
||||||
const struct sr_key_info *info = sr_key_info_get(SR_KEY_CONFIG, _id);
|
const struct sr_key_info *info = sr_key_info_get(SR_KEY_CONFIG, id());
|
||||||
if (!info)
|
if (!info)
|
||||||
throw Error(SR_ERR_NA);
|
throw Error(SR_ERR_NA);
|
||||||
return valid_string(info->name);
|
return valid_string(info->name);
|
||||||
|
|
|
@ -130,6 +130,17 @@ public:
|
||||||
template <class Class, class Parent, typename Struct>
|
template <class Class, class Parent, typename Struct>
|
||||||
class SR_API ParentOwned
|
class SR_API ParentOwned
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
/* Weak pointer for shared_from_this() implementation. */
|
||||||
|
weak_ptr<Class> _weak_this;
|
||||||
|
|
||||||
|
static void reset_parent(Class *object)
|
||||||
|
{
|
||||||
|
if (!object->_parent)
|
||||||
|
throw Error(SR_ERR_BUG);
|
||||||
|
object->_parent.reset();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/* Parent object which owns this child object's underlying structure.
|
/* Parent object which owns this child object's underlying structure.
|
||||||
|
|
||||||
|
@ -146,8 +157,12 @@ protected:
|
||||||
references to both the parent and all its children are gone. */
|
references to both the parent and all its children are gone. */
|
||||||
shared_ptr<Parent> _parent;
|
shared_ptr<Parent> _parent;
|
||||||
|
|
||||||
/* Weak pointer for shared_from_this() implementation. */
|
Struct *_structure;
|
||||||
weak_ptr<Class> _weak_this;
|
|
||||||
|
explicit ParentOwned(Struct *structure) :
|
||||||
|
_structure(structure)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* Get parent object that owns this object. */
|
/* Get parent object that owns this object. */
|
||||||
|
@ -184,20 +199,6 @@ public:
|
||||||
throw Error(SR_ERR_BUG);
|
throw Error(SR_ERR_BUG);
|
||||||
return get_shared_pointer(parent->shared_from_this());
|
return get_shared_pointer(parent->shared_from_this());
|
||||||
}
|
}
|
||||||
protected:
|
|
||||||
static void reset_parent(Class *object)
|
|
||||||
{
|
|
||||||
if (!object->_parent)
|
|
||||||
throw Error(SR_ERR_BUG);
|
|
||||||
object->_parent.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
Struct *_structure;
|
|
||||||
|
|
||||||
explicit ParentOwned(Struct *structure) :
|
|
||||||
_structure(structure)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Base template for classes whose resources are owned by the user. */
|
/* Base template for classes whose resources are owned by the user. */
|
||||||
|
@ -314,7 +315,7 @@ public:
|
||||||
* @param header Initial data from stream. */
|
* @param header Initial data from stream. */
|
||||||
shared_ptr<Input> open_stream(string header);
|
shared_ptr<Input> open_stream(string header);
|
||||||
map<string, string> serials(shared_ptr<Driver> driver) const;
|
map<string, string> serials(shared_ptr<Driver> driver) const;
|
||||||
protected:
|
private:
|
||||||
map<string, Driver *> _drivers;
|
map<string, Driver *> _drivers;
|
||||||
map<string, InputFormat *> _input_formats;
|
map<string, InputFormat *> _input_formats;
|
||||||
map<string, OutputFormat *> _output_formats;
|
map<string, OutputFormat *> _output_formats;
|
||||||
|
@ -376,7 +377,7 @@ public:
|
||||||
* @param options Mapping of (ConfigKey, value) pairs. */
|
* @param options Mapping of (ConfigKey, value) pairs. */
|
||||||
vector<shared_ptr<HardwareDevice> > scan(
|
vector<shared_ptr<HardwareDevice> > scan(
|
||||||
const map<const ConfigKey *, Glib::VariantBase> &options = {});
|
const map<const ConfigKey *, Glib::VariantBase> &options = {});
|
||||||
protected:
|
private:
|
||||||
bool _initialized;
|
bool _initialized;
|
||||||
vector<HardwareDevice *> _devices;
|
vector<HardwareDevice *> _devices;
|
||||||
explicit Driver(struct sr_dev_driver *structure);
|
explicit Driver(struct sr_dev_driver *structure);
|
||||||
|
@ -413,8 +414,10 @@ protected:
|
||||||
~Device();
|
~Device();
|
||||||
virtual shared_ptr<Device> get_shared_from_this() = 0;
|
virtual shared_ptr<Device> get_shared_from_this() = 0;
|
||||||
shared_ptr<Channel> get_channel(struct sr_channel *ptr);
|
shared_ptr<Channel> get_channel(struct sr_channel *ptr);
|
||||||
|
|
||||||
struct sr_dev_inst *_structure;
|
struct sr_dev_inst *_structure;
|
||||||
map<struct sr_channel *, Channel *> _channels;
|
map<struct sr_channel *, Channel *> _channels;
|
||||||
|
private:
|
||||||
map<string, ChannelGroup *> _channel_groups;
|
map<string, ChannelGroup *> _channel_groups;
|
||||||
/** Deleter needed to allow shared_ptr use with protected destructor. */
|
/** Deleter needed to allow shared_ptr use with protected destructor. */
|
||||||
class Deleter
|
class Deleter
|
||||||
|
@ -438,7 +441,7 @@ class SR_API HardwareDevice :
|
||||||
public:
|
public:
|
||||||
/** Driver providing this device. */
|
/** Driver providing this device. */
|
||||||
shared_ptr<Driver> driver();
|
shared_ptr<Driver> driver();
|
||||||
protected:
|
private:
|
||||||
HardwareDevice(shared_ptr<Driver> driver, struct sr_dev_inst *structure);
|
HardwareDevice(shared_ptr<Driver> driver, struct sr_dev_inst *structure);
|
||||||
~HardwareDevice();
|
~HardwareDevice();
|
||||||
shared_ptr<Device> get_shared_from_this();
|
shared_ptr<Device> get_shared_from_this();
|
||||||
|
@ -462,7 +465,7 @@ class SR_API UserDevice :
|
||||||
public:
|
public:
|
||||||
/** Add a new channel to this device. */
|
/** Add a new channel to this device. */
|
||||||
shared_ptr<Channel> add_channel(unsigned int index, const ChannelType *type, string name);
|
shared_ptr<Channel> add_channel(unsigned int index, const ChannelType *type, string name);
|
||||||
protected:
|
private:
|
||||||
UserDevice(string vendor, string model, string version);
|
UserDevice(string vendor, string model, string version);
|
||||||
~UserDevice();
|
~UserDevice();
|
||||||
shared_ptr<Device> get_shared_from_this();
|
shared_ptr<Device> get_shared_from_this();
|
||||||
|
@ -495,7 +498,7 @@ public:
|
||||||
void set_enabled(bool value);
|
void set_enabled(bool value);
|
||||||
/** Get the index number of this channel. */
|
/** Get the index number of this channel. */
|
||||||
unsigned int index() const;
|
unsigned int index() const;
|
||||||
protected:
|
private:
|
||||||
explicit Channel(struct sr_channel *structure);
|
explicit Channel(struct sr_channel *structure);
|
||||||
~Channel();
|
~Channel();
|
||||||
const ChannelType * const _type;
|
const ChannelType * const _type;
|
||||||
|
@ -517,7 +520,7 @@ public:
|
||||||
string name() const;
|
string name() const;
|
||||||
/** List of the channels in this group. */
|
/** List of the channels in this group. */
|
||||||
vector<shared_ptr<Channel> > channels();
|
vector<shared_ptr<Channel> > channels();
|
||||||
protected:
|
private:
|
||||||
ChannelGroup(Device *device, struct sr_channel_group *structure);
|
ChannelGroup(Device *device, struct sr_channel_group *structure);
|
||||||
~ChannelGroup();
|
~ChannelGroup();
|
||||||
vector<Channel *> _channels;
|
vector<Channel *> _channels;
|
||||||
|
@ -534,7 +537,7 @@ public:
|
||||||
vector<shared_ptr<TriggerStage> > stages();
|
vector<shared_ptr<TriggerStage> > stages();
|
||||||
/** Add a new stage to this trigger. */
|
/** Add a new stage to this trigger. */
|
||||||
shared_ptr<TriggerStage> add_stage();
|
shared_ptr<TriggerStage> add_stage();
|
||||||
protected:
|
private:
|
||||||
Trigger(shared_ptr<Context> context, string name);
|
Trigger(shared_ptr<Context> context, string name);
|
||||||
~Trigger();
|
~Trigger();
|
||||||
shared_ptr<Context> _context;
|
shared_ptr<Context> _context;
|
||||||
|
@ -562,7 +565,7 @@ public:
|
||||||
* @param type TriggerMatchType to apply.
|
* @param type TriggerMatchType to apply.
|
||||||
* @param value Threshold value. */
|
* @param value Threshold value. */
|
||||||
void add_match(shared_ptr<Channel> channel, const TriggerMatchType *type, float value);
|
void add_match(shared_ptr<Channel> channel, const TriggerMatchType *type, float value);
|
||||||
protected:
|
private:
|
||||||
vector<TriggerMatch *> _matches;
|
vector<TriggerMatch *> _matches;
|
||||||
explicit TriggerStage(struct sr_trigger_stage *structure);
|
explicit TriggerStage(struct sr_trigger_stage *structure);
|
||||||
~TriggerStage();
|
~TriggerStage();
|
||||||
|
@ -580,7 +583,7 @@ public:
|
||||||
const TriggerMatchType *type() const;
|
const TriggerMatchType *type() const;
|
||||||
/** Threshold value. */
|
/** Threshold value. */
|
||||||
float value() const;
|
float value() const;
|
||||||
protected:
|
private:
|
||||||
TriggerMatch(struct sr_trigger_match *structure, shared_ptr<Channel> channel);
|
TriggerMatch(struct sr_trigger_match *structure, shared_ptr<Channel> channel);
|
||||||
~TriggerMatch();
|
~TriggerMatch();
|
||||||
shared_ptr<Channel> _channel;
|
shared_ptr<Channel> _channel;
|
||||||
|
@ -600,7 +603,7 @@ class SR_PRIV DatafeedCallbackData
|
||||||
public:
|
public:
|
||||||
void run(const struct sr_dev_inst *sdi,
|
void run(const struct sr_dev_inst *sdi,
|
||||||
const struct sr_datafeed_packet *pkt);
|
const struct sr_datafeed_packet *pkt);
|
||||||
protected:
|
private:
|
||||||
DatafeedCallbackFunction _callback;
|
DatafeedCallbackFunction _callback;
|
||||||
DatafeedCallbackData(Session *session,
|
DatafeedCallbackData(Session *session,
|
||||||
DatafeedCallbackFunction callback);
|
DatafeedCallbackFunction callback);
|
||||||
|
@ -613,7 +616,7 @@ class SR_API SessionDevice :
|
||||||
public ParentOwned<SessionDevice, Session, struct sr_dev_inst>,
|
public ParentOwned<SessionDevice, Session, struct sr_dev_inst>,
|
||||||
public Device
|
public Device
|
||||||
{
|
{
|
||||||
protected:
|
private:
|
||||||
explicit SessionDevice(struct sr_dev_inst *sdi);
|
explicit SessionDevice(struct sr_dev_inst *sdi);
|
||||||
~SessionDevice();
|
~SessionDevice();
|
||||||
shared_ptr<Device> get_shared_from_this();
|
shared_ptr<Device> get_shared_from_this();
|
||||||
|
@ -662,7 +665,7 @@ public:
|
||||||
void set_trigger(shared_ptr<Trigger> trigger);
|
void set_trigger(shared_ptr<Trigger> trigger);
|
||||||
/** Get filename this session was loaded from. */
|
/** Get filename this session was loaded from. */
|
||||||
string filename() const;
|
string filename() const;
|
||||||
protected:
|
private:
|
||||||
explicit Session(shared_ptr<Context> context);
|
explicit Session(shared_ptr<Context> context);
|
||||||
Session(shared_ptr<Context> context, string filename);
|
Session(shared_ptr<Context> context, string filename);
|
||||||
~Session();
|
~Session();
|
||||||
|
@ -688,7 +691,7 @@ public:
|
||||||
const PacketType *type() const;
|
const PacketType *type() const;
|
||||||
/** Payload of this packet. */
|
/** Payload of this packet. */
|
||||||
shared_ptr<PacketPayload> payload();
|
shared_ptr<PacketPayload> payload();
|
||||||
protected:
|
private:
|
||||||
Packet(shared_ptr<Device> device,
|
Packet(shared_ptr<Device> device,
|
||||||
const struct sr_datafeed_packet *structure);
|
const struct sr_datafeed_packet *structure);
|
||||||
~Packet();
|
~Packet();
|
||||||
|
@ -712,12 +715,7 @@ protected:
|
||||||
PacketPayload();
|
PacketPayload();
|
||||||
virtual ~PacketPayload() = 0;
|
virtual ~PacketPayload() = 0;
|
||||||
virtual shared_ptr<PacketPayload> get_shared_pointer(Packet *parent) = 0;
|
virtual shared_ptr<PacketPayload> get_shared_pointer(Packet *parent) = 0;
|
||||||
/** Deleter needed to allow shared_ptr use with protected destructor. */
|
|
||||||
class Deleter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void operator()(PacketPayload *payload) { delete payload; }
|
|
||||||
};
|
|
||||||
friend class Deleter;
|
friend class Deleter;
|
||||||
friend class Packet;
|
friend class Packet;
|
||||||
friend class Output;
|
friend class Output;
|
||||||
|
@ -733,7 +731,7 @@ public:
|
||||||
int feed_version() const;
|
int feed_version() const;
|
||||||
/* Start time of this session. */
|
/* Start time of this session. */
|
||||||
Glib::TimeVal start_time() const;
|
Glib::TimeVal start_time() const;
|
||||||
protected:
|
private:
|
||||||
explicit Header(const struct sr_datafeed_header *structure);
|
explicit Header(const struct sr_datafeed_header *structure);
|
||||||
~Header();
|
~Header();
|
||||||
shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
|
shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
|
||||||
|
@ -748,7 +746,7 @@ class SR_API Meta :
|
||||||
public:
|
public:
|
||||||
/* Mapping of (ConfigKey, value) pairs. */
|
/* Mapping of (ConfigKey, value) pairs. */
|
||||||
map<const ConfigKey *, Glib::VariantBase> config() const;
|
map<const ConfigKey *, Glib::VariantBase> config() const;
|
||||||
protected:
|
private:
|
||||||
explicit Meta(const struct sr_datafeed_meta *structure);
|
explicit Meta(const struct sr_datafeed_meta *structure);
|
||||||
~Meta();
|
~Meta();
|
||||||
shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
|
shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
|
||||||
|
@ -768,7 +766,7 @@ public:
|
||||||
size_t data_length() const;
|
size_t data_length() const;
|
||||||
/* Size of each sample in bytes. */
|
/* Size of each sample in bytes. */
|
||||||
unsigned int unit_size() const;
|
unsigned int unit_size() const;
|
||||||
protected:
|
private:
|
||||||
explicit Logic(const struct sr_datafeed_logic *structure);
|
explicit Logic(const struct sr_datafeed_logic *structure);
|
||||||
~Logic();
|
~Logic();
|
||||||
shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
|
shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
|
||||||
|
@ -793,7 +791,7 @@ public:
|
||||||
const Unit *unit() const;
|
const Unit *unit() const;
|
||||||
/** Measurement flags associated with the samples in this packet. */
|
/** Measurement flags associated with the samples in this packet. */
|
||||||
vector<const QuantityFlag *> mq_flags() const;
|
vector<const QuantityFlag *> mq_flags() const;
|
||||||
protected:
|
private:
|
||||||
explicit Analog(const struct sr_datafeed_analog *structure);
|
explicit Analog(const struct sr_datafeed_analog *structure);
|
||||||
~Analog();
|
~Analog();
|
||||||
shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
|
shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
|
||||||
|
@ -817,7 +815,7 @@ public:
|
||||||
/** Create an input using this input format.
|
/** Create an input using this input format.
|
||||||
* @param options Mapping of (option name, value) pairs. */
|
* @param options Mapping of (option name, value) pairs. */
|
||||||
shared_ptr<Input> create_input(const map<string, Glib::VariantBase> &options = {});
|
shared_ptr<Input> create_input(const map<string, Glib::VariantBase> &options = {});
|
||||||
protected:
|
private:
|
||||||
explicit InputFormat(const struct sr_input_module *structure);
|
explicit InputFormat(const struct sr_input_module *structure);
|
||||||
~InputFormat();
|
~InputFormat();
|
||||||
friend class Context;
|
friend class Context;
|
||||||
|
@ -836,7 +834,7 @@ public:
|
||||||
void send(void *data, size_t length);
|
void send(void *data, size_t length);
|
||||||
/** Signal end of input data. */
|
/** Signal end of input data. */
|
||||||
void end();
|
void end();
|
||||||
protected:
|
private:
|
||||||
Input(shared_ptr<Context> context, const struct sr_input *structure);
|
Input(shared_ptr<Context> context, const struct sr_input *structure);
|
||||||
~Input();
|
~Input();
|
||||||
shared_ptr<Context> _context;
|
shared_ptr<Context> _context;
|
||||||
|
@ -851,7 +849,7 @@ class SR_API InputDevice :
|
||||||
public ParentOwned<InputDevice, Input, struct sr_dev_inst>,
|
public ParentOwned<InputDevice, Input, struct sr_dev_inst>,
|
||||||
public Device
|
public Device
|
||||||
{
|
{
|
||||||
protected:
|
private:
|
||||||
InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi);
|
InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi);
|
||||||
~InputDevice();
|
~InputDevice();
|
||||||
shared_ptr<Device> get_shared_from_this();
|
shared_ptr<Device> get_shared_from_this();
|
||||||
|
@ -873,7 +871,7 @@ public:
|
||||||
Glib::VariantBase default_value() const;
|
Glib::VariantBase default_value() const;
|
||||||
/** Possible values for this option, if a limited set. */
|
/** Possible values for this option, if a limited set. */
|
||||||
vector<Glib::VariantBase> values() const;
|
vector<Glib::VariantBase> values() const;
|
||||||
protected:
|
private:
|
||||||
Option(const struct sr_option *structure,
|
Option(const struct sr_option *structure,
|
||||||
shared_ptr<const struct sr_option *> structure_array);
|
shared_ptr<const struct sr_option *> structure_array);
|
||||||
~Option();
|
~Option();
|
||||||
|
@ -917,7 +915,7 @@ public:
|
||||||
* @see sr_output_flags
|
* @see sr_output_flags
|
||||||
*/
|
*/
|
||||||
bool test_flag(const OutputFlag *flag) const;
|
bool test_flag(const OutputFlag *flag) const;
|
||||||
protected:
|
private:
|
||||||
explicit OutputFormat(const struct sr_output_module *structure);
|
explicit OutputFormat(const struct sr_output_module *structure);
|
||||||
~OutputFormat();
|
~OutputFormat();
|
||||||
friend class Context;
|
friend class Context;
|
||||||
|
@ -931,7 +929,7 @@ public:
|
||||||
/** Update output with data from the given packet.
|
/** Update output with data from the given packet.
|
||||||
* @param packet Packet to handle. */
|
* @param packet Packet to handle. */
|
||||||
string receive(shared_ptr<Packet> packet);
|
string receive(shared_ptr<Packet> packet);
|
||||||
protected:
|
private:
|
||||||
Output(shared_ptr<OutputFormat> format, shared_ptr<Device> device);
|
Output(shared_ptr<OutputFormat> format, shared_ptr<Device> device);
|
||||||
Output(shared_ptr<OutputFormat> format,
|
Output(shared_ptr<OutputFormat> format,
|
||||||
shared_ptr<Device> device, const map<string, Glib::VariantBase> &options);
|
shared_ptr<Device> device, const map<string, Glib::VariantBase> &options);
|
||||||
|
@ -982,6 +980,7 @@ protected:
|
||||||
~EnumValue()
|
~EnumValue()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
static const std::map<const Enum, const Class * const> _values;
|
static const std::map<const Enum, const Class * const> _values;
|
||||||
const Enum _id;
|
const Enum _id;
|
||||||
const string _name;
|
const string _name;
|
||||||
|
|
Loading…
Reference in New Issue