#% Do not delete the line below; configure depends on this
#  \DeclareLaTeXClass[article]{AspectC++ Manual (Standard Class)}
#  \DeclareCategory{Articles}
# AspectC++ Manual textclass definition file. Based on 'Artical' source code
# Author : Olaf Spinczyk <os@aspectc.org>

Format 104
Input stdclass.inc
DefaultModule tcolorbox

SecNumDepth             3
TocDepth                3
DocBookRoot             article

NoStyle Chapter
NoCounter chapter
NoStyle Chapter*


Style Part
	Align                 Left
	AlignPossible         Left
	LabelType             Above
	TopSep                2
	BottomSep             1.5
	Font
	  Series              Bold
	  Size                Huge
	EndFont
	LabelFont
	  Series              Bold
	  Size                Larger
	EndFont
End


Style Part*
	Align                 Left
	AlignPossible         Left
	TopSep                2
	BottomSep             1.5
	Font
	  Series              Bold
	  Size                Huge
	EndFont
End

AddToPreamble
%
% setup fancyhdr
%
  %
  % two side book class setup
  % odd page  - left head: chapter  - left foot: page number
  % even page - right head: section - right foot: page number
  % no head on plain pages
  %
  \fancyhf{}%
  \fancyhead[LE,RO]{\slshape \rightmark}
  \fancyhead[LO,RE]{\slshape \leftmark}
  \fancyfoot[LE,RO]{\thepage}
  %
  % rules for head and foot
  % also on plain pages
  %
  \renewcommand{\headrulewidth}{.4pt}
  \renewcommand{\footrulewidth}{.4pt}
  \renewcommand{\plainfootrulewidth}{.4pt}
