paella/Code/include/Skeleton/Branch.hpp

136 lines
6.3 KiB
C++

////////////////////////////////////////////////////////////////////////////////
//
// Paella
// Copyright (C) 2015 - Thomas FORGIONE, Emilie JALRAS, Marion LENFANT, Thierry MALON, Amandine PAILLOUX
// Authors :
// Thomas FORGIONE
// Emilie JALRAS
// Marion LENFANT
// Thierry MALON
// Amandine PAILLOUX
//
// This file is part of the project Paella
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
////////////////////////////////////////////////////////////////////////////////
#ifndef BRANCH_HPP
#define BRANCH_HPP
#include <vector>
//////////////////////////////////////////////
/// \ingroup skeleton
/// Class wrapping a branch of a skeleton. It only contains the vector of int
/// representing the vertices of the skeleton that are on a branch.
//////////////////////////////////////////////
class Branch
{
public:
//////////////////////////////////////////////
/// \brief Add a point to a branch
/// \param nextPoint point to add to the branch
//////////////////////////////////////////////
void push_back(unsigned int nextPoint);
//////////////////////////////////////////////
/// \brief Computes the size of a path
/// \return the size of the path
//////////////////////////////////////////////
unsigned int size() const { return path.size(); };
///////////////////////////////////////////////
/// \brief Returns an iterator to the first element of the path
/// \return an iterator to the first element of the path
///////////////////////////////////////////////
std::vector<unsigned int>::iterator begin() { return path.begin(); }
///////////////////////////////////////////////
/// \brief Returns an iterator to the case after the last element of the path
/// \return an iterator to the case after the last element of the path
///////////////////////////////////////////////
std::vector<unsigned int>::iterator end() { return path.end(); }
///////////////////////////////////////////////
/// \brief Returns an iterator to the first element of the path
/// \return a const iterator to the first element of the path
///////////////////////////////////////////////
std::vector<unsigned int>::const_iterator begin() const { return path.begin(); }
///////////////////////////////////////////////
/// \brief Returns an iterator to the case after the last element of the path
/// \return a const iterator to the case after the last element of the path
///////////////////////////////////////////////
std::vector<unsigned int>::const_iterator end() const { return path.end(); }
///////////////////////////////////////////////
/// \brief Returns an iterator to the first element of the path
/// \return a const iterator to the first element of the path
///////////////////////////////////////////////
std::vector<unsigned int>::const_iterator cbegin() const { return path.begin(); }
///////////////////////////////////////////////
/// \brief Returns an iterator to the case after the last element of the path
/// \return a const iterator to the case after the last element of the path
///////////////////////////////////////////////
std::vector<unsigned int>::const_iterator cend() const { return path.end(); }
///////////////////////////////////////////////
/// \brief Overload of the operator==
/// \param other second branch
/// \return true if the branches are the same
/// \pre The branches must be correct branches. Especially, this
/// function only compares the first, the second and the last elements of
/// the branches.
///////////////////////////////////////////////
bool operator==(Branch const& other);
////////////////////////////////////////////////
/// \brief Overload of the operator[]
/// \param i index of the case to get
/// \return a reference to the i-th element of the path
////////////////////////////////////////////////
unsigned int& operator[](unsigned int i) { return path[i];}
////////////////////////////////////////////////
/// \brief Overload of the operator[]
/// \param i index of the case to get
/// \return a const reference to the i-th element of the path
////////////////////////////////////////////////
unsigned int const& operator[](unsigned int i) const { return path[i];}
////////////////////////////////////////////////
/// \brief returns a reference to i-th element
/// \param i index of the case to get
/// \return a reference to the i-th element of the path, throws a
/// std::out_of_range exception if i is out of range
////////////////////////////////////////////////
unsigned int& at(unsigned int i) { return path.at(i); }
////////////////////////////////////////////////
/// \brief returns a reference to i-th element
/// \param i index of the case to get
/// \return a const reference to the i-th element of the path, throws a
/// std::out_of_range exception if i is out of range
////////////////////////////////////////////////
unsigned int const& at(unsigned int i) const { return path.at(i); }
private:
std::vector<unsigned int> path; ///< vector where the path is stored
};
#endif