build system and framework for list

This commit is contained in:
Kyle Isom 2017-12-20 07:33:19 -08:00
parent f1220734a4
commit 54be01d113
9 changed files with 107 additions and 89 deletions

View File

@ -8,7 +8,7 @@ CONFOPTS="CXX=$CXX"
SILENT="${SILENT:-yes}" SILENT="${SILENT:-yes}"
if [ "${SILENT}" = "yes" ] if [ "${SILENT}" = "yes" ]
then then
CONFOPTS="$CONFOPTS --enable-silent-rules" CONFOPTS="$CONFOPTS"
fi fi
[ -d m4 ] || mkdir m4 [ -d m4 ] || mkdir m4

View File

@ -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

View File

@ -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

View File

@ -1,11 +1,16 @@
AM_CPPFLAGS = -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align AM_CPPFLAGS = -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align
AM_CPPFLAGS += -Wwrite-strings -Wmissing-declarations -Wno-long-long -Werror 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++ 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 bin_PROGRAMS := ch01ex01 ch01ex03 ch01ex04 ch01ex05 ch01ex06
ch01ex01_SOURCES := ch01ex01.cc ch01ex01_SOURCES := ch01ex01.cc
ch01ex03_SOURCES := ch01ex03.cc ch01ex03_SOURCES := ch01ex03.cc
ch01ex04_SOURCES := ch01ex04.cc ch01ex04_SOURCES := ch01ex04.cc
ch01ex05_SOURCES := ch01ex05.cc ch01ex05_SOURCES := ch01ex05.cc
ch01ex06_SOURCES := simplist.cc ch01ex06.cc ch01ex06_SOURCES := ch01ex06.cc
ch01ex06_LDADD := .libs/libods.a

View File

@ -1,5 +1,5 @@
#include <cassert> #include <cassert>
#include <simplist.h> #include <ods/simplist.h>
using namespace std; using namespace std;

22
src/ods/list.h Normal file
View File

@ -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

25
src/ods/simplist.h Normal file
View File

@ -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

View File

@ -1,4 +1,4 @@
#include "simplist.h" #include <ods/simplist.h>
#include <cassert> #include <cassert>
#include <cstdlib> #include <cstdlib>
#include <stdexcept> #include <stdexcept>
@ -7,7 +7,8 @@ constexpr std::size_t DEFAULT_SIZE = 8;
namespace ods { namespace ods {
SimpList<T>::SimpList<T>() template<typename T>
SimpList<T>::SimpList()
{ {
this->arr = new T[DEFAULT_SIZE]; this->arr = new T[DEFAULT_SIZE];
this->cap = 0; this->cap = 0;
@ -15,34 +16,45 @@ namespace ods {
} }
template <typename T>
std::size_t std::size_t
SimpList<T> size(void) SimpList<T>::size(void)
{ {
std::assert(len <= cap); assert(len <= cap);
return this->len(); return this->len();
} }
template <typename T>
T T
SimpList<T>::get(std::size_t i) SimpList<T>::get(std::size_t i)
{ {
i = 0;
throw std::invalid_argument("invalid argument"); throw std::invalid_argument("invalid argument");
} }
template <typename T>
T T
SimpList<T>::set(std::size_t, T) SimpList<T>::set(std::size_t, T)
{ {
throw std::invalid_argument("invalid argument"); throw std::invalid_argument("invalid argument");
} }
template <typename T>
void void
SimpList<T>::add(std::size_t, T) SimpList<T>::add(std::size_t, T)
{ {
return; return;
} }
template <typename T>
T T
SimpList<T>::remove(std::size_t) SimpList<T>::remove(std::size_t)
{ {
throw std::invalid_argument("invalid argument"); throw std::invalid_argument("invalid argument");
} }
};
} // end namespace ods