COTS Challenges for Embedded Systems - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

COTS Challenges for Embedded Systems

Description:

destructive read at head of stream. write to stream. Iterator Concepts: Expressions, Models ... i, i , *i (non-destructive) in addition to the expressions ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 10
Provided by: dsch7
Category:

less

Transcript and Presenter's Notes

Title: COTS Challenges for Embedded Systems


1
E61 CS 342S Object-Oriented Software Development
The STL and the Iterator Pattern
Christopher Gill Department of Computer Science
and Engineering Washington University, St.
Louis cdgill_at_cse.wustl.edu
Thanks to Jim Wang, Peng Wang
2
What is an Iterator?
  • GoF book suggests an interface
  • First (), Next(), IsDone(), CurrentItem()
  • However, intent they give is more essential
  • Provide a way to access the elements of an
    aggregate object sequentially without exposing
    its underlying representation
  • Having different representations
  • means aggregate objects may have different
    semantics for the interface above (some trivial)
  • Well consider interface methods above with
  • istream, ostream, array, linked list, bi-linked
    list

3
Syntax and Semantics
  • Syntax governs how interface is written
  • First () Next() IsDone() CurrentItem()
  • p A0 p p A gt 3 p
  • Semantics governs what implementation does
  • Move to start, move forward one position, test
    completion, return item at current position
  • Compilers can only check syntax (C, Java)
  • The programmer must address semantics
  • Including memory allocation, safe aliasing, etc.
  • Is it bad to implement Next () as --p ?

4
A Few Key Ideas to Consider
  • Difference Type
  • Type for distance between two iterators i1 and
    i2
  • E.g., ptrdiff_t
  • Reference, Value Types
  • For T p, value type is T, p normally returns T
  • For const T p, value type is const T, p gives
    const T
  • Iterator Category
  • What concept(s) it models

how far? units?
how far? units?
5
Review Iterator Concept Hierarchy
destructive read at head of stream
write to stream
read/write once
Input Iterator
Output Iterator
Linked-list style access
Forward Iterator
value persists after read/write, values have
locations, can express distance between two
iterators
Bi-linked-list style access
Bidirectional Iterator
Array/buffer style access
Random Access Iterator
6
Iterator Concepts Expressions, Models
  • Input Iterator (read from a stream/container)
  • i (destructive), i t, i-gtm, i, i , i
  • istream_iterator, most other STL iterators
  • Output Iterator (write to a stream/container)
  • X y(x), X yx, y x, x t, x, x , x t
  • front_insert_iterator, back_insert_iterator,
    insert_iterator, ostream_iterator
  • How are First(), Next(), IsDone(), CurrentItem()
    implemented for each of these?

7
Iterator Concepts Expressions, Models
  • Forward Iterator (moves in one direction)
  • Can pass same forward iterator in multiple args
  • Dereference does not move the iterator
  • X x, X(), i, i , i (non-destructive) in
    addition to the expressions for Input Iterator
    and Output Iterator
  • slistltintgtiterator, slistltdoublegtconst_iterato
    r, hash_setltstringgtiterator
  • Bidirectional Iterator (moves both ways)
  • Forward Iterator expressions,--i, i--
  • listltintgtiterator, setltstringgtiterator
  • How are First(), Next(), IsDone(), CurrentItem()
    implemented for each of these?
  • Can we do more than with Input/Output Iterator?

8
Iterator Concepts Expressions, Models
  • Random Access Iterator (constant time index)
  • Concept fully expresses C pointers
  • Bidirectional Iterator expressions and in, in,
    ni, i-n, i-n, n-i, i-j, iltj, in, int
  • Question we can express the distance between two
    Forward Iterators, so why dont those iterators
    have i-j, iltj ?
  • vectorltintgtiterator, dequeltintgtiterator, char
  • How are First(), Next(), IsDone(), CurrentItem()
    implemented for each of these?
  • Can we do more than with Forward/Bidirectional ?

9
Conclusions
  • What really matters with a pattern is
  • Its intent (the problem it solves)
  • Its context (when and how it applies)
  • The consequences of different solutions
  • Comparing Iterator pattern and STL iterators
  • Gives a deeper understanding of both
  • Offers clues about implementation using STL
  • A design and implementation approach
  • Design your solution according to given problem
  • Keep track of the patterns used in your design
  • Map design patterns into libraries/frameworks
  • Write code only when you have to
Write a Comment
User Comments (0)
About PowerShow.com