TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: All
from: Morten Toftgaard Jensen
date: 1995-12-08 23:55:16
subject: C++ implementation considerations o

Hey All!

I am learning how to use templates - and they're quite useful, as I
expected :-) However they have put me in a very interesting implementation
problem.

At this moment I'm using the IBM OCL ISortedSet collection class to store
objects of class FileItem. The FileItem class is holding specific file
information, such as name, size, attributes, date of creation, etc etc etc.
(as the quick reader may have guessed already).

I chose the ISortedSet because I wanted the file list to be ordered.
However you are able to sort a file not only by name, but also by size,
date of creation, etc. Also with the opportunity to sort them in descending
or ascending order.

So you could say my implementation of the "operator<"
operation in the FileItem class is kind of generic - and to make things
MUCH worse, the method of sorting a FileList is given at runtime and not
compile time.

This gives me the problem that I cannot apply a given sort method to the
ISortedSet at runtime.

So I have to implement it in the FileItem class (or a derived class, as in
the example below) and construct a FileItem object with the given
information.

This gives me two choices:
-------------------------
1. I could allocate an integer holding the sort method and sort heading for
each FileItem object in a given collection. However this is not very
efficient (space), nor is it very elegant, and last but not least, a
construction of this kind could limit future "upgrades" or make
them very crippled.

2. I could use a global variable, holding the information. This gives me
two problems. The first is that I don't really like the implementation of
global variables (not if I want any sleep at night, that is :-), and two,
that I cannot have more than one list at a time, unless I encapsulate the
list in another class.

A third choice could be the use of static, if following construction is
possible (and works the way I'm hoping):

// **************** THE BEGINNING! ****************
class	FileList
{
	// ... something very exciting

	class	FileItemNode : public FileItem	// Nested class deriving my FileItem class
	{
		// ... something even more exciting

		static unsigned int sortMethod;
		static unsigned int sortHeading;

		IBoolean operator< (FileItemNode const& aFileItemNode) const
		{
			// ...This something you simply WONT miss for the world

			// In here the implementation of sorting algorithms will be located.
		};
	};
	ISortedSet fileList;
};
// **************** THE END! ****************
The "example" above is written directly in this letter, so if I
have made any errors, please do not flame me (thanks in advance :-)

With the above code I'm hoping to be able to create a given number of
FileList objects. My question is though, how does static behave in this
case? Is the information static only within the class scope of FileList
(this is the effect I'm hoping for), or will there be only one instance of
the static information in all created FileList objects.

See what I'm getting at?!

Anybody who can help me, please do!

Thanks in advance for all letters!!!

Yours,

Morten T. Jensen
* Where do you want to go today? * Not the Microsoft way! *
* OS/2Net: 81:445/12.77 * FidoNet: 2:236/100.77 * InterNet: psy{at}danadata.dk *
---
* Origin: Finally the patients have taken over the asylum! (2:236/100.77)
SEEN-BY: 270/101 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407
SEEN-BY: 712/515 517 628 713/888 800/1 7877/2809
@PATH: 236/100 235/47 236/9 235/50 240/5500 24/24 396/1 270/101 712/515
@PATH: 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.