build system and framework for list
This commit is contained in:
parent
f1220734a4
commit
54be01d113
|
@ -8,7 +8,7 @@ CONFOPTS="CXX=$CXX"
|
|||
SILENT="${SILENT:-yes}"
|
||||
if [ "${SILENT}" = "yes" ]
|
||||
then
|
||||
CONFOPTS="$CONFOPTS --enable-silent-rules"
|
||||
CONFOPTS="$CONFOPTS"
|
||||
fi
|
||||
|
||||
[ -d m4 ] || mkdir m4
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
#ifndef __ODS_LIST__
|
||||
#define __ODS_LIST__
|
||||
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace ods {
|
||||
|
||||
// Lists are sequences of values.
|
||||
template <typename T>
|
||||
class List {
|
||||
public:
|
||||
virtual std::size_t size(void);
|
||||
virtual T get(std::size_t);
|
||||
virtual T set(std::size_t, T);
|
||||
virtual void add(std::size_t, T);
|
||||
virtual T remove(std::size_t);
|
||||
};
|
||||
|
||||
} // end namespace ods
|
||||
|
||||
#endif
|
|
@ -1,24 +0,0 @@
|
|||
#ifndef __ODS_SIMPLIST__
|
||||
#define __ODS_SIMPLIST__
|
||||
|
||||
#include "list.h"
|
||||
|
||||
namespace ods {
|
||||
|
||||
template <typename T>
|
||||
class SimpList : public List {
|
||||
public:
|
||||
SimpList();
|
||||
std::size_t size(void);
|
||||
T get(std::size_t);
|
||||
T set(std::size_t, T);
|
||||
void add(std::size_t, T);
|
||||
T remove(std::size_t);
|
||||
private:
|
||||
T arr[];
|
||||
std::size_t cap;
|
||||
std::size_t len;
|
||||
};
|
||||
|
||||
} // end namespace ods
|
||||
#endif
|
|
@ -1,11 +1,16 @@
|
|||
AM_CPPFLAGS = -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align
|
||||
AM_CPPFLAGS += -Wwrite-strings -Wmissing-declarations -Wno-long-long -Werror
|
||||
AM_CPPFLAGS += -Wunused-variable -std=c++14 -D_XOPEN_SOURCE -O0 -g -I. -I../include
|
||||
AM_CPPFLAGS += -Wunused-variable -std=c++14 -D_XOPEN_SOURCE -O0 -g -I.
|
||||
AM_CPPFLAGS += -fno-elide-constructors -Weffc++
|
||||
|
||||
lib_LTLIBRARIES := libods.la
|
||||
libods_la_SOURCES := simplist.cc
|
||||
libods_la_CPPFLAGS := $(AM_CPPFLAGS)
|
||||
|
||||
bin_PROGRAMS := ch01ex01 ch01ex03 ch01ex04 ch01ex05 ch01ex06
|
||||
ch01ex01_SOURCES := ch01ex01.cc
|
||||
ch01ex03_SOURCES := ch01ex03.cc
|
||||
ch01ex04_SOURCES := ch01ex04.cc
|
||||
ch01ex05_SOURCES := ch01ex05.cc
|
||||
ch01ex06_SOURCES := simplist.cc ch01ex06.cc
|
||||
ch01ex06_SOURCES := ch01ex06.cc
|
||||
ch01ex06_LDADD := .libs/libods.a
|
|
@ -1,5 +1,5 @@
|
|||
#include <cassert>
|
||||
#include <simplist.h>
|
||||
#include <ods/simplist.h>
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef __ODS_LIST__
|
||||
#define __ODS_LIST__
|
||||
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace ods {
|
||||
|
||||
// Lists are sequences of values.
|
||||
template<typename T>
|
||||
class List {
|
||||
public:
|
||||
virtual std::size_t size(void);
|
||||
virtual T get(std::size_t);
|
||||
virtual T set(std::size_t, T);
|
||||
virtual void add(std::size_t, T);
|
||||
virtual T remove(std::size_t);
|
||||
};
|
||||
|
||||
} // end namespace ods
|
||||
|
||||
#endif
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef __ODS_SIMPLIST__
|
||||
#define __ODS_SIMPLIST__
|
||||
|
||||
#include <ods/list.h>
|
||||
#include <cstddef>
|
||||
|
||||
namespace ods {
|
||||
|
||||
template<typename T>
|
||||
class SimpList {
|
||||
public:
|
||||
SimpList();
|
||||
std::size_t size(void);
|
||||
T get(std::size_t);
|
||||
T set(std::size_t, T);
|
||||
void add(std::size_t, T);
|
||||
T remove(std::size_t);
|
||||
private:
|
||||
T *arr;
|
||||
std::size_t cap;
|
||||
std::size_t len;
|
||||
};
|
||||
|
||||
} // end namespace ods
|
||||
#endif
|
|
@ -1,4 +1,4 @@
|
|||
#include "simplist.h"
|
||||
#include <ods/simplist.h>
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
|
@ -7,42 +7,54 @@ constexpr std::size_t DEFAULT_SIZE = 8;
|
|||
|
||||
namespace ods {
|
||||
|
||||
SimpList<T>::SimpList<T>()
|
||||
{
|
||||
template<typename T>
|
||||
SimpList<T>::SimpList()
|
||||
{
|
||||
this->arr = new T[DEFAULT_SIZE];
|
||||
this->cap = 0;
|
||||
this->len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::size_t
|
||||
SimpList<T> size(void)
|
||||
{
|
||||
std::assert(len <= cap);
|
||||
template <typename T>
|
||||
std::size_t
|
||||
SimpList<T>::size(void)
|
||||
{
|
||||
assert(len <= cap);
|
||||
return this->len();
|
||||
}
|
||||
}
|
||||
|
||||
T
|
||||
SimpList<T>::get(std::size_t i)
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
T
|
||||
SimpList<T>::get(std::size_t i)
|
||||
{
|
||||
i = 0;
|
||||
throw std::invalid_argument("invalid argument");
|
||||
}
|
||||
}
|
||||
|
||||
T
|
||||
SimpList<T>::set(std::size_t, T)
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
T
|
||||
SimpList<T>::set(std::size_t, T)
|
||||
{
|
||||
throw std::invalid_argument("invalid argument");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SimpList<T>::add(std::size_t, T)
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
SimpList<T>::add(std::size_t, T)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
T
|
||||
SimpList<T>::remove(std::size_t)
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
T
|
||||
SimpList<T>::remove(std::size_t)
|
||||
{
|
||||
throw std::invalid_argument("invalid argument");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
} // end namespace ods
|
||||
|
|
Loading…
Reference in New Issue