%
% Variables to change some details
%
% version number for this document
%
\newcommand{\@version}{1}
\newcommand{\version}[1]{ \renewcommand{\@version}{#1} }
%
%
\newcommand\pslogo[1]{\gdef\@pslogo{#1}}
\pslogo{}
%
\newcommand\otherlogo[1]{\gdef\@otherlogo{#1}}
\otherlogo{}
%
\newcommand\remark[1]{\gdef\@remark{#1}}
\remark{}
%
\newcommand{\doctype}[1]{\gdef\@doctype{#1}}
\doctype{Studie:}
%
\newcommand\credit[1]{\gdef\@credit{#1}}
\credit{Diese Studie wurde durch die\par
\vskip .3cm
pure-systems GmbH\par
Agnetenstr. 14\par
39106 Magdeburg\par
http://www.pure-systems.com\par
\vskip .3cm
erstellt.}
%
%
%
\newcommand\layoutlogos{

        \newlength{\@pslogowidth}
        \newlength{\@otherlogowidth}
        \settowidth{\@otherlogowidth}{\@otherlogo}
        \settowidth{\@pslogowidth}{\@pslogo}

        \noindent
        \begin{minipage}{\@otherlogowidth}
        {\@otherlogo}
        \end{minipage}
        \hspace*{\fill}
        \begin{minipage}{\@pslogowidth}
        {\@pslogo}
        \end{minipage}
}

%
% redefine \maketitle macro
%
\renewcommand{\maketitle}{
    \null
    \thispagestyle{empty}

        {\layoutlogos}

        \vskip 3cm
        \begin{center}\leavevmode
        {\Huge\raggedright {\@doctype}\\ {\@title}\par}
        \rule{\textwidth}{1mm}
        \vskip 3mm
        {\Large\raggedleft {\@author}\par}
        \vskip 15mm
        {\Large\raggedleft {\@date}\par}
        \end{center}
        \vfill
        {\large\raggedleft {\@remark}\par}
        \vskip 1cm
        \null
%
        \newpage
%
        \null
        \thispagestyle{empty}
}

%--------------------------------------------------------------------
% setup pure-systems style
%--------------------------------------------------------------------
\doctype{Documentation:}
\otherlogo{
  \resizebox{4cm}{!}{\includegraphics{images/ac++logo}}}

%--------------------------------------------------------------------
% place footnotes at the bottom of the page
%--------------------------------------------------------------------
\renewcommand\footnoterule{%
  \vfill
  \kern-3\p@
  \hrule\@width.3\columnwidth
  \kern2.6\p@}

%--------------------------------------------------------------------
% leave less than one and a half space between lines
%--------------------------------------------------------------------
\setstretch{1.15}

%--------------------------------------------------------------------
% environment 'comment'
%--------------------------------------------------------------------
\usepackage{comment}

%--------------------------------------------------------------------
% add 'Index' to table of contents
%--------------------------------------------------------------------
\let\old@theindex\theindex
\def\theindex{
  \old@theindex
  \addcontentsline{toc}{section}{\indexname}}

%--------------------------------------------------------------------
% landscape mode
%--------------------------------------------------------------------
\usepackage{pdflscape}

%--------------------------------------------------------------------
% caption of longtables
%--------------------------------------------------------------------
\usepackage{capt-of}

\usepackage{xcolor} % for colored listings
\usepackage{parskip} % do no indent paragraphs

%--------------------------------------------------------------------
% encircled numbers
\usepackage{pifont}
%--------------------------------------------------------------------

%--------------------------------------------------------------------
% configure color box, which are use for nice breakable listings
%--------------------------------------------------------------------
\usepackage{tcolorbox}
\tcbuselibrary{breakable, skins}
\tcbset{breakable, enhanced, skin=enhanced, colback=black!10, colframe=black!30}


\usepackage{tikz}
\usetikzlibrary{
  arrows.meta,
  tikzmark,
  calc,
  positioning
}

\usepackage{listings}
\lstset{basicstyle={\ttfamily},
  escapeinside={<==}{\^^M},
  showstringspaces=false,
  upquote=true}
\usetikzmarklibrary{listings}

%--------------------------------------------------------------------
% AspectC++ listing style definitions
%--------------------------------------------------------------------
\lstdefinelanguage[Aspect]{C++}[ISO]{C++}{
  morekeywords={[2], aspect, advice, pointcut, attribute, slice, call, execution, construction, destruction,
    get, set, ref, builtin, within, cflow, before, around, after, tjp, JoinPoint, order, derived,
     base, args, that, target, result, override
  }
}

%--------------------------------------------------------------------
% special setting for bash code
%--------------------------------------------------------------------
\lstdefinelanguage{bash}{
  keywords={},
  backgroundcolor=\color{black!10}
}

%--------------------------------------------------------------------
% special setting for cmake code
%--------------------------------------------------------------------
\lstdefinelanguage{cmake}{
  keywords={cmake_minimum_required, project, set, add_executable, file},
  backgroundcolor=\color{black!10}
}


% Create a counter for listings so that the comment markers have a local scope
\newcounter{aclstcount}
\tikzset{ tikzmark suffix={-\theaclstcount} }
\AtBeginEnvironment{lstlisting}{\stepcounter{aclstcount}}
\newcommand{\pos}[1]{\tikzmark{pos_#1}}

% This is needed, because 'tikzmark's are stored in the aux file, which is only rebuild
% by lyx if cross-references change. The warning message fakes this situation. Without
% it mistakes with using the marks could remain visible even after fixing them. Restarting
% LyX helps, but is annoying. So we better wait a little longer for every rebuild.
\wlog{LaTeX Warning:Rerun to get cross-references}

% latex commands to draw the markers with tikz:

\newcommand{\lstarrowcomment}[4]{%
\def\vertval{#3}%
\ifdimless{\vertval}{0.0cm}{%
\begin{tikzpicture}[%
  remember picture,
  overlay,
  annotation/.style={
    inner sep=0pt,
    outer sep=0pt,
    outer xsep=1mm,
    text width=10cm,
    font=\bfseries
  },
  >={Stealth[inset=0pt, angle=45:7pt]}
]
\draw[<-] (pic cs:pos_#1)  ++(0.5,.5ex) -| ++(#2,#3)
node[annotation, above right]
{\normalfont #4};
\end{tikzpicture}
}{
\begin{tikzpicture}[%
  remember picture,
  overlay,
  annotation/.style={
    inner sep=0pt,
    outer sep=0pt,
    outer xsep=1mm,
    text width=10cm,
    font=\bfseries
  },
  >={Stealth[inset=0pt, angle=45:7pt]}
]
\draw[<-] (pic cs:pos_#1)  ++(0.5,.5ex) -| ++(#2,#3)
node[annotation, below right]
{\normalfont #4};
\end{tikzpicture}%
}
}

EndPreamble

AddToHTMLPreamble
<script src="ac-highlight.js"></script>
<link rel="stylesheet" href="ac-manual.css"/>

<script>
function convertToCm(svg, lengthstr) {
  length = svg.createSVGLength();
  length.valueAsString = lengthstr;
  length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_CM);
  return length.valueInSpecifiedUnits.toString();
}

function createMarker(p) {
  svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
  p_len = p["len"] ? convertToCm(svg, p.len) : "2";
  p_height = p["height"] ? convertToCm(svg, p.height) : "1";
  p_text = p["text"] ? p.text : "";
  p_text = p_text.replace(/(\r\n|\n|\r)/gm,""); // we insert this into a pre environment!
  p_down = false;
  if (p_height &lt; 0) {
    p_height = -p_height;
    p_down = true;
  }
  elem = document.createElement("span");
  style = "position:absolute;margin-left: 2em;"
  if (!p_down) {
    style += "padding-top:1lh;"
  }
  elem.setAttribute("style", style);
  svg.setAttribute("width", p_len + "cm");
  svg.setAttribute("height", p_height + "cm");
  svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
  if (p_down) {
    svg.setAttribute("style", "position:absolute;top:0;");
  }
  else {
    svg.setAttribute("style", "position:absolute;bottom:0;");
  }
  defs = document.createElementNS("http://www.w3.org/2000/svg", "defs");
  marker = document.createElementNS("http://www.w3.org/2000/svg", "marker");
  marker.setAttribute("id", "markerarrow");
  marker.setAttribute("markerWidth", "12");
  marker.setAttribute("markerHeight", "10");
  marker.setAttribute("refX", "5");
  marker.setAttribute("refY", "5");
  marker.setAttribute("orient", "auto");
  mpath = document.createElementNS("http://www.w3.org/2000/svg", "path")
  mpath.setAttribute("d", "M 0 0 L 12 5 L 0 10 z");
  mpath.setAttribute("fill", "black");
  marker.appendChild(mpath);
  defs.appendChild(marker);
  path = document.createElementNS("http://www.w3.org/2000/svg", "polyline");
  path.setAttribute("stroke", "black");
  path.setAttribute("stroke-width", "1px");
  path.setAttribute("fill", "none");
  path.setAttribute("marker-end", "url(#markerarrow)");
  if (p_down) {
    path.setAttribute("points", p_len + "," + p_height + " " + p_len + ",0.2 0.2,0.2");
  }
  else {
    path.setAttribute("points", p_len + ",0 " + p_len + "," + p_height + " 0.2," + p_height);
  }
  path.setAttribute("vector-effect", "non-scaling-stroke");
  ytrans = (p_down) ? 0 : -0.15;
  path.setAttribute("transform", "scale(37.795) translate(-0.02," + ytrans + ")"); // 1cm = 37..px
  svg.appendChild(defs);
  svg.appendChild(path);
  elem.appendChild(svg);
  text = document.createElement("td");
  text.setAttribute("class", "listing_arrow_text");
  text_style_prefix = (p_down ? "vertical-align:bottom;" : "position:absolute;bottom:0;");
  text_extra_padding = (p_down ? "padding-top:5px;" : "padding-bottom:5px;");
  text_padding = p_len*1 + 0.2; // *1 force addition instead of string appending
  text.setAttribute("style", text_style_prefix + "height:" + p_height + "cm;padding: 0 0 0 " + text_padding + "cm;user-select:none;" + text_extra_padding);
  text.innerHTML = p_text;
  elem.appendChild(text);
  return elem;
}

function highlight(preElement) {
  text = preElement.textContent.replaceAll(/&lt;==/g, "//");
  preElement.textContent = text;
  text = acHighlight(preElement);
  preElement.innerHTML = text;
}

function injectMarker(listingDiv, commentDiv) {
  posDivs = commentDiv.querySelectorAll('.flex_listing_arrow_p___pos');
  if (posDivs.length != 1)
    return;
  prefix = "flex_listing_arrow_p___";
  markerType = commentDiv.className.substring(prefix.length);
  pos = posDivs[0].textContent;
  commentDivs = listingDiv.querySelectorAll('.comment');
  commentDivs.forEach(comment => {
    if (comment.textContent.indexOf("\\pos{" + pos + "}") != -1) {
      attrDivs = commentDiv.querySelectorAll('.flex_listing_arrow_p___len, .flex_listing_arrow_p___height, .flex_listing_arrow_p___text');
      m = {};
      attrDivs.forEach(attrDiv => {
        attrName = attrDiv.className.substring(prefix.length);
        attrValue = attrDiv.innerHTML;
        m[attrName] = attrValue;
      });
      m.type = markerType;
      comment.replaceWith(createMarker(m));
    }
  });
  commentDiv.remove();
}

window.onload = (event) => {
  const interestingDivs = document.querySelectorAll('pre[class*="C++"], .listing_arrow_comment');
  activeListing = null;
  interestingDivs.forEach(currDiv => {
    if (currDiv.nodeName == "pre") {
      activeListing = currDiv;
      highlight(activeListing);
    }
    else {
      injectMarker(activeListing, currDiv);
    }
  });
};
</script>
EndPreamble

# Make sure that no HTML styling is generated for listings and their caption
InsetLayout Listings
    HTMLTag	pre
    HTMLStyle
    EndHTMLStyle
End

# No styling for the table of contents, too!
InsetLayout TOC
    HTMLStyle
    EndHTMLStyle
End

Style "Listing Arrow Comment"
    LatexType             Paragraph
	Align                 Left
	AlignPossible         Left
	LeftDelim             "<br/>\lstarrowcomment"
	RightDelim            "<br/>\vspace{-\the\baselineskip}<br/>"
	LeftMargin            "listing arrow comment: "
	LabelString           "Listing arrow comment: "
    LabelType       Static
    LabelFont
        Series        Medium
        Shape         Italic
        Size          Small
        Color         textlabel1
    EndFont
    Newline           1
End

InsetLayout "Flex:Listing Arrow P1: Pos"
    LyXType					custom
	Decoration				Classic
    LatexType				None
    BgColor					white
	LabelString				"pos"
	LeftDelim				"{"
	RightDelim				"}"
	HTMLIsBlock				0
End

InsetLayout "Flex:Listing Arrow P2: Len"
    LyXType					custom
	Decoration				Classic
    LatexType				None
    BgColor					white
	LabelString				"len"
	LeftDelim				"{"
	RightDelim				"}"
	HTMLIsBlock				0
End

InsetLayout "Flex:Listing Arrow P3: Height"
    LyXType					custom
	Decoration				Classic
    LatexType				None
    BgColor					white
	LabelString				"height"
	LeftDelim				"{"
	RightDelim				"}"
	HTMLIsBlock				0
End

InsetLayout "Flex:Listing Arrow P4: Text"
    LyXType					custom
	Decoration				Classic
    LatexType				None
    BgColor					white
	LabelString				"txt"
	MultiPar				0
	LeftDelim				"{"
	RightDelim				"}"
	HTMLIsBlock				0
End
