%%
%% This is file `tikz-timing-counters.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% tikz-timing.dtx  (with options: `tikz-timing-counters.sty')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from tikz-timing-counters.sty.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file tikz-timing.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%% Copyright (C) 2009-2012 by Martin Scharrer <martin@scharrer-online.de>
%% ----------------------------------------------------------------------
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Martin Scharrer.
%%
%% This work consists of the files tikz-timing.dtx and tikz-timing.ins
%% and the derived filebase tikz-timing*.sty.
%%
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{tikz-timing-counters}[%
    2017/12/20
    v0.7f
    tikz-timing library for counter values]
\newif\if@tikztiming@counter@wraps

\tikzset{%
  timing/new counter/.style={timing/counter/new={#1}},
  timing/counter/.cd,
  new/.code={\tikztiming@counter@new{#1}},
  new/.value required,
  opt/.cd,
  char/.initial=,
  char/.value required,
  reset char/.initial=,
  reset char/.value required,
  reset type/.is choice,
  reset type/width/.code={\def\tikztiming@resettype{0}},
  reset type/arg/.code={\def\tikztiming@resettype{1}},
  reset type/both/.code={\def\tikztiming@resettype{2}},
  reset type/Both/.code={\def\tikztiming@resettype{3}},
  half width char/.initial=,
  half width char/.value required,
  base/.initial=10,
  base/.value required,
  increment/.initial=1,
  increment/.value required,
  max value/.initial=,
  max value/.value required,
  min value/.initial=,
  min value/.value required,
  wraps/.is if=@tikztiming@counter@wraps,
  digits/.initial=,
  digits/.value required,
  fg style/.initial=,
  bg style/.initial=,
  text style/.initial=,
  text format/.initial=,
  fg style/.value required,
  bg style/.value required,
  text style/.value required,
  text format/.value required,
}
\def\tikztiming@counter@textformat{}%
\def\tikztimingcounter#1{%
  \csname tikztiming@counter@#1\endcsname
}
\def\tikztimingsetcounter#1#2{%
  \begingroup
    \pgfmathtruncatemacro\@tempa{#2}%
    \expandafter\global\expandafter\let\csname tikztiming@counter@#1\endcsname\@tempa
  \endgroup
}
\def\tikztiming@counter@new#1{%
 \begingroup
  \def\tikztiming@resettype{0}%
  \pgfqkeys{/tikz/timing/counter/opt}{#1}%
  \tikzset{timing/counter/opt/char/.get=\counterchar}%
  \ifx\counterchar\empty
    \PackageError{tikz-timing-counters}{Counter character must be given using
    the 'char' key!}{}%
    \endgroup
  \else
    \pgfkeys{/tikz/timing/counter/opt/min value/.get=\min}%
    \pgfkeys{/tikz/timing/counter/opt/max value/.get=\max}%
    \if@tikztiming@counter@wraps
      \ifx\min\empty
        \def\min{0}%
      \fi
      \ifx\max\empty
        \PackageError{tikz-timing-counters}{The option 'wraps' needs the option 'max value' to be set!}{}%
      \fi
      \def\@tempb{%
        \noexpand\tikztiming@counter@wrap%
          {\expandafter\unexpanded\expandafter{\min}}%
          {\expandafter\unexpanded\expandafter{\max}}%
      }%
    \else
      \ifx\min\empty
        \ifx\max\empty
          \let\@tempb\empty
        \else
          \def\@tempb{%
            \noexpand\tikztiming@counter@maxsat%
              {\expandafter\unexpanded\expandafter{\max}}%
          }%
        \fi
      \else
        \ifx\max\empty
          \def\@tempb{%
            \noexpand\tikztiming@counter@minsat%
              {\expandafter\unexpanded\expandafter{\min}}%
          }%
        \else
          \def\@tempb{%
            \noexpand\tikztiming@counter@minmaxsat%
              {\expandafter\unexpanded\expandafter{\min}}%
              {\expandafter\unexpanded\expandafter{\max}}%
          }%
        \fi
      \fi
    \fi
    \pgfkeys{/tikz/timing/counter/opt/fg style/.get=\fgstyle}%
    \pgfkeys{/tikz/timing/counter/opt/bg style/.get=\bgstyle}%
    \pgfkeys{/tikz/timing/counter/opt/text style/.get=\textstyle}%
    \pgfkeys{/tikz/timing/counter/opt/text format/.get=\textformat}%
    \pgfkeys{/tikz/timing/counter/opt/increment/.get=\increment}%
    \edef\@tempa{%
      \noexpand\tikztiming@counter@new@
        {\pgfkeysvalueof{/tikz/timing/counter/opt/char}}%
        {\pgfkeysvalueof{/tikz/timing/counter/opt/base}}%
        {\pgfkeysvalueof{/tikz/timing/counter/opt/half width char}}%
        {\pgfkeysvalueof{/tikz/timing/counter/opt/reset char}}%
        {\pgfkeysvalueof{/tikz/timing/counter/opt/digits}}%
        {\expandafter\unexpanded\expandafter{\increment}}%
        {\@tempb}%
        {\min}%
        {\tikztiming@resettype}%
        {\expandafter\unexpanded\expandafter{\fgstyle}}%
        {\expandafter\unexpanded\expandafter{\bgstyle}}%
        {\expandafter\unexpanded\expandafter{\textstyle}}%
        {\expandafter\unexpanded\expandafter{\textformat}}%
    }%
    \expandafter\expandafter\expandafter\endgroup
    \expandafter\@tempa
  \fi
}
\def\tikztiming@counter@new@#1#2#3#4#5#6#7#8#9{%
  \ifx\empty#8\empty
    \@namedef{tikztiming@counter@#1}{0}%
  \else
    \expandafter
    \pgfmathtruncatemacro\csname tikztiming@counter@#1\endcsname{#8}%
  \fi
  \tikztimingmetachar{#1}[1]{ { [timing/counter/#1] ##1D{[timing/counter/#1/text]\tikztiming@counter@vs{#1}{#2}{#5}{#6}{#7}} } }%
  \ifx\empty#3\empty
      \tikztiming@iflower{#1}{}%
        {\lowercase{\tikztimingmetachar{#1}}[1]%
          { { [timing/counter/#1] ##1d{[timing/counter/#1/text]\tikztiming@counter@vs{#1}{#2}{#5}{#6}{#7}}} }%
        }%
  \else
    \tikztimingmetachar{#3}[1]{%
      { [timing/counter/#1] ##1d{[timing/counter/#1/text]\tikztiming@counter@vs{#1}{#2}{#5}{#6}{#7}} }%
    }%
  \fi
  \ifx\empty#4\empty\else
    \ifcase0#9\relax
      \tikztimingmetachar{#4}[1]{[|/utils/exec=\tikztiming@counter@reset{#1}{##1}|]}%
    \or
      \tikztimingmetachar{#4}[2]{[|/utils/exec=\tikztimingsetcounter{#1}{##2}|]}%
    \or
      \uppercase{\tikztimingmetachar{#4}}[1]{[|/utils/exec=\tikztiming@counter@reset{#1}{##1}|]}%
      \lowercase{\tikztimingmetachar{#4}}[2]{[|/utils/exec=\tikztimingsetcounter{#1}{##2}|]}%
    \or
      \lowercase{\tikztimingmetachar{#4}}[1]{[|/utils/exec=\tikztiming@counter@reset{#1}{##1}|]}%
      \uppercase{\tikztimingmetachar{#4}}[2]{[|/utils/exec=\tikztimingsetcounter{#1}{##2}|]}%
    \fi
  \fi
  \tikztiming@counter@new@@{#1}%
}
\def\tikztiming@counter@new@@#1#2#3#4#5{%
  \tikzset{timing/counter/#1/.style={}}%
  \ifx\empty#2\empty\else
    \tikzset{timing/counter/#1/.append style={%
      /tikz/timing/d/.style={#2}%
    }}%
  \fi
  \ifx\empty#3\empty\else
    \tikzset{timing/counter/#1/.append style={%
      /tikz/timing/d/background/.style={#3}%
    }}%
  \fi
  \tikzset{timing/counter/#1/text/.style={#4}}%
  \ifx\empty#5\empty\else
    \tikzset{timing/counter/#1/.append style={%
      /utils/exec={\def\tikztiming@counter@textformat{#5}}%
    }}%
  \fi
}
\def\tikztiming@counter@reset#1#2{%
  \begingroup
    \pgfmathtruncatemacro\@tempa{round((#2)/\tikztiming@wscale)}%
    \expandafter\global\expandafter\let\csname tikztiming@counter@#1\endcsname\@tempa
  \endgroup
}
\def\tikztiming@counter@vs#1#2#3#4#5{%
  \begingroup
    \ifx\empty#3\empty\else
      \pgfmathsetbasenumberlength{#3}%
    \fi
    \ifnum#2=10
      \expandafter\expandafter\expandafter\tikztiming@counter@textformat
      \expandafter\expandafter\expandafter{\csname tikztiming@counter@#1\endcsname}%
    \else
      \pgfmathdectoBase\pgfmathresult{\@nameuse{tikztiming@counter@#1}}{#2}%
      \expandafter\tikztiming@counter@textformat\expandafter{\pgfmathresult}%
    \fi
    \edef\N{\@nameuse{tikztiming@counter@#1}}%
    \pgfmathtruncatemacro\N{\N + #4}%
    #5%
    \expandafter\global\expandafter\let\csname tikztiming@counter@#1\endcsname\N
  \endgroup
}
\def\tikztiming@counter@minsat#1{%
  \pgfmathtruncatemacro\MIN{#1}%
  \ifnum\N<\MIN \let\N\MIN \fi
}
\def\tikztiming@counter@maxsat#1{%
  \pgfmathtruncatemacro\MAX{#1}%
  \ifnum\N>\MAX \let\N\MAX \fi
}
\def\tikztiming@counter@minmaxsat#1#2{%
  \tikztiming@counter@minsat{#1}%
  \tikztiming@counter@maxsat{#2}%
}
\def\tikztiming@counter@wrap#1#2{%
  \pgfmathtruncatemacro\MIN{#1}%
  \pgfmathtruncatemacro\MAX{#2}%
  \ifnum\N>\MAX
    \pgfmathtruncatemacro\N{\MIN + (\N-\MAX-1)}%
  \fi
  \ifnum\N<\MIN
    \pgfmathtruncatemacro\N{\MAX - (\MIN-\N+1)}%
  \fi
}
\RequirePackage{pgfopts}
\ProcessPgfOptions{/tikz/timing/counter}
\endinput
%%
%% End of file `tikz-timing-counters.sty'.
