Skip to content

Instantly share code, notes, and snippets.

@sherm1
Last active September 30, 2015 23:14
Show Gist options
  • Save sherm1/01adcdbb93105f3a7fea to your computer and use it in GitHub Desktop.
Save sherm1/01adcdbb93105f3a7fea to your computer and use it in GitHub Desktop.
Non-virtual interface naming comparison
//==============================================================================
// STUDY
//==============================================================================
/** This is the abstract base class for all Simbody studies.
...
The %Study class has a public interface for users of Studies, and a pure virtual
protected interface for implementors of Studies. **/
class Study {
public:
/** Destructor is virtual to support derived class cleanup. **/
virtual ~Study() = default;
/** Return the System that is the subject of this %Study. This is only
available as a const reference because a System is immutable during a
%Study. **/
const System& getSystem() const
{ return getSystemVirtual(); }
/** Return a const reference to the "current" state of this %Study, with the
precise meaning up to the concrete %Study to define. ... See
updInternalState() to get write access to meaningful internal data of
the %Study. **/
const State& getCurrentState() const
{ return getCurrentStateVirtual(); }
/** Return a const reference to the "internal" state of this %Study, with
the precise meaning up to the concrete %Study to define. This should be
a reference to the object that the %Study modifies internally that
represents the furthest progress of the trajectory. Note that it may be
further along that what gets returned by getCurrentState(). **/
const State& getInternalState() const
{ return getInternalStateVirtual(); }
/** Return a writable reference to the "internal" state of this %Study.
Modifying this state will affect the progression of the %Study. This is
typically done in event handlers and during initialization. See
getInternalState() for more information. **/
State& updInternalState()
{ return updInternalStateVirtual(); }
/** Return the current accuracy setting in use by this %Study. The precise
meaning of this parameter varies according to the concrete %Study type, but
it can usually be interpreted to mean something related to the number of
correct digits in the results. For example, 1e-3 would mean that we are
requesting three correct digits, that is, an accuracy of 0.1%. If this
doesn't make sense for a particular concrete %Study it returns `NaN`. **/
Real getAccuracyInUse() const
{ return getAccuracyInUseVirtual(); }
/** Return the current constraint tolerance in use by this %Study. The
precise meaning of this parameter varies according to the concrete %Study
type, but is usually the value determining how precisely constraints or
other algebraic equations are to be satisfied. If this
doesn't make sense for a particular concrete %Study it returns `NaN`. **/
Real getConstraintToleranceInUse() const
{ return getConstraintToleranceInUseVirtual(); }
/** Studies can't be copied. **/
Study(const Study&) = delete;
/** Studies can't be copied. **/
Study& operator=(const Study&) = delete;
protected:
/** Constructor is for derived class use only. **/
Study() {}
/** You must provide a const reference to the System you are studying. **/
virtual const System& getSystemVirtual() const = 0;
/** Return your %Study's notion of current state. It is fine if this is
the same as your internal state. Note that you must return a reference so
if you create a temporary state you must do so into an internal object that
persists at least until the next step. If this doesn't make sense for your
%Study you should throw an exception with a helpful message. **/
virtual const State& getCurrentStateVirtual() const = 0;
/** This should be a reference to the internal object that you use to
represent the furthest your %Study algorithm has progressed along the
generated trajectory. If this doesn't make sense for your %Study you
should throw an exception with a helpful message. **/
virtual const State& getInternalStateVirtual() const = 0;
/** This should be a writable reference to the same object returned by
getInternalState(). This should be the state that you want an event
handler to modify to affect the subsequent trajectory. If this doesn't make
sense for your %Study you should throw an exception with a helpful
message. **/
virtual State& updInternalStateVirtual() = 0;
/** This should be the accuracy you are currently using, not necessarily
regurgitating a user setting. If this doesn't make sense for your
particular concrete %Study, just return `NaN`. Make sure your documentation
explains exactly what is meant by "accuracy" in your %Study. **/
virtual Real getAccuracyInUseVirtual() const = 0;
/** This should be the constraint tolerance you are currently using, not
necessarily regurgitating a user setting. If this doesn't make sense for
your particular concrete %Study, just return `NaN`. Make sure your
documentation explains exactly what is meant by "constraint tolerance" in
your %Study. **/
virtual Real getConstraintToleranceInUseVirtual() const = 0;
};
//==============================================================================
// STUDY
//==============================================================================
/** This is the abstract base class for all Simbody studies.
...
The %Study class has a public interface for users of Studies, and a pure virtual
protected interface for implementors of Studies. **/
class Study {
public:
/** Destructor is virtual to support derived class cleanup. **/
virtual ~Study() = default;
/** Return the System that is the subject of this %Study. This is only
available as a const reference because a System is immutable during a
%Study. **/
const System& getSystem() const
{ return implementGetSystem(); }
/** Return a const reference to the "current" state of this %Study, with the
precise meaning up to the concrete %Study to define. ... See
updInternalState() to get write access to meaningful internal data of
the %Study. **/
const State& getCurrentState() const
{ return implementGetCurrentState(); }
/** Return a const reference to the "internal" state of this %Study, with
the precise meaning up to the concrete %Study to define. This should be
a reference to the object that the %Study modifies internally that
represents the furthest progress of the trajectory. Note that it may be
further along that what gets returned by getCurrentState(). **/
const State& getInternalState() const
{ return implementGetInternalState(); }
/** Return a writable reference to the "internal" state of this %Study.
Modifying this state will affect the progression of the %Study. This is
typically done in event handlers and during initialization. See
getInternalState() for more information. **/
State& updInternalState()
{ return implementUpdInternalState(); }
/** Return the current accuracy setting in use by this %Study. The precise
meaning of this parameter varies according to the concrete %Study type, but
it can usually be interpreted to mean something related to the number of
correct digits in the results. For example, 1e-3 would mean that we are
requesting three correct digits, that is, an accuracy of 0.1%. If this
doesn't make sense for a particular concrete %Study it returns `NaN`. **/
Real getAccuracyInUse() const
{ return implementGetAccuracyInUse(); }
/** Return the current constraint tolerance in use by this %Study. The
precise meaning of this parameter varies according to the concrete %Study
type, but is usually the value determining how precisely constraints or
other algebraic equations are to be satisfied. If this
doesn't make sense for a particular concrete %Study it returns `NaN`. **/
Real getConstraintToleranceInUse() const
{ return implementGetConstraintToleranceInUse(); }
/** Studies can't be copied. **/
Study(const Study&) = delete;
/** Studies can't be copied. **/
Study& operator=(const Study&) = delete;
protected:
/** Constructor is for derived class use only. **/
Study() {}
/** You must provide a const reference to the System you are studying. **/
virtual const System& implementGetSystem() const = 0;
/** Return your %Study's notion of current state. It is fine if this is
the same as your internal state. Note that you must return a reference so
if you create a temporary state you must do so into an internal object that
persists at least until the next step. If this doesn't make sense for your
%Study you should throw an exception with a helpful message. **/
virtual const State& implementGetCurrentState() const = 0;
/** This should be a reference to the internal object that you use to
represent the furthest your %Study algorithm has progressed along the
generated trajectory. If this doesn't make sense for your %Study you
should throw an exception with a helpful message. **/
virtual const State& implementGetInternalState() const = 0;
/** This should be a writable reference to the same object returned by
getInternalState(). This should be the state that you want an event
handler to modify to affect the subsequent trajectory. If this doesn't make
sense for your %Study you should throw an exception with a helpful
message. **/
virtual State& implementUpdInternalState() = 0;
/** This should be the accuracy you are currently using, not necessarily
regurgitating a user setting. If this doesn't make sense for your
particular concrete %Study, just return `NaN`. Make sure your documentation
explains exactly what is meant by "accuracy" in your %Study. **/
virtual Real implementGetAccuracyInUse() const = 0;
/** This should be the constraint tolerance you are currently using, not
necessarily regurgitating a user setting. If this doesn't make sense for
your particular concrete %Study, just return `NaN`. Make sure your
documentation explains exactly what is meant by "constraint tolerance" in
your %Study. **/
virtual Real implementGetConstraintToleranceInUse() const = 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment