Skip to content
Snippets Groups Projects
Commit e3158851 authored by hcasse's avatar hcasse
Browse files

io: small fix in outputting FP values, removal of unused include in

FileInput.
data: fixes in SortedList, MapList classes.
parent 1f4f2559
Branches
No related tags found
No related merge requests found
...@@ -39,6 +39,7 @@ public: ...@@ -39,6 +39,7 @@ public:
class Iter: public PreIterator<Iter, T> { class Iter: public PreIterator<Iter, T> {
friend class ListMap; friend class ListMap;
public: public:
inline Iter() { }
inline Iter(const ListMap<K, T>& l): i(l) { } inline Iter(const ListMap<K, T>& l): i(l) { }
inline bool ended(void) const { return i.ended(); } inline bool ended(void) const { return i.ended(); }
inline const T& item(void) const { return (*i).snd; } inline const T& item(void) const { return (*i).snd; }
...@@ -48,23 +49,24 @@ public: ...@@ -48,23 +49,24 @@ public:
PairIter i; PairIter i;
}; };
class KeyIter: public PreIterator<KeyIter, T> { class KeyIter: public PreIterator<KeyIter, K> {
public: public:
inline KeyIter(void) { } inline KeyIter(void) { }
inline KeyIter(const ListMap<K, T>& l): i(l) { } inline KeyIter(const ListMap<K, T>& l): i(l) { }
inline bool ended(void) const { return i.ended(); } inline bool ended(void) const { return i.ended(); }
inline const K& item(void) const { return (*i).fst; } inline const K& item(void) const { return (*i).fst; }
inline void next(void) { i.next(); } inline void next(void) { i.next(); }
inline bool equals(const KeyIter& ii) { return i.equals(ii.i); }
private: private:
PairIter i; PairIter i;
}; };
// Collection concept // Collection concept
inline Iter begin(void) const { return Iter(*this); } inline Iter begin(void) const { return Iter(*this); }
inline Iter end(void) const { return Iter(*this); } inline Iter end(void) const { return Iter(); }
inline int count(void) const { return base_t::count(); } inline int count(void) const { return base_t::count(); }
inline bool contains(const T& v) const inline bool contains(const T& v) const
{ for(const auto i: *this) if(E::isEqual(i, v)) return true; return false; } { for(const auto& i: *this) if(E::isEqual(i, v)) return true; return false; }
template <class CC> inline bool containsAll(const CC& c) const template <class CC> inline bool containsAll(const CC& c) const
{ for(const auto i: c) if(!contains(i)) return false; return true; } { for(const auto i: c) if(!contains(i)) return false; return true; }
inline bool isEmpty(void) const { return base_t::isEmpty(); } inline bool isEmpty(void) const { return base_t::isEmpty(); }
......
...@@ -80,6 +80,7 @@ public: ...@@ -80,6 +80,7 @@ public:
// MutableCollection concept // MutableCollection concept
inline void clear(void) { list.clear(); } inline void clear(void) { list.clear(); }
inline void copy(const SortedList<T>& l) { list.copy(l.list); }
void add(const T &value) { void add(const T &value) {
for(typename list_t::PrecIter current(list); current(); current++) for(typename list_t::PrecIter current(list); current(); current++)
...@@ -111,6 +112,7 @@ public: ...@@ -111,6 +112,7 @@ public:
} }
inline Iter find(const T& item) const { return find(item, begin()); } inline Iter find(const T& item) const { return find(item, begin()); }
inline T& at(const Iter& i) { return list.at(i); } inline T& at(const Iter& i) { return list.at(i); }
inline Iter nth(int n) const { Iter i(*this); while(n != 0 && i()) { n--; i++; }; return i; }
// operators // operators
inline SortedList<T>& operator=(const SortedList<T, C>& sl) { list.copy(sl.list); return *this; } inline SortedList<T>& operator=(const SortedList<T, C>& sl) { list.copy(sl.list); return *this; }
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#ifndef ELM_IO_FILEINPUT_H_ #ifndef ELM_IO_FILEINPUT_H_
#define ELM_IO_FILEINPUT_H_ #define ELM_IO_FILEINPUT_H_
#include <elm/io/BufferedInStream.h>
#include <elm/io/Input.h> #include <elm/io/Input.h>
#include <elm/sys/Path.h> #include <elm/sys/Path.h>
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#ifndef ELM_STREE_TREE_H_ #ifndef ELM_STREE_TREE_H_
#define ELM_STREE_TREE_H_ #define ELM_STREE_TREE_H_
#include <elm/assert.h>
#include <elm/compare.h> #include <elm/compare.h>
namespace elm { namespace stree { namespace elm { namespace stree {
......
...@@ -508,9 +508,14 @@ void Output::print(const FloatFormat& fmt) { ...@@ -508,9 +508,14 @@ void Output::print(const FloatFormat& fmt) {
} }
// perform the display // perform the display
if(fmt._width == 0) {
strm->write(b, s);
return;
}
else {
int pref = 0, suff = 0, spaces = max(0, fmt._width - s); int pref = 0, suff = 0, spaces = max(0, fmt._width - s);
switch(fmt._align) { switch(fmt._align) {
case NONE: strm->write(b, s); return; case NONE:
case LEFT: suff = spaces; break; case LEFT: suff = spaces; break;
case RIGHT: pref = spaces; break; case RIGHT: pref = spaces; break;
case CENTER: pref = spaces/2; suff = spaces - pref; break; case CENTER: pref = spaces/2; suff = spaces - pref; break;
...@@ -523,6 +528,7 @@ void Output::print(const FloatFormat& fmt) { ...@@ -523,6 +528,7 @@ void Output::print(const FloatFormat& fmt) {
if(suff) if(suff)
strm->write(buf2, suff); strm->write(buf2, suff);
} }
}
/** /**
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <elm/checksum/Fletcher.h> #include <elm/checksum/Fletcher.h>
#include <elm/io/InFileStream.h> #include <elm/io/InFileStream.h>
#include <elm/sys/System.h> #include <elm/sys/System.h>
#include <elm/io/BufferedInStream.h>
using namespace elm; using namespace elm;
using namespace elm::io; using namespace elm::io;
...@@ -348,5 +349,15 @@ TEST_BEGIN(io_format) ...@@ -348,5 +349,15 @@ TEST_BEGIN(io_format)
} }
} }
// format wdth test
{
StringBuffer buf;
buf << io::fmt(111).width(10);
CHECK_EQUAL(buf.toString().length(), 10);
buf.reset();
buf << io::fmt(0.111).width(10);
CHECK_EQUAL(buf.toString().length(), 10);
}
TEST_END TEST_END
...@@ -402,7 +402,6 @@ TEST_BEGIN(list) ...@@ -402,7 +402,6 @@ TEST_BEGIN(list)
} }
} }
#if 0
// test map // test map
{ {
ListMap<int, string> m; ListMap<int, string> m;
...@@ -411,10 +410,21 @@ TEST_BEGIN(list) ...@@ -411,10 +410,21 @@ TEST_BEGIN(list)
CHECK_EQUAL(m.count(), 1); CHECK_EQUAL(m.count(), 1);
m.put(1, "one"); m.put(1, "one");
CHECK_EQUAL(m.count(), 2); CHECK_EQUAL(m.count(), 2);
//CHECK(m.contains("zero")); CHECK(m.contains("zero"));
/*CHECK_EQUAL(m.get(0, -1), 0);*/ CHECK_EQUAL(m.get(0, ""), string("zero"));
int c = 0;
for(auto x: m)
c++;
CHECK_EQUAL(c, 2);
c = 0;
for(auto x: m.keys())
c += x;
CHECK_EQUAL(c, 1);
} }
#if 0
// compatibility test // compatibility test
/* TODO /* TODO
{ {
......
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
#include <elm/data/SortedList.h> #include <elm/data/SortedList.h>
#include <elm/data/ListMap.h> #include <elm/data/ListMap.h>
#include <elm/data/ListSet.h> #include <elm/data/ListSet.h>
#include "../include/elm/test.h" #include <elm/test.h>
#include "check-concept.h"
using namespace elm; using namespace elm;
...@@ -29,6 +30,13 @@ TEST_BEGIN(sorted_list) ...@@ -29,6 +30,13 @@ TEST_BEGIN(sorted_list)
SortedList<int> list; SortedList<int> list;
// concept test
{
checkCollection(list, list, 111);
checkMutableCollection(list, 111);
checkList(list, 111);
}
{ {
// Addition // Addition
list.add(5); list.add(5);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment