473,785 Members | 2,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What to name container "flavors"?

Hiya.

Frequently (as in at least twice now) I find that when I write some sort of
container I want at least two out of three possible versions:

o fixed max size known at compile time
o fixed max size known at run time
o max size is dynamic

The question is how to name the variants consistently. My usual approach is
to give the "generic" name to whichever flavor I write first and then add
modifiers to the other two whenever prodded to build 'em:

template<size_t NStates, typename TState>
class HiddenMarkovMod el {...};

and a week later:

template<typena me TState>
class RTHiddenMarkovM odel { RTHiddenMarkovM odel(size_t nStates)...};

and 3 weeks after that:

template<typena me TState>
class DynamicHiddenMa rkovModel { ... };

OK, truth is I've yet to need to code DynamicHiddenMa rkovModel - bad
example. But:

template<typena me TCell>
class Stack { Stack(size_t maxStates) ...};

template<size_t NStates, typename TCell>
class FixedStack {...};

template<typena me TCell>
class DynamicStack {...};

has come up. Sort of a trivial question, how to name these things to reduce
average client surprise (library name entropy), but I am wondering how
y'all cope with this.

- Michael
Jul 23 '05 #1
2 1537
On 2005-06-30, Michael Olea <ol***@sbcgloba l.net> wrote:
Hiya.

Frequently (as in at least twice now) I find that when I write some sort of
container I want at least two out of three possible versions:

o fixed max size known at compile time
o fixed max size known at run time
o max size is dynamic

The question is how to name the variants consistently. My usual approach is
to give the "generic" name to whichever flavor I write first and then add
modifiers to the other two whenever prodded to build 'em:


One way to do it is make it all the same class, and make the dynamic or
staticness a policy parameter.

struct dynamic {} ;

template <size_t i> struct static_fixed {} ;
struct rt_fixed {} ;

template <typename T, typename policy = dynamic> class Array ;

So now your classes would be called things like:

Array<Foo, dynamic> a1; // a dynamic array
Array<Foo, static_fixed<10 > > a2; // a fixed array, sze known at compile time
Array<Foo, rt_fixed > a3(30); // a fixed array, size known at runtime

template <typename T>
class Array <T, dynamic > : private std::vector<T>
{
public:
typedef typename std::vector<T>: :size_type size_type;
// etc ...

Array() : std::vector<T> () {}
Array(size_type N) : std::vector<T> (N) {}
template <typename iter> Array (iter i1, iter i2)
: std::vector<T>( i1,i2) {}
T& operator [] (size_type i) { return std::vector<T>: :operator[] (i); }
const T& operator [] (size_type i)const
{ return std::vector<T>: :operator[] (i); }

// blah blah
};

// Array<T, rt_fixed> is the same except some functionality needs to be
// restricted, e.g. resize, push_back, capacity, etc.

template <typename T, size_t i>
class Array<T, static_fixed<i> >
{
T impl[i];
public:
// blah blah blah ...
};

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/
Jul 23 '05 #2
Donovan Rebbechi wrote:
On 2005-06-30, Michael Olea <ol***@sbcgloba l.net> wrote:
Hiya.

Frequently (as in at least twice now) I find that when I write some sort
of container I want at least two out of three possible versions:

o fixed max size known at compile time
o fixed max size known at run time
o max size is dynamic

The question is how to name the variants consistently. My usual approach
is to give the "generic" name to whichever flavor I write first and then
add modifiers to the other two whenever prodded to build 'em:
One way to do it is make it all the same class, and make the dynamic or
staticness a policy parameter.


Yeah. I gave that idea a good, hard, intense 5 minute's thought before
posting. My conclusion was that that is certainly the way to go when
feasible, but it probably only reduces rather than eliminates the problem -
there will still be cases where separate classes have to be written, and
named (I think). An interesting exercise would be to take that approach
with bitsets - have std::bitset and boost::dynamic_ bitset fall out as
special cases of: bitset<Size_Pol icy>. No loss of functionality, no loss of
efficiency: easy, hard, or crazy?

struct dynamic {} ;

template <size_t i> struct static_fixed {} ;
struct rt_fixed {} ;

template <typename T, typename policy = dynamic> class Array ;

