Attention une mise à jour du service Gitlab va être effectuée le mardi 30 novembre entre 17h30 et 18h00. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes. Cette mise à jour intermédiaire en version 14.0.12 nous permettra de rapidement pouvoir mettre à votre disposition une version plus récente.

Commit aad2fa0b authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud
Browse files

First step toward distributed container.

parent 6b652bc8
......@@ -3,9 +3,9 @@
## Author: Julien Wintz
## Created: Mon Feb 4 12:16:39 2013 (+0100)
## Version:
## Last-Updated: Mon Feb 4 12:53:05 2013 (+0100)
## By: Julien Wintz
## Update #: 14
## Last-Updated: 2013 Mon Feb 4 16:03:57 (+0100)
## By: Thibaud Kloczko
## Update #: 16
######################################################################
##
### Change Log:
......@@ -20,7 +20,9 @@ project(dtkDistributed)
set(${PROJECT_NAME}_HEADERS
dtkDistributedCommunicatorPlugin.h
dtkDistributedCommunicatorPluginManager.h)
dtkDistributedCommunicatorPluginManager.h
dtkDistributedContainer.h
dtkDistributedContainer.tpp)
set(${PROJECT_NAME}_SOURCES
dtkDistributedCommunicatorPluginManager.cpp)
......
/* dtkDistributedContainer.h ---
*
* Author: Thibaud Kloczko
* Created: 2013 Mon Feb 4 15:59:05 (+0100)
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#ifndef DTKDISTRIBUTEDCONTAINER_H
#define DTKDISTRIBUTEDCONTAINER_H
template<typename T> class dtkDistributedContainer;
// /////////////////////////////////////////////////////////////////
// dtkDistributedLocalIterator interface
// /////////////////////////////////////////////////////////////////
template<typename T> class dtkDistributedLocalIterator
{
public:
dtkDistributedLocalIterator(dtkDistributedContainer<T> *container);
~dtkDistributedLocalIterator(void);
public:
void toBack(void);
void toFront(void);
public:
bool hasNext(void);
bool hasPrevious(void);
public:
const T& next(void);
const T& previous(void);
public:
const T& peekNext(void);
const T& peekPrevious(void);
public:
qlonglong localIndex(void) const;
qlonglong globalIndex(void) const;
private:
dtkDistributedContainer<T> *c;
typedef typename QVector<T>::const_iterator const_iterator;
const_iterator i;
};
// /////////////////////////////////////////////////////////////////
// dtkDistributedContainer interface
// /////////////////////////////////////////////////////////////////
template<typename T> class dtkDistributedContainer
{
public:
dtkDistributedContainer(void);
~dtkDistributedContainer(void);
public:
void resize(const qlonglong& size);
qlonglong size(void) const;
public:
void set(const qlonglong& index, const T& value);
public:
const T& at(const qlonglong& index);
public:
dtkDistributedLocalIterator<T> *localIterator(void);
private:
QVector<T> m_array;
dtkDistributedLocalIterator<T> *m_iterator;
public:
friend class dtkDistributedLocalIterator<T>;
};
// /////////////////////////////////////////////////////////////////
// Implementations
// /////////////////////////////////////////////////////////////////
#include "dtkDistributedContainer.tpp"
#endif
/* dtkDistributedContainer.tpp ---
*
* Author: Thibaud Kloczko
* Created: 2013 Mon Feb 4 16:02:53 (+0100)
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#ifndef DTKDISTRIBUTEDCONTAINER_TPP
#define DTKDISTRIBUTEDCONTAINER_TPP
// /////////////////////////////////////////////////////////////////
// dtkDistributedLocalIterator implementation
// /////////////////////////////////////////////////////////////////
template<typename T> dtkDistributedLocalIterator<T>::dtkDistributedLocalIterator(dtkDistributedContainer<T> *container) : c(container), i(c->m_array.constBegin())
{
};
template<typename T> dtkDistributedLocalIterator<T>::~dtkDistributedLocalIterator(void)
{
};
template <typename T> void dtkDistributedLocalIterator<T>::toBack(void)
{
i = c->m_array.constEnd();
};
template <typename T> void dtkDistributedLocalIterator<T>::toFront(void)
{
i = c->m_array.constBegin();
};
template <typename T> bool dtkDistributedLocalIterator<T>::hasNext(void)
{
return (i != c->m_array.constEnd());
};
template <typename T> bool dtkDistributedLocalIterator<T>::hasPrevious(void)
{
return (i != c->m_array.constBegin());
};
template <typename T> const T& dtkDistributedLocalIterator<T>::next(void)
{
return (*i++);
};
template <typename T> const T& dtkDistributedLocalIterator<T>::previous(void)
{
return *(--i);
};
template <typename T> const T& dtkDistributedLocalIterator<T>::peekNext(void)
{
return *i;
};
template <typename T> const T& dtkDistributedLocalIterator<T>::peekPrevious(void)
{
const_iterator p = i;
return (*--p);
};
template <typename T> qlonglong dtkDistributedLocalIterator<T>::localIndex(void) const
{
return 0;
};
template <typename T> qlonglong dtkDistributedLocalIterator<T>::globalIndex(void) const
{
return 0;
};
// /////////////////////////////////////////////////////////////////
// dtkDistributedContainer implementation
// /////////////////////////////////////////////////////////////////
template<typename T> dtkDistributedContainer<T>::dtkDistributedContainer(void)
{
m_iterator = NULL;
};
template<typename T> dtkDistributedContainer<T>::~dtkDistributedContainer(void)
{
if (m_iterator)
delete m_iterator;
m_iterator = NULL;
};
template<typename T> void dtkDistributedContainer<T>::resize(const qlonglong& size)
{
m_array.resize(size);
};
template <typename T> qlonglong dtkDistributedContainer<T>::size(void) const
{
return m_array.size();
};
template <typename T> void dtkDistributedContainer<T>::set(const qlonglong& index, const T& value)
{
m_array.replace(index, value);
};
template <typename T> const T&dtkDistributedContainer<T>:: at(const qlonglong& index)
{
return m_array.at(index);
};
template <typename T> dtkDistributedLocalIterator<T> *dtkDistributedContainer<T>::localIterator(void)
{
if (!m_iterator)
m_iterator = new dtkDistributedLocalIterator<T>(this);
return m_iterator;
};
#endif
......@@ -13,6 +13,7 @@
*/
#include "dtkDistributedContainerTest.h"
#include <dtkDistributed/dtkDistributedContainer.h>
void dtkDistributedContainerTestCase::initTestCase(void)
{
......@@ -26,7 +27,19 @@ void dtkDistributedContainerTestCase::init(void)
void dtkDistributedContainerTestCase::test(void)
{
QVERIFY(1 == 1);
qlonglong N = 1000;
dtkDistributedContainer<qlonglong> c;
c.resize(N);
QVERIFY(N == c.size());
dtkDistributedLocalIterator<qlonglong> *it = c.localIterator();
while(it->hasNext()) {
c.set(it->globalIndex(), it->localIndex());
it->next();
}
}
void dtkDistributedContainerTestCase::cleanupTestCase(void)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment