Menu

Tree [119d76] master /
 History

HTTPS access


File Date Author Commit
 html 2012-07-31 rsz rsz [119d76] Fixed link in readme.
 src 2012-07-31 rsz rsz [363c20] Housekeeping after dir restructuring.
 test 2012-07-31 rsz rsz [363c20] Housekeeping after dir restructuring.
 LICENSE.MIT 2012-07-31 rsz rsz [363c20] Housekeeping after dir restructuring.
 Makefile 2012-07-31 rsz rsz [363c20] Housekeeping after dir restructuring.
 README.md 2012-07-31 rsz rsz [119d76] Fixed link in readme.

Read Me

Overview

ezOdometer is a C++ class for linear and non-linear positional
notation.

Just like an odometer in a car, this C++ class allows positional
counting, but with additional flexibility of using arbitrary
values per digit position so you can sequence instead of just
counting/incrementing. Each numerical position can be set by
a min,max,stride, each being positive or negative, or by using
a list of arbitrary unordered values, so you're not limited to
base 10 per position. This allows one to model multi-dimensional
array slicing (aka hyper-slabbing) or permutation. It's a single
header templated implementation to minimize memory usage and
uses STL.

Features

  • Single C++ header implementation.
  • Only depends on STL.

Download

Source code

Git

C++ Usage

#include "ezOdometer.hpp"
#include <assert.h>

int main() {
  // Simple base-2 counter up to decimal 7 (111).
  ez::ezOdometer<int> o1(3);
  o1.setrange(0,0,1);
  o1.setrange(1,0,1);
  o1.setrange(2,0,1);

  while(!o1.isDone()) {
    std::cout << "o1="; o1.print(); std::cout << "\n";
    ++o1;
  };

  // Prints:
  // o1=000
  // o1=001
  // o1=010
  // o1=011
  // o1=100
  // o1=101
  // o1=110
  // o1=111

  // Get the number of iterations if we printed each combo.
  assert( o1.getNumCombinations() == 2*2*2 );

  // Re-use odometer.
  o1.reset();
  // Make middle digit be a constant 0.
  o1.lock(1, 0);
  while(!o1.isDone()) {
    std::cout << "o1="; o1.print(); std::cout << "\n";
    ++o1;
  };

  // Prints:
  // o1=000
  // o1=001
  // o1=100
  // o1=101

  // Check if digit at this position reached its limit.
  o1.atLimit(2);

  // Now define odometer digits with min,max,stride.
  o1.reset();
  o1.setrange(0,-1,1);
  o1.setrange(2,2,10,3);
  while(!o1.isDone()) { ++o1; };

  // Now use custom arbitray digits for 4 value wide odometer.
  ez::ezCustomOdometer<int> o2(4);
  // Just min,max,stride.
  o2.setrange(0,-1,5,3);
  // Make the custom sequence.
  std::vector<int> values;
  values.push_back(-5);
  values.push_back(10);
  values.push_back(123);
  o2.setCustomValues(1,values);
  // Make more custom values.
  values.clear();
  values.push_back(9);
  values.push_back(99);
  o2.setCustomValues(2,values);
  // For the last digit, make it a constant "2".
  o2.setCustomValue(3,2);

  // This would print as:
  // o2=-1,-5,9,2
  // o2=-1,-5,99,2
  // o2=-1,10,9,2
  // o2=-1,10,99,2
  // o2=-1,123,9,2
  // o2=-1,123,99,2
  // o2=2,-5,9,2
  // o2=2,-5,99,2
  // o2=2,10,9,2
  // o2=2,10,99,2
  // o2=2,123,9,2
  // o2=2,123,99,2
  // o2=5,-5,9,2
  // o2=5,-5,99,2
  // o2=5,10,9,2
  // o2=5,10,99,2
  // o2=5,123,9,2
  // o2=5,123,99,2
  // o2=5,123,99,2

  // Clone the odometer.
  ez::ezCustomOdometer<int> o3(4);
  o3 = o2;

  // We can "normalize", so digits are from "0" to "n-1".
  o3.normalize();
  assert( o3.digits[0]==0 );
  assert( o3.digits[1]==0 );
  assert( o3.digits[2]==0 );
  assert( o3.digits[3]==0 );
  assert( o3.maxs[0]==2 );
  assert( o3.maxs[1]==2 );
  assert( o3.maxs[2]==0 );
  assert( o3.maxs[3]==0 );

  // Iterating would print:
  // o3=0,0,0,0
  // o3=0,1,0,0
  // o3=0,2,0,0
  // o3=1,0,0,0
  // o3=1,1,0,0
  // o3=1,2,0,0
  // o3=2,0,0,0
  // o3=2,1,0,0
  // o3=2,2,0,0
  // o3=2,2,0,0

  return 0;
}

Installation

make test
make memtest
make clean
sudo make install PREFIX=/usr/local

Distribution

make html
make clean
make dist VER=0.1.3

Publishing

ssh -t rsz,ezodometer@shell.sourceforge.net create
scp html/* rsz,ezodometer@shell.sourceforge.net:/home/project-web/ezodometer/htdocs
scp ../ezOdometer-0.1.3.tar.gz rsz,ezodometer@shell.sourceforge.net:/home/frs/project/e/ez/ezodometer

License

Copyright 2011, 2012 Remik Ziemlinski (see LICENSE.MIT)

<link rel="stylesheet" href="http://yandex.st/highlightjs/7.0/styles/default.min.css">

<script src="http://yandex.st/highlightjs/7.0/highlight.min.js"></script> <script>hljs.initHighlightingOnLoad();</script>