diff --git a/autobuild b/autobuild index b9dcb72..1f94136 100644 --- a/autobuild +++ b/autobuild @@ -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 diff --git a/include/list.h b/include/list.h deleted file mode 100644 index fd77522..0000000 --- a/include/list.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __ODS_LIST__ -#define __ODS_LIST__ - - -#include - -namespace ods { - -// Lists are sequences of values. - template - 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 diff --git a/include/simplist.h b/include/simplist.h deleted file mode 100644 index 70b1472..0000000 --- a/include/simplist.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef __ODS_SIMPLIST__ -#define __ODS_SIMPLIST__ - -#include "list.h" - -namespace ods { - - template - 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 diff --git a/src/Makefile.am b/src/Makefile.am index e0da8fc..25f63aa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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++ -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 +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 := ch01ex06.cc +ch01ex06_LDADD := .libs/libods.a \ No newline at end of file diff --git a/src/ch01ex06.cc b/src/ch01ex06.cc index ec19e5f..7b23901 100644 --- a/src/ch01ex06.cc +++ b/src/ch01ex06.cc @@ -1,5 +1,5 @@ #include -#include +#include using namespace std; diff --git a/src/ods/list.h b/src/ods/list.h new file mode 100644 index 0000000..20f6e37 --- /dev/null +++ b/src/ods/list.h @@ -0,0 +1,22 @@ +#ifndef __ODS_LIST__ +#define __ODS_LIST__ + + +#include + +namespace ods { + +// Lists are sequences of values. +template +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 diff --git a/include/queue.h b/src/ods/queue.h similarity index 100% rename from include/queue.h rename to src/ods/queue.h diff --git a/src/ods/simplist.h b/src/ods/simplist.h new file mode 100644 index 0000000..02fc930 --- /dev/null +++ b/src/ods/simplist.h @@ -0,0 +1,25 @@ +#ifndef __ODS_SIMPLIST__ +#define __ODS_SIMPLIST__ + +#include +#include + +namespace ods { + +template +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 diff --git a/src/simplist.cc b/src/simplist.cc index 988fd92..905eeea 100644 --- a/src/simplist.cc +++ b/src/simplist.cc @@ -1,4 +1,4 @@ -#include "simplist.h" +#include #include #include #include @@ -7,42 +7,54 @@ constexpr std::size_t DEFAULT_SIZE = 8; namespace ods { - SimpList::SimpList() - { - this->arr = new T[DEFAULT_SIZE]; - this->cap = 0; - this->len = 0; - } +template +SimpList::SimpList() +{ + this->arr = new T[DEFAULT_SIZE]; + this->cap = 0; + this->len = 0; +} - std::size_t - SimpList size(void) - { - std::assert(len <= cap); - return this->len(); - } +template +std::size_t +SimpList::size(void) +{ + assert(len <= cap); + return this->len(); +} - T - SimpList::get(std::size_t i) - { - throw std::invalid_argument("invalid argument"); - } - T - SimpList::set(std::size_t, T) - { - throw std::invalid_argument("invalid argument"); - } +template +T +SimpList::get(std::size_t i) +{ + i = 0; + throw std::invalid_argument("invalid argument"); +} - void - SimpList::add(std::size_t, T) - { - return; - } - T - SimpList::remove(std::size_t) - { - throw std::invalid_argument("invalid argument"); - } -}; +template +T +SimpList::set(std::size_t, T) +{ + throw std::invalid_argument("invalid argument"); +} + + +template +void +SimpList::add(std::size_t, T) +{ + return; +} + + +template +T +SimpList::remove(std::size_t) +{ + throw std::invalid_argument("invalid argument"); +} + +} // end namespace ods