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

もう少しいい感じに書けるかも。Keys/DefaultValuesを内包する型パラメータの指定は考察... #43

Open
github-actions bot opened this issue Jun 7, 2020 · 0 comments
Labels

Comments

@github-actions
Copy link

github-actions bot commented Jun 7, 2020

もう少しいい感じに書けるかも。Keys/DefaultValuesを内包する型パラメータの指定は考察が必要

// TODO: もう少しいい感じに書けるかも。Keys/DefaultValuesを内包する型パラメータの指定は考察が必要

        /**
         * @brief 指定された値をconfigVolatileに書き込みます
         * 
         * @tparam T 書き込むデータの型
         * @param isOverwrite すでに値がセットされている場合でも上書きする場合はtrue
         * @param key セット対象のKey
         * @param value セットする値
         */
        template<typename T>
        void write(bool isOverwrite, const char* key, T& value) {
            if (isOverwrite || !this->configVolatile.containsKey(key)) { 
                this->configVolatile[key] = value;
            }
        }

        /**
         * @brief 指定されたKeyの値を読み出します
         * 
         * @tparam T 読み出す型
         * @param key 読み出し対象のKey
         * @param value 読みだしたデータの書き込み先、Keyが存在しない場合は操作しません
         * @return true 読み出し成功
         * @return false 読み出し失敗
         */
        template<typename T>
        bool read(const char* key, T& value) {
            // Keyが存在しない
            if (!this->configVolatile.containsKey(key)) {
                return false;
            }
            // 値を読み出す
            value = this->configVolatile[key];
            return true;
        }
        /**
         * @brief すべての値を初期値で上書きします
         * @param isMigrate 存在しない値のみを上書きする場合はtrue
         * 
         * @note 完全新規のconfigを生成する場合はisMigrate=falseで実行する
         */
        void init(bool isMigrate) {
            // 一通り必要な初期値をセット
            // TODO: もう少しいい感じに書けるかも。Keys/DefaultValuesを内包する型パラメータの指定は考察が必要
            this->write(!isMigrate, GlobalConfigKeys::Identifier              , GlobalConfigDefaultValues::Identifier);
            this->write(!isMigrate, GlobalConfigKeys::Date                    , GlobalConfigDefaultValues::Date);
            this->write(!isMigrate, GlobalConfigKeys::Time                    , GlobalConfigDefaultValues::Time);
            this->write(!isMigrate, GlobalConfigKeys::GroveTaskFps            , GlobalConfigDefaultValues::GroveTaskFps);
            this->write(!isMigrate, GlobalConfigKeys::ButtonTaskFps           , GlobalConfigDefaultValues::ButtonTaskFps);
            this->write(!isMigrate, GlobalConfigKeys::UiTaskFps               , GlobalConfigDefaultValues::UiTaskFps);
            this->write(!isMigrate, GlobalConfigKeys::BrightnessHoldMs        , GlobalConfigDefaultValues::BrightnessHoldMs);
            this->write(!isMigrate, GlobalConfigKeys::BrightnessTransitionMs  , GlobalConfigDefaultValues::BrightnessTransitionMs);

            // migrationでなければNonVolatile側にも反映(this->clear()対策)
            if (!isMigrate) {
                this->configNonVolatile = this->configVolatile;
            }
        }

        /**
ndex ffbaee7..fffdaa7 100644
++ b/src/UiTask.cpp

ff16bf4e6a41f4415616df49d0e79100a6a39e5b

@github-actions github-actions bot added the todo label Jun 7, 2020
@kamiyaowl kamiyaowl added this to To do in やること Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
やること
  
To do
Development

No branches or pull requests

0 participants