473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

policy based design (needs improvement?)

Hi everyond. I'm trying to write a library usign policy based design
so I can implement
different behaviors. One of the behaviors was to define a
StoragePolicy. The following code gives the whole idea for a
population object:

#ifndef _POPULATION_H
#define _POPULATION_H

#include "gaParameters.h"
#include "gaIndividual.h"

using namespace std;

template <class T>
class StoragePolicy
{
void create(size_t,size_t);

};

template <class T>
struct StdVectorStorage
{
typename std::vector<T>::iterator it_;

std::vector<Tstorage_;

void create(size_t p,size_t l)
{
storage_ = std::vector<T>(p);
for(it_ = storage_.begin(); it_ != storage_.end(); ++it_)
it_->init(l);
}

protected:

~StdVectorStorage()
{
}

};

template
<
class Individual,
template <classclass StoragePolicy = StdVectorStorage

class Population : public StoragePolicy<Individual>
{
public:

gaParameters* gaParams_;

// initialize population
void initialize(gaParameters* p);

};

template
<
typename Individual,
template <classclass StoragePolicy

void Population<Individual,StoragePolicy>::initialize(g aParameters* p)
{
// assign pointer to parameter list
gaParams_ = p;
unsigned int xsite_; //!< Crossover point

// create population according to the desired policy
this->create(
(size_t)gaParams_->get(popSize),
(size_t)gaParams_->get(lChrom));

}

#endif

Now, since I'm using a storage policy, I thought that it may be nice to
try different data structures to hold the population. One of them of
course is the std::vector so that is the first one I'm using here.
Then, the user will only need to specify the storage used in this
context:

int main(int argc, char *argv[]){

typedef Chromosome<BoostBitsetStoragechrom;
typedef Individual<chrom, HeapStorageind;
typedef Population<ind,StdVectorStoragepop;
....

There are many things that bother me from this design:
1. I didn't know if it was fine to declare the population size having a
Pointer to the actual storage as this:

template
<
class Pointer,
class Individual,
template <classclass StoragePolicy = StdVectorStorage

class Population : public StoragePolicy<Individual>
{
Pointer *pointee_;
....

because then the user needs to know what the Pointer points to (and
this information is supposed to be within the StoragePolicy).
Therefore, I created within the policy class, a pointee_ variable that
points to the actual data structures where the individuals are created
(and this variable is inherited when the Population is instantiated).
Is there a better way to accomplish this?

2. Now, If I create another policy parallel to the StoragePolicy, then
I need to know what kind of data structure the StoragePolicy is using
and this is really what is bothering me right now because it is telling
me that this policy cannot be orthogonalized with other policies
(unless I can access the structure using a random access iterator,
thing that I cannot do with my knowledge of C++ at this moment).

Any ideas???

Sep 19 '06 #1
0 1353

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: ian | last post by:
I have begun testing some code based on Chapter 1.5.1 of the book Modern C++ Design by Andrei Alexandrescu. The test code is listed below and the compiler error message that is generated is: ...
0
by: rjoshi | last post by:
There is a nice article about practicle usage of Policy Base Design at http://www.codeproject.com/library/Generic_Pool_Design.asp
9
by: Martin Vorbrodt | last post by:
I'm designing a Matrix class of 4x4 matrices used in computer graphics. Both OpenGL and Direct3D can take a pointer to array of 16 floats which represent the values in the matrix. OGL takes it in...
4
by: Martin Vorbrodt | last post by:
please be so kind and direct me to as many sources as you can regarding the *subject* matter. i'm new to the topic and would like to learn as much as possible. thank you in advance martin
4
by: Erik Wikström | last post by:
In school (no I will not ask you to do my schoolwork for me) we talked about policy-based design and got an assignment where we got the a code- fragment from a stack-implementation. The idea with...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
11
by: aaragon | last post by:
Hi everyone. I'm trying to write a class with policy based design (Alexandrescu's Modern C++ Design). I'm not a programmer but an engineer so this is kind of hard for me. Through the use of...
2
by: nw | last post by:
Hi, I previously posted a question asking for suggestions on my class design. My original code consisted of a pure virtual base class Body which contained a number of integration algorithms...
3
by: DerrickH | last post by:
I have a template class with three policies: PolicyA, PolicyB, and PolicyC. The design dilemma I am having is that B and C depend upon A, but I would like my Host class to derive from all three. In...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.