当前位置: 首页>>代码示例>>C++>>正文


C++ InputConfig::SetDefaults方法代码示例

本文整理汇总了C++中InputConfig::SetDefaults方法的典型用法代码示例。如果您正苦于以下问题:C++ InputConfig::SetDefaults方法的具体用法?C++ InputConfig::SetDefaults怎么用?C++ InputConfig::SetDefaults使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InputConfig的用法示例。


在下文中一共展示了InputConfig::SetDefaults方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

// Read the data files
void
InputEvents::LoadDefaults(InputConfig &input_config)
{
    // Get defaults
    input_config.SetDefaults();

    if (IsAltair()) {
#include "InputEvents_altair.cpp"
        apply_defaults(input_config,
                       default_modes,
                       default_events,
                       ARRAY_SIZE(default_events),
                       default_gesture2event,
                       default_key2event, default_gc2event, default_n2event,
                       default_labels);
    } else {
#include "InputEvents_default.cpp"
        apply_defaults(input_config,
                       default_modes,
                       default_events,
                       ARRAY_SIZE(default_events),
                       default_gesture2event,
                       default_key2event, default_gc2event, default_n2event,
                       default_labels);
    }
}
开发者ID:RBE-Avionik,项目名称:xcsoar,代码行数:27,代码来源:InputDefaults.cpp

示例2: assert

static void
apply_defaults(InputConfig &input_config,
               const TCHAR *const* default_modes,
               const InputConfig::Event *default_events,
               unsigned num_default_events,
               const flat_gesture_map *default_gesture2event,
               const flat_event_map *default_key2event,
               const flat_event_map *default_gc2event,
               const flat_event_map *default_n2event,
               const flat_label *default_labels)
{
  assert(num_default_events <= InputConfig::MAX_EVENTS);

  input_config.SetDefaults();
  while (*default_modes != NULL)
    input_config.AppendMode(*default_modes++);

  input_config.events.resize(num_default_events + 1);
  std::copy(default_events, default_events + num_default_events,
            input_config.events.begin() + 1);

  while (default_gesture2event->event > 0) {
    input_config.Gesture2Event.add(default_gesture2event->data,
                                   default_gesture2event->event);
    ++default_gesture2event;
  }
  
  while (default_key2event->event > 0) {
    input_config.Key2Event[default_key2event->mode][default_key2event->key] =
      default_key2event->event;
    ++default_key2event;
  }

  while (default_gc2event->event > 0) {
    input_config.GC2Event[default_gc2event->key] =
      default_gc2event->event;
    ++default_gc2event;
  }

  while (default_n2event->event > 0) {
    input_config.N2Event[default_n2event->key] =
      default_n2event->event;
    ++default_n2event;
  }

  while (default_labels->label != NULL) {
    makeLabel(input_config,
              (InputEvents::Mode)default_labels->mode,
              default_labels->label,
              default_labels->location, default_labels->event);
    ++default_labels;
  }
}
开发者ID:StefanL74,项目名称:XCSoar,代码行数:53,代码来源:InputDefaults.cpp

示例3: main

int main(int argc, char **argv)
{
  Args args(argc, argv, "PATH");
  const char *path = args.ExpectNext();
  args.ExpectEnd();

  FileLineReader reader(path);
  if (reader.error()) {
    fprintf(stderr, "Failed to open input file\n");
    return 1;
  }

  InputConfig config;
  config.SetDefaults();
  ParseInputFile(config, reader);

  for (unsigned mode = 0; mode < config.modes.size(); ++mode) {
    _tprintf(_T("Mode '%s'\n"), config.modes[mode].c_str());

    for (unsigned key = 0; key < InputConfig::MAX_KEY; ++key) {
      unsigned event = config.Key2Event[mode][key];
      assert(event < InputConfig::MAX_EVENTS);
      if (event == 0)
        continue;

      printf("  Key 0x%x\n", key);
      do {
        Dump(config.events[event], event);
        assert(config.events[event].next < InputConfig::MAX_EVENTS);
        event = config.events[event].next;
      } while (event > 0);
    }

    for (unsigned i = 0; i < Menu::MAX_ITEMS; ++i) {
      const MenuItem &mi = config.menus[mode][i];
      if (mi.IsDefined()) {
        _tprintf(_T("  Menu[%u] = '%s'\n"), i, mi.label);
        unsigned event = mi.event;
        assert(event < InputConfig::MAX_EVENTS);
        do {
          Dump(config.events[event], event);
          assert(config.events[event].next < InputConfig::MAX_EVENTS);
          event = config.events[event].next;
        } while (event > 0);
      }
    }
  }

  return 0;
}
开发者ID:Adrien81,项目名称:XCSoar,代码行数:50,代码来源:RunInputParser.cpp

示例4: while

