///////////////////////////////////////////////////////////////////////////// // Name: options.h // Author: Laurent Pugin // Created: 2005 // Copyright (c) Authors and others. All rights reserved. ///////////////////////////////////////////////////////////////////////////// #ifndef __VRV_OPTIONS_H__ #define __VRV_OPTIONS_H__ #ifdef CUSTOM_VEROVIO_OPTIONS #include "custom_options.h" #else #include #include #include //---------------------------------------------------------------------------- #include "attalternates.h" #include "atttypes.h" #include "jsonxx.h" //---------------------------------------------------------------------------- namespace vrv { class OptionGrp; //---------------------------------------------------------------------------- // Default scaling (%) and spacing (units) values //---------------------------------------------------------------------------- #define DEFAULT_SCALE 100 #define MIN_SCALE 1 #define MAX_SCALE 1000 //---------------------------------------------------------------------------- // Options //---------------------------------------------------------------------------- // the space between each lyric line in units #define TEMP_LYRIC_LINE_SPACE 5.0 // the key signature spacing factor #define TEMP_KEYSIG_STEP 0.4 // the key signature spacing factor for natural (usually slighly larger) #define TEMP_KEYSIG_NATURAL_STEP 0.6 //---------------------------------------------------------------------------- // Option defines //---------------------------------------------------------------------------- enum option_BREAKS { BREAKS_none = 0, BREAKS_auto, BREAKS_line, BREAKS_smart, BREAKS_encoded }; enum option_CONDENSE { CONDENSE_none = 0, CONDENSE_auto, CONDENSE_all, CONDENSE_encoded }; enum option_FOOTER { FOOTER_none = 0, FOOTER_auto, FOOTER_encoded, FOOTER_always }; enum option_HEADER { HEADER_none = 0, HEADER_auto, HEADER_encoded }; enum option_MULTIRESTSTYLE { MULTIRESTSTYLE_auto = 0, MULTIRESTSTYLE_default, MULTIRESTSTYLE_block, MULTIRESTSTYLE_symbols }; enum option_SYSTEMDIVIDER { SYSTEMDIVIDER_none = 0, SYSTEMDIVIDER_auto, SYSTEMDIVIDER_left, SYSTEMDIVIDER_left_right }; //---------------------------------------------------------------------------- // Option //---------------------------------------------------------------------------- /** * This class is a base class of each styling parameter */ class Option { public: // constructors and destructors Option() { m_isSet = false; m_shortOption = 0; m_isCmdOnly = false; } virtual ~Option() {} virtual void CopyTo(Option *option); void SetKey(const std::string &key) { m_key = key; } std::string GetKey() const { return m_key; } virtual bool SetValueBool(bool value); virtual bool SetValueDbl(double value); virtual bool SetValueArray(const std::vector &values); virtual bool SetValue(const std::string &value); virtual std::string GetStrValue() const; virtual std::string GetDefaultStrValue() const; void SetInfo(const std::string &title, const std::string &description); std::string GetTitle() const { return m_title; } std::string GetDescription() const { return m_description; } bool IsSet() const { return m_isSet; } void SetShortOption(char shortOption, bool isCmdOnly); char GetShortOption() const { return m_shortOption; } bool IsCmdOnly() const { return m_isCmdOnly; } /** * Return a JSON object for the option */ jsonxx::Object ToJson() const; public: //----------------// // Static members // //----------------// /** * Static maps used my OptionIntMap objects. Set in OptIntMap::Init */ static const std::map s_breaks; static const std::map s_condense; static const std::map s_footer; static const std::map s_header; static const std::map s_multiRestStyle; static const std::map s_systemDivider; protected: std::string m_title; std::string m_description; bool m_isSet; private: std::string m_key; /* the character for a short option - not set (0) by default) */ char m_shortOption; /* a flag indicating that the option is available only on the command line */ bool m_isCmdOnly; }; //---------------------------------------------------------------------------- // OptionBool //---------------------------------------------------------------------------- /** * This class is for boolean styling params */ class OptionBool : public Option { public: // constructors and destructors OptionBool() { m_defaultValue = false; } virtual ~OptionBool() {} virtual void CopyTo(Option *option); void Init(bool defaultValue); virtual bool SetValueBool(bool value); virtual bool SetValueDbl(double value); virtual bool SetValue(const std::string &value); virtual std::string GetStrValue() const; virtual std::string GetDefaultStrValue() const; bool GetValue() const { return m_value; } bool GetDefault() const { return m_defaultValue; } bool SetValue(bool value); private: // public: // private: bool m_value; bool m_defaultValue; }; //---------------------------------------------------------------------------- // OptionDbl //---------------------------------------------------------------------------- /** * This class is for integer styling params */ class OptionDbl : public Option { public: // constructors and destructors OptionDbl() { m_defaultValue = 0.0; m_minValue = 0.0; m_maxValue = 0.0; } virtual ~OptionDbl() {} virtual void CopyTo(Option *option); void Init(double defaultValue, double minValue, double maxValue); virtual bool SetValueDbl(double value); virtual bool SetValue(const std::string &value); virtual std::string GetStrValue() const; virtual std::string GetDefaultStrValue() const; double GetValue() const { return m_value; } double GetDefault() const { return m_defaultValue; } double GetMin() const { return m_minValue; } double GetMax() const { return m_maxValue; } bool SetValue(double value); private: // public: // private: double m_value; double m_defaultValue; double m_minValue; double m_maxValue; }; //---------------------------------------------------------------------------- // OptionInt //---------------------------------------------------------------------------- /** * This class is for integer styling params */ class OptionInt : public Option { public: // constructors and destructors OptionInt() { m_defaultValue = 0; m_minValue = 0; m_maxValue = 0; } virtual ~OptionInt() {} virtual void CopyTo(Option *option); void Init(int defaultValue, int minValue, int maxValue, bool definitionFactor = false); virtual bool SetValueDbl(double value); virtual bool SetValue(const std::string &value); virtual std::string GetStrValue() const; virtual std::string GetDefaultStrValue() const; int GetValue() const; int GetUnfactoredValue() const; int GetDefault() const { return m_defaultValue; } int GetMin() const { return m_minValue; } int GetMax() const { return m_maxValue; } bool SetValue(int value); private: // public: // private: int m_value; int m_defaultValue; int m_minValue; int m_maxValue; bool m_definitionFactor; }; //---------------------------------------------------------------------------- // OptionString //---------------------------------------------------------------------------- /** * This class is for string styling params */ class OptionString : public Option { public: // constructors and destructors OptionString() {} virtual ~OptionString() {} virtual void CopyTo(Option *option); void Init(const std::string &defaultValue); virtual bool SetValue(const std::string &value); virtual std::string GetStrValue() const { return m_value; } virtual std::string GetDefaultStrValue() const { return m_defaultValue; } std::string GetValue() const { return m_value; } std::string GetDefault() const { return m_defaultValue; } private: // public: // private: std::string m_value; std::string m_defaultValue; }; //---------------------------------------------------------------------------- // OptionArray //---------------------------------------------------------------------------- /** * This class is for array (string) styling params */ class OptionArray : public Option { public: // constructors and destructors OptionArray() {} virtual ~OptionArray() {} virtual void CopyTo(Option *option); void Init(); virtual bool SetValueArray(const std::vector &values); virtual bool SetValue(const std::string &value); virtual std::string GetStrValue() const; virtual std::string GetDefaultStrValue() const; std::vector GetValue() const { return m_values; } std::vector GetDefault() const { return m_defaultValues; } bool SetValue(std::vector const &values); private: // public: // private: std::vector m_values; std::vector m_defaultValues; }; //---------------------------------------------------------------------------- // OptionIntMap //---------------------------------------------------------------------------- /** * This class is for map break options */ class OptionIntMap : public Option { public: // constructors and destructors OptionIntMap(); virtual ~OptionIntMap() {} virtual void CopyTo(Option *option); void Init(int defaultValue, const std::map *values); virtual bool SetValue(const std::string &value); virtual std::string GetStrValue() const; virtual std::string GetDefaultStrValue() const; int GetValue() const { return m_value; } int GetDefault() const { return m_defaultValue; } bool SetValue(int value); std::vector GetStrValues(bool withoutDefault) const; std::string GetStrValuesAsStr(bool withoutDefault) const; private: // public: // private: const std::map *m_values; int m_value; int m_defaultValue; }; //---------------------------------------------------------------------------- // OptionStaffrel //---------------------------------------------------------------------------- /** * This class is for map styling params */ class OptionStaffrel : public Option { public: // constructors and destructors OptionStaffrel(){}; virtual ~OptionStaffrel(){}; virtual void CopyTo(Option *option); // Alternate type style cannot have a restricted list of possible values void Init(data_STAFFREL defaultValue); virtual bool SetValue(const std::string &value); virtual std::string GetStrValue() const; virtual std::string GetDefaultStrValue() const; // For altenate types return a reference to the value // Alternatively we can have a values vector for each sub-type const data_STAFFREL *GetValueAlternate() const { return &m_value; } const data_STAFFREL *GetDefaultAlernate() const { return &m_defaultValue; } private: // public: // private: data_STAFFREL m_value; data_STAFFREL m_defaultValue; }; //---------------------------------------------------------------------------- // OptionStaffrelBasic //---------------------------------------------------------------------------- /** * This class is for map styling params */ class OptionStaffrelBasic : public Option { public: // constructors and destructors OptionStaffrelBasic(){}; virtual ~OptionStaffrelBasic(){}; virtual void CopyTo(Option *option); void Init(data_STAFFREL_basic defaultValue, const std::vector &values); virtual bool SetValue(const std::string &value); virtual std::string GetStrValue() const; virtual std::string GetDefaultStrValue() const; data_STAFFREL_basic GetValue() const { return m_value; } data_STAFFREL_basic GetDefault() const { return m_defaultValue; } private: // public: // private: std::vector m_values; data_STAFFREL_basic m_value; data_STAFFREL_basic m_defaultValue; }; //---------------------------------------------------------------------------- // OptionJson //---------------------------------------------------------------------------- /// Distinguish whether Json is passed directly or should be read from file enum class JsonSource { String, FilePath }; /** * This class is for Json input params */ class OptionJson : public Option { using JsonPath = std::vector>; public: /** * @name Constructor, destructor and initialization */ ///@{ OptionJson() = default; virtual ~OptionJson() = default; void CopyTo(Option *option) override; void Init(JsonSource source, const std::string &defaultValue); ///@} /** * Member access */ JsonSource GetSource() const; jsonxx::Object GetValue(bool getDefault = false) const; /** * Interface methods: accessing values as string */ ///@{ bool SetValue(const std::string &value) override; std::string GetStrValue() const override; std::string GetDefaultStrValue() const override; ///@} /** * Accessing values as json node path */ ///@{ bool HasValue(const std::vector &jsonNodePath) const; int GetIntValue(const std::vector &jsonNodePath, bool getDefault = false) const; double GetDoubleValue(const std::vector &jsonNodePath, bool getDefault = false) const; bool UpdateNodeValue(const std::vector &jsonNodePath, const std::string &value); ///@} protected: JsonPath StringPath2NodePath(const jsonxx::Object &obj, const std::vector &jsonNodePath) const; /// Read json from string or file bool ReadJson(jsonxx::Object &output, const std::string &input) const; private: JsonSource m_source = JsonSource::String; jsonxx::Object m_values; jsonxx::Object m_defaultValues; }; //---------------------------------------------------------------------------- // OptionGrp //---------------------------------------------------------------------------- /** * This class is a base class of each styling parameter */ class OptionGrp { public: // constructors and destructors OptionGrp() {} virtual ~OptionGrp() {} void SetLabel(const std::string &label, const std::string &id) { m_label = label; m_id = id; } std::string GetLabel() const { return m_label; } std::string GetId() const { return m_id; } void AddOption(Option *option) { m_options.push_back(option); } const std::vector