/** @file sample for Glib::PatternSpec
 *
 * Last CVS checkin:
 * $Date: $
 * $Author: scheff $
 */

/**************************************************************************/

// standard C/C++ header:
#include <iostream>
#include <string>

// Gnome header:
#include <glibmm/init.h>
#include <glibmm/pattern.h>

using namespace std;

/**************************************************************************/

/** waits for user confirm.
 *
 * @param action text with next action
 */
static void pause(const char *action)
{
  cout << "Press [ENTER] to " << action << ": " << flush;
  string str; getline(cin, str);
}

/** provides the main function of application.
 *
 * @param argc number of command line arguments
 * @param argv pointer to array of pointers to strings with command line
 *        arguments
 * @return 0 ... application exited regularly\n
 *         else ... execution of application aborted
 */
int main(int argc, char *argv[])
{
  Glib::init();
  pause("start");
  // sample data
  const char *patterns[] = {
    "*",
    "Base*",
    "Base/*",
    "*Base*",
    "Robot*",
    "*Robot*",
    "*/Robot",
    "*/Robot*",
    "*/Robot/*"
  };
  int m = sizeof patterns / sizeof patterns[0];
  const char *samples[] = {
    "",
    "Base",
    "Base/Resource",
    "Base/Resource/Robot",
    "Base/Resource/Robot/KUKA",
    "Base/Resource/Robot/KUKA/KR360"
  };
  int n = sizeof samples / sizeof samples[0];
  // for each pattern and each sample do:
  for (int i = 0; i < m; ++i) {
    Glib::PatternSpec patternSpec(patterns[i]);
    cout << "Pattern: '" << patterns[i] << "':" << endl;
    for (int j = 0; j < n; ++j) {
      const char *sample = samples[j];
      cout << "  Check '" << sample << "':" << endl
        << "    " << (patternSpec.match(sample) ? "OK." : "Not matching.")
        << endl;
    }
    // wait for confirm
    pause("continue");
  }
  // done
  pause("finish");
  return 0;
}

