Note: This tutorial assumes that you have completed the previous tutorials: Arrays.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Stencils

Description: Windows onto ecl arrays.

Keywords: ecl arrays

Tutorial Level: INTERMEDIATE

Next Tutorial: Buffer Overflow Detection

Often you require a window onto a container (array) and stencils provide a safe way to do this. Stencils avoid the use of dangerous pointers which can cause problems if the underlying container goes out of scope or is resized. It does this by including the underlying container as a reference and also includes similar out of range checks that arrays perform (exception throwing in debug mode for [] and always for at()).

   1 typedef Array<int,5> FixedArray;
   2 typedef Stencil< FixedArray > FixedStencil;
   3 
   4 FixedArray array;
   5 array << 1,2,3,4,5;
   6 FixedStencil stencil(array,1,3); // windows from index 1 to 3
   7 std::cout << stencil[1] << std::endl; // accesses array[2];
   8 

Wiki: ecl_containers/Tutorials/Stencils (last edited 2012-01-18 14:31:40 by DanielStonier)