So now your classes would be called things like:

Array<Foo, dynamic> a1; // a dynamic array
Array<Foo, static_fixed<10 > > a2; // a fixed array, sze known at compile
time
Array<Foo, rt_fixed > a3(30); // a fixed array, size known at runtime

template <typename T>
class Array <T, dynamic > : private std::vector<T>
{
public:
typedef typename std::vector<T>: :size_type size_type;
// etc ...

Array() : std::vector<T> () {}
Array(size_type N) : std::vector<T> (N) {}
template <typename iter> Array (iter i1, iter i2)
: std::vector<T>( i1,i2) {}
T& operator [] (size_type i) { return std::vector<T>: :operator[] (i);
} const T& operator [] (size_type i)const
{ return std::vector<T>: :operator[] (i); }

// blah blah
};

// Array<T, rt_fixed> is the same except some functionality needs to be
// restricted, e.g. resize, push_back, capacity, etc.
Right. Maybe Array derives publicly from the parameterized Size_Policy,
which, if dynamic, has the enriched interface...

template <typename T, size_t i>
class Array<T, static_fixed<i> >
{
T impl[i];
public:
// blah blah blah ...
};

Cheers,


Cheers, and thanks for the ideas - Michael
Jul 23 '05 #3

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

Similar topics

6
2919
by: rcb845 | last post by:
HI fellow php fans, I am blocked with a simple problem, at least it seems simple, but I cannot make it through. I want to execute a .php script in case of "error 404, page not found". I am not yet on a production server but on my local Apache server. I have defined my personal error file. I have modified the apache configuration httpd.conf to point to this
0
1650
by: David H | last post by:
Background. I'm running on WinXP w/ MS Services for Unix installed (to give rsh/rlogin ability), both Python 2.3 and 2.4 version. In linux, I'm running RHEE with python2.3 version. The code below works fine for me in linux, but in WinXP the popen*() command "hangs". More specifically, I get an apparent python prompt (without the '>>> ', but whatever I type has no effect, and hitting return does a CR but not the additional LF, so I...
6
3674
by: Al Dykes | last post by:
I've just grabbed a PHP book and can deal with the syntax and now I need to decide to learn specific packages and features. Define "framework". What are the major framework flavors ? Under what conditions can I use two or more frameworks? Sorry for the beginners question.
20
2755
by: John Bailo | last post by:
http://www.joelonsoftware.com/articles/APIWar.html "So you've got the Windows API, you've got VB, and now you've got .NET, in several language flavors, and don't get too attached to any of that, because we're making Avalon, you see, which will only run on the newest Microsoft operating system, which nobody will have for a loooong time. And personally I still haven't had time to learn .NET very deeply, and we haven't ported Fog...
2
2180
by: Joe Lester | last post by:
Does anyone know if there's a way to embed the Postgres database inside an application... so that it runs transparently, without the user even having to know it's there? I would prefer to use Postgres, but I fear that I may have to resort to mySQL or some other SQL database that can be embedded. I'm building a Cocoa app on OS X and am familiar with the libpq C library. Thanks!
93
4009
by: jacob navia | last post by:
In this group there is a bunch of people that call themselves 'regulars' that insist in something called "portability". Portability for them means the least common denominator. Write your code so that it will compile in all old and broken compilers, preferably in such a fashion that it can be moved with no effort from the embedded system in the coffe machine to the 64 bit processor in your desktop.
2
4618
by: SammyBar | last post by:
Hi all, I'm trying to send a message from ASP.NET to another PC by using MSMQ. I created my ASP.NET project by using Visual Studio 2005 but I initially set the project to be located on the File System. Then I could successfully send, receive and purge the public queries I use to exchange information with the another PC. But when I realized I can not reach the file system created project from a third PC then I recreated the project as...
206
8374
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a footprint which says: "Indeed, one often hears arguments against building exibility into an engineered sys- tem. For example, in the philosophy of the computer language Python it is claimed: \There should be one|and preferably only one|obvious...
2
8734
by: HaifaCarina | last post by:
i have this unfinished java program and i can't figure out what is the problem.. please help... /** * @(#)Answer3.java * * * @author * @version 1.00 2008/1/17
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10152
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.