<commit_before>#include <IOKit/IOLib.h>

#include "Config.hpp"
#include "EventWatcher.hpp"
#include "IOLogWrapper.hpp"
#include "PointingRelativeToKey.hpp"

namespace org_pqrs_KeyRemap4MacBook {
  namespace RemapFunc {
    PointingRelativeToKey::PointingRelativeToKey(void) :
      current_keytokey_(NULL)
    {
      keyrepeat_ic_.begin();

      keytokey_[KEYTOKEY_UP].add(KeyCode::VK_PSEUDO_KEY);
      keytokey_[KEYTOKEY_DOWN].add(KeyCode::VK_PSEUDO_KEY);
      keytokey_[KEYTOKEY_LEFT].add(KeyCode::VK_PSEUDO_KEY);
      keytokey_[KEYTOKEY_RIGHT].add(KeyCode::VK_PSEUDO_KEY);
    }

    PointingRelativeToKey::~PointingRelativeToKey(void)
    {}

    void
    PointingRelativeToKey::add(unsigned int datatype, unsigned int newval)
    {
      switch (datatype) {
        case BRIDGE_DATATYPE_POINTINGRELATIVE:
        {
          PointingRelative val(newval);
          if (val == PointingRelative::UP)    { current_keytokey_ = &(keytokey_[KEYTOKEY_UP]);    }
          if (val == PointingRelative::DOWN)  { current_keytokey_ = &(keytokey_[KEYTOKEY_DOWN]);  }
          if (val == PointingRelative::LEFT)  { current_keytokey_ = &(keytokey_[KEYTOKEY_LEFT]);  }
          if (val == PointingRelative::RIGHT) { current_keytokey_ = &(keytokey_[KEYTOKEY_RIGHT]); }
          break;
        }

        case BRIDGE_DATATYPE_KEYCODE:
        case BRIDGE_DATATYPE_CONSUMERKEYCODE:
        case BRIDGE_DATATYPE_POINTINGBUTTON:
        case BRIDGE_DATATYPE_OPTION:
        {
          if (! current_keytokey_) {
            IOLOG_ERROR("Invalid PointingRelativeToKey::add\n");
          } else {
            current_keytokey_->add(datatype, newval);
          }

          break;
        }

        case BRIDGE_DATATYPE_FLAGS:
        {
          if (! current_keytokey_) {
            fromFlags_ = Flags(newval);

            keytokey_[KEYTOKEY_UP].add(datatype, newval);
            keytokey_[KEYTOKEY_DOWN].add(datatype, newval);
            keytokey_[KEYTOKEY_LEFT].add(datatype, newval);
            keytokey_[KEYTOKEY_RIGHT].add(datatype, newval);
          } else {
            current_keytokey_->add(datatype, newval);
          }
          break;
        }

        default:
          IOLOG_ERROR("PointingRelativeToKey::add invalid datatype:%d\n", datatype);
          break;
      }<commit_msg>cleanup<commit_after>#include <IOKit/IOLib.h>

#include "Config.hpp"
#include "EventWatcher.hpp"
#include "IOLogWrapper.hpp"
#include "PointingRelativeToKey.hpp"

namespace org_pqrs_KeyRemap4MacBook {
  namespace RemapFunc {
    PointingRelativeToKey::PointingRelativeToKey(void) :
      current_keytokey_(NULL)
    {
      keyrepeat_ic_.begin();

      for (size_t i = 0; i < KEYTOKEY__END__; ++i) {
        keytokey_[i].add(KeyCode::VK_PSEUDO_KEY);
      }
    }

    PointingRelativeToKey::~PointingRelativeToKey(void)
    {}

    void
    PointingRelativeToKey::add(unsigned int datatype, unsigned int newval)
    {
      switch (datatype) {
        case BRIDGE_DATATYPE_POINTINGRELATIVE:
        {
          PointingRelative val(newval);
          if (val == PointingRelative::UP)    { current_keytokey_ = &(keytokey_[KEYTOKEY_UP]);    }
          if (val == PointingRelative::DOWN)  { current_keytokey_ = &(keytokey_[KEYTOKEY_DOWN]);  }
          if (val == PointingRelative::LEFT)  { current_keytokey_ = &(keytokey_[KEYTOKEY_LEFT]);  }
          if (val == PointingRelative::RIGHT) { current_keytokey_ = &(keytokey_[KEYTOKEY_RIGHT]); }
          break;
        }

        case BRIDGE_DATATYPE_KEYCODE:
        case BRIDGE_DATATYPE_CONSUMERKEYCODE:
        case BRIDGE_DATATYPE_POINTINGBUTTON:
        case BRIDGE_DATATYPE_OPTION:
        {
          if (! current_keytokey_) {
            IOLOG_ERROR("Invalid PointingRelativeToKey::add\n");
          } else {
            current_keytokey_->add(datatype, newval);
          }

          break;
        }

        case BRIDGE_DATATYPE_FLAGS:
        {
          if (! current_keytokey_) {
            fromFlags_ = Flags(newval);

            for (size_t i = 0; i < KEYTOKEY__END__; ++i) {
              keytokey_[i].add(datatype, newval);
            }
          } else {
            current_keytokey_->add(datatype, newval);
          }
          break;
        }

        default:
          IOLOG_ERROR("PointingRelativeToKey::add invalid datatype:%d\n", datatype);
          break;
      }
{'fraction_non_alphanumeric': 0.10694572217111316, 'fraction_numerical': 0.0009199632014719411, 'mean_word_length': 2.535772357723577, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4733561', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1450, 'n_words': 197}