void
ParseInputFile(InputConfig &config, TLineReader &reader)
{
  // TODO code - Safer sizes, strings etc - use C++ (can scanf restrict length?)

  // Multiple modes (so large string)
  EventBuilder current;
  current.clear();

  int line = 0;

  // Read from the file
  TCHAR *buffer;
  while ((buffer = reader.ReadLine()) != NULL) {
    TrimRight(buffer);
    line++;

    const TCHAR *key, *value;

    // experimental: if the first line is "#CLEAR" then the whole default config is cleared
    //               and can be overwritten by file
    if (line == 1 && StringIsEqual(buffer, _T("#CLEAR"))) {
      config.SetDefaults();
    } else if (buffer[0] == _T('\0')) {
      // Check valid line? If not valid, assume next record (primative, but works ok!)
      // General checks before continue...
      current.commit(config, line);

      // Clear all data.
      current.clear();

    } else if (StringIsEmpty(buffer) || buffer[0] == _T('#')) {
      // Do nothing - we probably just have a comment line
      // NOTE: Do NOT display buffer to user as it may contain an invalid stirng !

    } else if (parse_assignment(buffer, key, value)) {
      if (StringIsEqual(key, _T("mode"))) {
        current.mode = value;
      } else if (StringIsEqual(key, _T("type"))) {
        current.type = value;
      } else if (StringIsEqual(key, _T("data"))) {
        current.data = value;
      } else if (StringIsEqual(key, _T("event"))) {
        if (_tcslen(value) < 256) {
          TCHAR d_event[256] = _T("");
          TCHAR d_misc[256] = _T("");
          int ef;

          #if defined(__BORLANDC__)
          memset(d_event, 0, sizeof(d_event));
          memset(d_misc, 0, sizeof(d_event));
          if (_tcschr(value, ' ') == NULL) {
            _tcscpy(d_event, value);
          } else {
          #endif

          ef = _stscanf(value, _T("%[^ ] %[A-Za-z0-9 \\/().,]"), d_event,
              d_misc);

          #if defined(__BORLANDC__)
          }
          #endif

          if ((ef == 1) || (ef == 2)) {

            // TODO code: Consider reusing existing identical events

            pt2Event event = InputEvents::findEvent(d_event);
            if (event) {
              TCHAR *allocated = UnescapeBackslash(d_misc);
              current.event_id = config.AppendEvent(event, allocated,
                                                    current.event_id);

              /* not freeing the string, because
                 InputConfig::AppendEvent() stores the string point
                 without duplicating it; strictly speaking, this is a
                 memory leak, but the input file is only loaded once
                 at startup, so this is acceptable; in return, we
                 don't have to duplicate the hard-coded defaults,
                 which saves some memory */
              //free(allocated);

            } else {
              LogStartUp(_T("Invalid event type: %s at %i"), d_event, line);
            }
          } else {
            LogFormat("Invalid event type at %i", line);
          }
        }
      } else if (StringIsEqual(key, _T("label"))) {
        current.label = value;
      } else if (StringIsEqual(key, _T("location"))) {
        current.location = ParseUnsigned(value);

      } else {
        LogStartUp(_T("Invalid key/value pair %s=%s at %i"), key, value, line);
      }
    } else  {
      LogFormat("Invalid line at %i", line);
    }
//.........这里部分代码省略.........
开发者ID:Tjeerdm,项目名称:XCSoarDktjm,代码行数:101,代码来源:InputParser.cpp

示例5: assert

static void
apply_defaults(InputConfig &input_config,
               const TCHAR *const* default_modes,
               const InputConfig::Event *default_events,
               unsigned num_default_events,
               const flat_gesture_map *default_gesture2event,
               const flat_event_map *default_key2event,
               const flat_event_map *default_gc2event,
               const flat_event_map *default_n2event,
               const flat_label *default_labels)
{
    assert(num_default_events <= InputConfig::MAX_EVENTS);

    input_config.SetDefaults();
    while (*default_modes != NULL)
        input_config.AppendMode(*default_modes++);

    input_config.events.resize(num_default_events + 1);
    std::copy_n(default_events, num_default_events,
                input_config.events.begin() + 1);

    while (default_gesture2event->event > 0) {
        input_config.Gesture2Event.Add(default_gesture2event->data,
                                       default_gesture2event->event);
        ++default_gesture2event;
    }

    while (default_key2event->event > 0) {
        unsigned key_code_idx = default_key2event->key;
        auto key_2_event = input_config.Key2Event;
#if defined(ENABLE_SDL) && (SDL_MAJOR_VERSION >= 2)
        if (default_key2event->key & SDLK_SCANCODE_MASK) {
            key_2_event = input_config.Key2EventNonChar;
            key_code_idx &= ~SDLK_SCANCODE_MASK;
        }
#endif
        key_2_event[default_key2event->mode][key_code_idx] =
            default_key2event->event;
        ++default_key2event;
    }

    while (default_gc2event->event > 0) {
        input_config.GC2Event[default_gc2event->key] =
            default_gc2event->event;
        ++default_gc2event;
    }

    while (default_n2event->event > 0) {
        input_config.N2Event[default_n2event->key] =
            default_n2event->event;
        ++default_n2event;
    }

    while (default_labels->label != NULL) {
        makeLabel(input_config,
                  (InputEvents::Mode)default_labels->mode,
                  default_labels->label,
                  default_labels->location, default_labels->event);
        ++default_labels;
    }
}
开发者ID:RBE-Avionik,项目名称:xcsoar,代码行数:61,代码来源:InputDefaults.cpp


注:本文中的InputConfig::SetDefaults方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。