Homework 7 - Computer Architecture I - ShanghaiTech University

Homework 7 - Ring Buffer in C++

Computer Architecture I ShanghaiTech University
HW6 HW7 HW8

Goals

In this assignment, you need to reimplement ring buffer in C++. You need to learn about following topics

Setup

You can download the template here. We provided a header file for you.

Overview

Your task is to implement a ring buffer in C++ using templates. In ringbuffer.hpp, we’ve declared all classes you need. You need to finish the implementation of the class and methods in ringbuffer.hpp. All you implementation should be in a file named ringbuffer.ipp. If you don’t know what is ipp file, here is a brief explanation.

Before templates, you put the declarations of methods in the header file and the implementation went to a .cpp file. These files were compiled separately as their own compilation unit.

With templates, this is no longer possible almost all template methods need to be defined in the header. To separated them at least on a logical level, some people put the declarations in the header but move all implementations of template methods to .ipp files (i for “inline”) and include the .ipp file at the end of the header.

Implementation Details

Please obey the following rules:

Ring buffer

Requirements of implementing the ring buffer is the same as HW2.

Other detailed requirements are in ringbuffer.hpp .

Iterator

Finish the implementation of __detail::__iterator<_Tp>. You have to implement the following methods:

You should also overload the following operators:

You can refer to std::vector<_Tp>::iterator for some detailed implementation.

Const Iterator

It is similar to the iterator except for the dereferenced value should be const type (they cannot be modified). All methods for iterator should also be implemented for const iterator. You should also implement one additional method:

Hints

Submission

Archive ringbuffer.ipp and create hw7.tar. Submit hw7.tar to Autolab.


Last Modified: Fri May 6 01:06:34 CST 2022