preferred idiom for "occasional properties"

I've been exploring what a cross platform process library would look like and have a question about whether there is a preferred idiom for what I'll call an occasional property for lack of a better term. Given a process, I'd like to be able to query the parent process. Posix has such a notion, but win32 doesn't. On posix, afaik, every process has a parent except for "init." I can't decide whether I should say class process { public: process parent(); static const process nprocess; // like std::string's npos }; where parent() != nprocess when the process has a parent. or class process { public: typedef std::pair<process,bool> parent_type; parent_type parent(); }; where parent_type.second == true when the process has a parent. I also considered a "parent_iterator", since on posix, you could keep walking backwards up the hierarchy till you get to init, e.g. class parent_iterator; class process { public: parent_iterator parent(); }; but conceptually, I couldn't see a good "end()" Anyone care to offer an idea for the best way to handle this? jr

On Tue, Nov 01, 2005 at 01:13:48PM -0500, joel reed wrote:
I've been exploring what a cross platform process library would look like and have a question about whether there is a preferred idiom for what I'll call an occasional property for lack of a better term.
Given a process, I'd like to be able to query the parent process. Posix has such a notion, but win32 doesn't. On posix, afaik, every process has a parent except for "init."
snip
Anyone care to offer an idea for the best way to handle this?
I suppose I should add that throwing an exception didn't seem appropriate, but perhaps I'm mistaken here. I'm just looking for best practices advice from a library design perspective. jr

On Tue, Nov 01, 2005 at 08:39:04PM +0100, Pavel Vozenilek wrote:
"joel reed" wrote:
Given a process, I'd like to be able to query the parent process. Posix has such a notion, but win32 doesn't.
Toolhelp functions CreateToolhelp32Snapshot(), then Process32First()/Process32Next(), examine item th32ParentProcessID.
Thanks Pavel, I'll look into these functions. As far as an idiom is concerned, I found one that may work - using a "parent_iterator" where parent_iterator() is the end of sequence marker. This would match istream_iterator. jr

"joel reed" <joel.reed@ddiworld.com> wrote in message news:20051101181348.GA10833@ddiworld.com...
I've been exploring what a cross platform process library would look like and have a question about whether there is a preferred idiom for what I'll call an occasional property for lack of a better term.
Given a process, I'd like to be able to query the parent process. Posix has such a notion, but win32 doesn't. On posix, afaik, every process has a parent except for "init."
I can't decide whether I should say
class process { public: process parent();
static const process nprocess; // like std::string's npos };
where parent() != nprocess when the process has a parent.
or
class process { public: typedef std::pair<process,bool> parent_type; parent_type parent(); };
where parent_type.second == true when the process has a parent.
I also considered a "parent_iterator", since on posix, you could keep walking backwards up the hierarchy till you get to init, e.g.
class parent_iterator;
class process { public: parent_iterator parent(); };
but conceptually, I couldn't see a good "end()"
Why not just use boost::optional? Then you could declare boost::optional<process &> parent(); One of the main uses of optional is to return data that might or might not exist. Joe Gottman
participants (3)
-
Joe Gottman
-
joel reed
-
Pavel Vozenilek