casacore
Loading...
Searching...
No Matches
ObjectID.h
Go to the documentation of this file.
1//# ObjectID.h: A unique identifier for distributed and other objects
2//# Copyright (C) 1996,1998,1999,2000,2001,2003
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26
27#ifndef CASA_OBJECTID_H
28#define CASA_OBJECTID_H
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/casa/BasicSL/String.h>
33#include <casacore/casa/iosfwd.h>
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37//# Forward declarations
38template<class T> class Block;
39
40// <summary>
41// ObjectID: A unique identifier for distributed and other objects.
42// </summary>
43
44// <use visibility=export>
45
46// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tObjectID.cc" demos="">
47
48// <prerequisite>
49// <li> none
50// </prerequisite>
51//
52// <etymology>
53// The ObjectID class name reflects its role as the single identifier for
54// distributed and other user-level objects.
55// </etymology>
56//
57// <synopsis>
58// The ObjectID class is used to give a unique identifier to ``high-level''
59// objects in the system. Internally the ObjectID consists of a sequence number
60// (unique within the creating process), a process id, a creation time, and a
61// host id. Pragmatically the ObjectID should be unique with no dangers of
62// collisions.
63//
64// A special ``Null'' ObjectID is available.
65// </synopsis>
66//
67// <motivation>
68// The fundamental purpose for an ObjectID is to provide a unique identifier
69// for persistent objects, or for objects that might be accessed outside the
70// creating processes address space.
71// </motivation>
72//
73// <todo asof="1997/09/23">
74// <li> Nothing (hostid -> hostname on this date).
75// </todo>
76
78{
79public:
80 // If <src>makeNull</src> is True, make the null ObjectID, otherwise create
81 // a unique ObjectID.
82 ObjectID(Bool makeNull = False);
83 // Create explicitly from the provided constituents.
84 ObjectID(Int sequence, Int pid, Int time, const String &hostname);
85
86 // Copy <src>other</src>. Note that if the ObjectID is embedded inside an
87 // object, the enclosing object probably does not want to copy the ObjectID
88 // since generally speaking the identity of the enclosing object should be
89 // immutable.
90 // <group>
91 ObjectID(const ObjectID &other);
92 ObjectID &operator=(const ObjectID &other);
93 // </group>
94
95 // Is this ObjectID set?
96 Bool isNull() const;
97
98 // Compare two ObjectID's for (in)equality.
99 // <group>
100 Bool operator==(const ObjectID &other) const;
101 Bool operator!=(const ObjectID &other) const;
102 // </group>
103
104 // It is useful to interconvert between strings and ObjecID's, e.g. when
105 // saving to FITS or writing to a table. The form of the string is:
106 // <srcblock>
107 // sequence=123 host=hostname pid=pid time=time
108 // </srcblock>
109 // with an optional comma between the fields.
110 // However, in general user code should not depend on the exact form of
111 // the string.
112 // <group>
113 // If this fails, an error message is set and the ObjectID is the null
114 // ObjectID.
115 Bool fromString(String &error, const String &in);
116 // Note that <src>out</src> is zero'd before it is set.
117 void toString(String &out) const;
118 // </group>
119
120 // Ordinarily the user does not need to get at the exact state of the,
121 // ObjectID, however it is available for those times when it is necessary.
122 // <group>
123 Int sequence() const;
124 Int pid() const;
125 Int creationTime() const;
126 const String &hostName() const;
127 // </group>
128
129 // Extract objectID strings (as set by glish script substitute.g) from
130 // a command, convert them to ObjectID objects, store those in the
131 // Block, and replace the strings by their Block indices as
132 // <src>$OBJ#n#O</src> where n is the index.
134 const String& command);
135
136private:
141
142 // Make a unique sequence number, returns 0 on first call, 1 on next, ...
144};
145
147
148ostream &operator<<(ostream &os, const ObjectID &id);
149
150//# Inlines
151
152inline Int ObjectID::sequence() const
153{
154 return sequence_number_p;
155}
156
157inline Int ObjectID::pid() const
158{
159 return process_id_p;
160}
161
163{
164 return creation_time_p;
165}
166
167inline const String &ObjectID::hostName() const
168{
169 return hostname_p;
170}
171
172
173} //# NAMESPACE CASACORE - END
174
175#endif
simple 1-D array
Definition Block.h:198
ObjectID & operator=(const ObjectID &other)
const String & hostName() const
Definition ObjectID.h:167
static String extractIDs(Block< ObjectID > &objectIDs, const String &command)
Extract objectID strings (as set by glish script substitute.g) from a command, convert them to Object...
static Int sequence_number()
Make a unique sequence number, returns 0 on first call, 1 on next,...
Bool isNull() const
Is this ObjectID set?
Int pid() const
Definition ObjectID.h:157
ObjectID(Bool makeNull=False)
If makeNull is True, make the null ObjectID, otherwise create a unique ObjectID.
Bool fromString(String &error, const String &in)
It is useful to interconvert between strings and ObjecID's, e.g.
ObjectID(const ObjectID &other)
Copy other.
ObjectID(Int sequence, Int pid, Int time, const String &hostname)
Create explicitly from the provided constituents.
void toString(String &out) const
Note that out is zero'd before it is set.
Int sequence() const
Ordinarily the user does not need to get at the exact state of the, ObjectID, however it is available...
Definition ObjectID.h:152
Bool operator!=(const ObjectID &other) const
Int creationTime() const
Definition ObjectID.h:162
Bool operator==(const ObjectID &other) const
Compare two ObjectID's for (in)equality.
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
TableExprNode time(const TableExprNode &node)
Definition ExprNode.h:1584
uInt hashFunc(const ObjectID &)
unsigned int uInt
Definition aipstype.h:49
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40