• Classes
  • Modules
  • Namespaces
  • Files
  • Related Pages
  • File List
  • File Members

cdbField.h

Go to the documentation of this file.
00001 #ifndef __cdb__Field_h__
00002 #define __cdb__Field_h__
00003 /*******************************************************************************
00004 * ALMA - Atacama Large Millimiter Array
00005 * Copyright (c) European Southern Observatory, 2011
00006 *
00007 * This library is free software; you can redistribute it and/or
00008 * modify it under the terms of the GNU Lesser General Public
00009 * License as published by the Free Software Foundation; either
00010 * version 2.1 of the License, or (at your option) any later version.
00011 *
00012 * This library is distributed in the hope that it will be useful,
00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 * Lesser General Public License for more details.
00016 *
00017 * You should have received a copy of the GNU Lesser General Public
00018 * License along with this library; if not, write to the Free Software
00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 *
00021 * "@(#) $Id: cdbField.h,v 1.31 2011/10/28 15:05:05 hsommer Exp $"
00022 *
00023 * who       when      what
00024 * --------  --------  ----------------------------------------------
00025 * almadev  2011-10-28  created
00026 */
00027 
00028 #include <iostream>
00029 
00030 #include "acsutil.h"
00031 
00032 #include "cdbData_Types.h"
00033 
00034 #include "cdbExport.h"
00035 
00036 // ------------------[ Stream extraction/insertion ]-----------------------
00037 
00038 #if !defined(__GNUG__)
00039 
00040 //{secret}
00041 std::ostream& operator<<(std::ostream &os, cdb::LongLong ll);
00042 
00043 //{secret}
00044 std::istream& operator>>(std::istream &is, cdb::LongLong &ll);
00045 
00046 //{secret}
00047 std::ostream& operator<<(std::ostream &os, cdb::ULongLong ll);
00048 
00049 //{secret}
00050 std::istream& operator>>(std::istream &is, cdb::ULongLong &ll);
00051 
00052 #endif //!defined(__GNUG__)
00053 
00054 #if defined(CDB_HAS_ANY)
00055 
00056 //
00057 // DESCRIPTION: Stream insertion of the Any type.
00058 //
00059 // Stream extraction/insertion operators for the Any type. Any's binary
00060 // image is stringified as text containing hexadecimal octets and written
00061 // to the stream as a single word.
00062 //
00063 // EXAMPLE:
00064 //
00065 //      Any a;
00066 //      // .. do something with a
00067 //      cout << a << endl;
00068 //
00069 #ifndef MAKE_VXWORKS
00070 std::ostream& operator<<(std::ostream &os, const cdb::Any& any);
00071 #else
00072 std::ostream& operator<<(std::ostream &os, const cdb::Any& any);
00073 #endif
00074 
00075 //{secret}
00076 #ifndef MAKE_VXWORKS
00077 std::istream& operator>>(std::istream &is, cdb::Any &any);
00078 #else
00079 std::istream& operator>>(std::istream &is, cdb::Any &any);
00080 #endif
00081 
00082 #endif // defined(CDB_HAS_ANY)
00083 
00084 namespace cdb {
00085 
00086 // ------------------------[ Null field types ]----------------------------
00087 
00088 //{partOf:Field::IsNull}
00089 #define CDB_FIELD_NULL          1
00090 
00091 //{partOf:Field::IsNull}
00092 #define CDB_FIELD_UNINITIALIZED 2
00093 
00094 //{partOf:Field::IsNull}
00095 #define CDB_FIELD_NONEXISTENT   3
00096 
00097 // ------------------------------[ Field ]---------------------------------
00098 
00099 //
00100 // DESCRIPTION: A field in the database.
00101 //
00102 // A field is the basic building block of a database. It stores one value,
00103 // and knows its type so that it can be correctly interpreted.
00104 //
00105 class cdb_EXPORT Field
00106 {
00107 public:  
00108   //{group:Type manipulation}
00109   // DESCRIPTION: Enumeration of all supported data types.
00110   //
00111   enum Type
00112   {
00113     tyNull=0,     // No-value. Can also be used to imply special meaning.
00114 
00115     tyAny=1,      // The CORBA::Any type.
00116     tyString=2,   // A string.
00117     tyOctet=3,    // 8-bit unsigned integer.
00118     tyBoolean=4,  // A boolean value (true/false).
00119 
00120     tyShort=5,    // 16-bit signed integer.
00121     tyLong=6,     // 32-bit signed integer.
00122     tyLongLong=7, // 64-bit signed integer.
00123 
00124     tyUShort=8,   // 16-bit unsigned integer.
00125     tyULong=9,    // 32-bit unsigned integer.
00126     tyULongLong=10,// 64-bit unsigned integer.
00127 
00128     tyFloat=11,    // IEEE 4-byte floating point number.
00129     tyDouble=12,   // IEEE 8-byte floating point number.
00130 
00131     tyArray=13,    // Abstract superclass of all arrays.
00132 
00133     tyAnyArray=14,
00134     tyStringArray=15,
00135     tyOctetArray=16,
00136 
00137     tyShortArray=17,
00138     tyLongArray=18,
00139     tyLongLongArray=19,
00140 
00141     tyUShortArray=20,
00142     tyULongArray=21,
00143     tyULongLongArray=22,
00144 
00145     tyFloatArray=23,
00146     tyDoubleArray=24
00147   };
00148 
00149   // ----------------------------------------------------------------------
00150   // GROUP = Static instances
00151   // ----------------------------------------------------------------------
00152 
00153   //
00154   // DESCRIPTION: A global predefined Null field.
00155   //
00156   // When calling Field::Null.IsNull(), a value of CDB_FIELD_NULL is
00157   // returned.
00158   //
00159   static const Field Null;
00160 
00161   //
00162   // DESCRIPTION: A global predefined field denoting a non-existent field.
00163   //
00164   // When calling Field::Nonexistent.IsNull(), a value of
00165   // CDB_FIELD_NONEXISTENT is returned
00166   //
00167   static const Field Nonexistent;
00168 
00169   //
00170   // DESCRIPTION: Construct a field.
00171   //
00172   // PARAMETERS:
00173   //   ty      - Data-type that this field will store.
00174   //   nBound  - For compsite types (strings, arrays), specifies up to how
00175   //             many elements may be contained in the field.
00176   //
00177   Field(Type ty, ULong nBound = 0);
00178 
00179   //
00180   // DESCRIPTION: Construct a field. The field will carry a null value.
00181   //
00182   Field();
00183 
00184   //
00185   // DESCRIPTION: Copy constructor: construct a field that will store the
00186   //              same data as the specified field.
00187   //
00188   Field(const Field &fld);
00189 
00190 #if defined(CDB_HAS_ANY)
00191   Field(const Any &);
00192 #endif // defined(CDB_HAS_ANY)
00193 
00194   Field(const String &);
00195   Field(Octet);
00196 
00197   Field(Short);
00198   Field(Long);
00199   Field(LongLong);
00200 
00201   Field(UShort);
00202   Field(ULong);
00203   Field(ULongLong);
00204 
00205   Field(Float);
00206   Field(Double);
00207 
00208 #if defined(CDB_HAS_ANY)
00209   Field(const AnyArray &);
00210 #endif // defined(CDB_HAS_ANY)
00211   Field(const StringArray &);
00212   Field(const OctetArray &);
00213 
00214   Field(const ShortArray &);
00215   Field(const LongArray &);
00216   Field(const LongLongArray &);
00217 
00218   Field(const UShortArray &);
00219   Field(const ULongArray &);
00220   Field(const ULongLongArray &);
00221 
00222   Field(const FloatArray &);
00223   Field(const DoubleArray &);
00224 
00225   Field &operator=(const Field &);
00226 
00227   ~Field();
00228 
00229   // ----------------------------------------------------------------------
00230   // GROUP = Type manipulation
00231   // ----------------------------------------------------------------------
00232 
00233   //
00234   // DESCRIPTION: Set the data type that this field will store.
00235   //
00236   // Makes the field capable of storing data of type ty. If the type
00237   // currently being stored by the filed does not match ty, it is properly
00238   // disposed. After using this function, the user should not assume that
00239   // the data has been initialized, i.e. using Get before a Set is illegal.
00240   //
00241   // EXAMPLE:
00242   //
00243   //       Field fld;
00244   //       fld.SetType(Field::tyString);
00245   //
00246   Boolean SetType(Type ty, ULong ulBound = 0); 
00247   Type GetType() const { return m_ty; }
00248   ULong GetBound() const { return ptr.m_ulBound; };
00249   
00250   //
00251   // DESCRIPTION: Returns the reason why the field was set to 0.
00252   //
00253   // RETURN VALUE:
00254 
00255   //   A code explaining the reason why the field is set to Null. If 0 is
00256   //   returned, the field is not Null. Otherwise, one of these can be
00257   //   expected:
00258   //
00259   //    CDB_FIELD_NULL - The field is Null because it is meant to carry
00260   //                     a Null value.
00261   //
00262   //    CDB_FIELD_UNINITIALIZED - The field is Null because it has not
00263   //                              yet been initialized to another value.
00264   //
00265   //    CDB_FIELD_NONEXISTENT - The field does not exist.
00266   //
00267   ULong IsNull() const { return (m_ty == tyNull)?m_ulWhyNull:0; }
00268 
00269   // ----------------------------------------------------------------------
00270   // GROUP = Accessors
00271   // ----------------------------------------------------------------------
00272   
00273   //
00274   //
00275   //
00276   Boolean GetOctet(Octet &) const;
00277   //{partOf:GetOctet}
00278   Boolean GetString(String &) const;
00279   Boolean getValue(String &) const;
00280   //{partOf:GetOctet}
00281   Boolean GetBoolean(Boolean &) const;
00282 
00283   //{partOf:GetOctet}
00284   Boolean GetShort(Short &) const;
00285   //{partOf:GetOctet}
00286   Boolean GetLong(Long &) const;
00287   Boolean getValue(Long &) const;
00288   //{partOf:GetOctet}
00289   Boolean GetLongLong(LongLong &) const;
00290   Boolean getValue(LongLong & val) const { return GetLongLong(val); }
00291     
00292   //{partOf:GetOctet}
00293   Boolean GetUShort(UShort &) const;
00294   //{partOf:GetOctet}
00295   Boolean GetULong(ULong &) const;
00296   Boolean getValue(ULong &) const;
00297   //{partOf:GetOctet}
00298   Boolean GetULongLong(ULongLong &) const;
00299   Boolean getValue(ULongLong &val) const {  return GetULongLong(val); }
00300 
00301   //{partOf:GetOctet}
00302   Boolean GetFloat(Float &) const;
00303   Boolean getValue(Float &) const;
00304   //{partOf:GetOctet}
00305   Boolean GetDouble(Double &) const;
00306   Boolean getValue(Double &) const;
00307 
00308   //{partOf:GetOctet}
00309   Boolean GetStringArray(StringArray &) const;
00310   //{partOf:GetOctet}
00311   Boolean GetOctetArray(OctetArray &) const;
00312 
00313   //{partOf:GetOctet}
00314   Boolean GetShortArray(ShortArray &) const;
00315   //{partOf:GetOctet}
00316   Boolean GetLongArray(LongArray &) const;
00317   //{partOf:GetOctet}
00318   Boolean GetLongLongArray(LongLongArray &) const;
00319 
00320   //{partOf:GetOctet}
00321   Boolean GetUShortArray(UShortArray &) const;
00322   //{partOf:GetOctet}
00323   Boolean GetULongArray(ULongArray &) const;
00324   //{partOf:GetOctet}
00325   Boolean GetULongLongArray(ULongLongArray &) const;
00326 
00327   //{partOf:GetOctet}
00328   Boolean GetFloatArray(FloatArray &) const;
00329   //{partOf:GetOctet}
00330   Boolean GetDoubleArray(DoubleArray &) const;
00331   Boolean getValue(DoubleArray &) const;
00332 
00333   StringArray * GetStringArray();
00334   LongArray * GetLongArray();
00335 
00336   Field operator[](ULong idx) const; 
00337 
00338 #if defined(CDB_HAS_ANY)
00339   //{partOf:GetOctet}
00340   Boolean GetAny(Any &) const;
00341   //{partOf:GetOctet}
00342   Boolean GetAnyArray(AnyArray &) const;
00343 #endif // defined(CDB_HAS_ANY)
00344 
00345   // ----------------------------------------------------------------------
00346   // GROUP = Mutators
00347   // ----------------------------------------------------------------------
00348 
00349   //
00350   // If the field currently contains other type of data than the one being
00351   // stored, the operation has no effect and false is returned.
00352   //
00353   Boolean SetString(const String &);
00354   Boolean SetOctet(Octet);
00355   Boolean SetBoolean(Boolean);
00356 
00357   Boolean SetShort(Short);
00358   Boolean SetLong(Long);
00359   Boolean SetLongLong(LongLong);
00360 
00361   Boolean SetUShort(UShort);
00362   Boolean SetULong(ULong);
00363   Boolean SetULongLong(ULongLong);
00364 
00365   Boolean SetFloat(Float);
00366   Boolean SetDouble(Double);
00367 
00368   Boolean SetStringArray(const StringArray &);
00369   Boolean SetOctetArray(const OctetArray &);
00370 
00371   Boolean SetShortArray(const ShortArray &);
00372   Boolean SetLongArray(const LongArray &);
00373   Boolean SetLongLongArray(const LongLongArray &);
00374 
00375   Boolean SetUShortArray(const UShortArray &);
00376   Boolean SetULongArray(const ULongArray &);
00377   Boolean SetULongLongArray(const ULongLongArray &);
00378 
00379   Boolean SetFloatArray(const FloatArray &);
00380   Boolean SetDoubleArray(const DoubleArray &);
00381 
00382 #if defined(CDB_HAS_ANY)
00383   Boolean SetAny(const Any &);
00384   Boolean SetAnyArray(const AnyArray &);
00385 #endif // defined(CDB_HAS_ANY)
00386 
00387   // ----------------------------------------------------------------------
00388   // GROUP = Conversion helpers
00389   // ----------------------------------------------------------------------
00390 
00391   Boolean ToString(String &, Boolean bType = 1) const;
00392   Boolean FromString(const String &);
00393 
00394 #if defined(CDB_HAS_ANY)
00395   //Boolean ToAny(Any &) const;
00396   //Boolean ToAny(Any &) const;
00397   //Boolean FromAny(const Any &);
00398 #endif // defined(CDB_HAS_ANY)
00399 
00400 protected:
00401   //
00402   // Identifies the type of data currently being stored.
00403   //
00404   Type  m_ty;  
00405   union
00406   {
00407     //
00408     // Inlined data can be up to 8 bytes in length. This is sufficient for
00409     // storing octets, short, long, and longlong integers, doubles and
00410     // floats. Other types store a pointer to the actual data and a bound
00411     // on the amount of data that can be stored there (e.g., number of
00412     // characters for strings). A bound of 0 indicates "no limits".
00413     //
00414     Octet  m_inline[8];
00415     struct
00416     {
00417       ULong  m_ulBound;
00418       void  *m_pointer;
00419     } ptr;
00420     
00421     ULong m_ulWhyNull;
00422   };
00423 
00424   Boolean Convert( Octet& val ) const;
00425   Boolean Convert( Short& val ) const;
00426   Boolean Convert( Long& val ) const;
00427   Boolean Convert( LongLong& val ) const;
00428   Boolean Convert( UShort& val ) const;
00429   Boolean Convert( ULong& val ) const;
00430   Boolean Convert( ULongLong& val ) const;
00431   Boolean Convert( Float& val ) const;
00432   Boolean Convert( Double& val ) const;
00433 
00434   Boolean Convert(StringArray &val) const;
00435   Boolean Convert(LongArray &val) const;
00436   Boolean Convert(DoubleArray &val) const;
00437 };
00438 
00439 //
00440 // DESCRIPTION: An array of fields.
00441 //
00442 typedef std::vector<Field> FieldArray;
00443 
00444 //#include "cdbField.i"
00445 
00446  }; 
00447 
00448 #endif // __cdb__Field_h__
00449 
00450 // ************************************************************************
00451 //
00452 // REVISION HISTORY:
00453 //
00454 //   $Log: cdbField.h,v $
00455 //   Revision 1.31  2011/10/28 15:05:05  hsommer
00456 //   Manually fixed "no LGPL license text" issue reported by addCopyright.py
00457 //
00458 //   Revision 1.30  2006/09/01 02:20:54  cparedes
00459 //   small change, NAMESPACE_BEGIN / NAMESPACE_END / NAMESPACE_USE macross to clean up a little the cpp code
00460 //
00461 //   Revision 1.29  2005/08/23 15:22:54  vwang
00462 //   to add float into BACI
00463 //
00464 //   Revision 1.28  2005/02/14 10:39:49  acaproni
00465 //   Some changes to reduce the coding standards number of errors
00466 //
00467 //   Revision 1.27  2003/07/10 15:23:16  bjeram
00468 //   support for longlong and uLongLong
00469 //
00470 //   Revision 1.26  2003/07/09 08:07:35  bjeram
00471 //   ported to gcc 3.2
00472 //
00473 //   Revision 1.25  2003/05/06 13:32:01  bjeram
00474 //   port to Tornado 2.2
00475 //
00476 //   Revision 1.24  2003/01/28 16:43:50  vltsccm
00477 //   gchiozzi: patch for cdb module to create lib/endorsed directory, since CVS cannot restore empty directories
00478 //
00479 //   Revision 1.23  2003/01/24 10:44:04  vltsccm
00480 //   cdb1.23
00481 //
00482 //   Revision 1.22  2003/01/20 15:12:19  vltsccm
00483 //   cdb1.22
00484 //
00485 //   Revision 1.21  2003/01/20 10:45:53  vltsccm
00486 //   cdb1.21
00487 //
00488 //   Revision 1.20  2002/12/05 16:03:58  vltsccm
00489 //   cdb1.20
00490 //
00491 //   Revision 1.19  2002/11/25 16:04:50  vltsccm
00492 //   cdb1.19
00493 //
00494 //   Revision 1.18  2002/11/13 14:53:04  vltsccm
00495 //   cdb1.18
00496 //
00497 //   Revision 1.17  2002/11/13 10:22:31  vltsccm
00498 //   cdb1.17
00499 //
00500 //   Revision 1.16  2002/11/06 08:37:04  vltsccm
00501 //   cdb1.16
00502 //
00503 //   Revision 1.15.1.23  2002/11/05 16:05:13  vltsccm
00504 //   cdb1.15.1.23
00505 //
00506 //   Revision 1.15.1.22  2002/11/05 13:46:31  vltsccm
00507 //   cdb1.15.1.22
00508 //
00509 //   Revision 1.15.1.21  2002/11/05 10:41:14  vltsccm
00510 //   cdb1.15.1.21
00511 //
00512 //   Revision 1.15.1.20  2002/11/01 12:49:03  vltsccm
00513 //   cdb1.15.1.20
00514 //
00515 //   Revision 1.15.1.19  2002/10/30 07:56:44  vltsccm
00516 //   cdb1.15.1.19
00517 //
00518 //   Revision 1.15.1.18  2002/10/25 12:44:24  vltsccm
00519 //   cdb1.15.1.18
00520 //
00521 //   Revision 1.15.1.17  2002/10/24 13:08:44  vltsccm
00522 //   cdb1.15.1.17
00523 //
00524 //   Revision 1.15.1.16  2002/10/16 11:43:45  vltsccm
00525 //   cdb1.15.1.16
00526 //
00527 //   Revision 1.15.1.15  2002/10/14 22:26:10  vltsccm
00528 //   cdb1.15.1.15
00529 //
00530 //   Revision 1.15.1.14  2002/10/14 12:18:32  vltsccm
00531 //   cdb1.15.1.14
00532 //
00533 //   Revision 1.15.1.13  2002/10/04 16:20:23  vltsccm
00534 //   cdb1.15.1.13
00535 //
00536 //   Revision 1.15.1.12  2002/10/02 12:54:14  vltsccm
00537 //   cdb1.15.1.12
00538 //
00539 //   Revision 1.15.1.11  2002/10/01 10:33:25  vltsccm
00540 //   cdb1.15.1.11
00541 //
00542 //   Revision 1.15.1.10  2002/09/30 13:56:52  vltsccm
00543 //   cdb1.15.1.10
00544 //
00545 //   Revision 1.15.1.9  2002/09/26 14:13:10  vltsccm
00546 //   cdb1.15.1.9
00547 //
00548 //   Revision 1.15.1.8  2002/09/26 07:45:46  vltsccm
00549 //   cdb1.15.1.8
00550 //
00551 //   Revision 1.15.1.7  2002/09/17 16:19:22  vltsccm
00552 //   cdb1.15.1.7
00553 //
00554 //   Revision 1.15.1.6  2002/09/17 11:15:47  vltsccm
00555 //   cdb1.15.1.6
00556 //
00557 //   Revision 1.15.1.5  2002/09/02 09:37:06  vltsccm
00558 //   cdb1.15.1.5
00559 //
00560 //   Revision 1.15.1.4  2002/08/09 09:35:23  vltsccm
00561 //   cdb1.15.1.4
00562 //
00563 //   Revision 1.15.1.3  2002/07/24 07:29:11  vltsccm
00564 //   cdb1.15.1.3
00565 //
00566 //   Revision 1.15.1.2  2002/07/12 09:58:17  vltsccm
00567 //   cdb1.15.1.2
00568 //
00569 //   Revision 1.15+.1.1  2002/07/09 09:40:09  vltsccm
00570 //   cdb1.15.1
00571 //
00572 //   Revision 1.15  2002/02/05 17:50:08  vltsccm
00573 //   cdb1.15
00574 //
00575 //   Revision 1.14  2002/01/14 21:14:18  vltsccm
00576 //   cdb1.14
00577 //
00578 //   Revision 1.13  2001/10/19 09:56:22  vltsccm
00579 //   cdb1.13
00580 //
00581 //   Revision 1.12  2001/09/18 10:07:12  vltsccm
00582 //   cdb1.12
00583 //
00584 //   Revision 1.11  2001/07/12 07:48:27  vltsccm
00585 //   cdb1.11
00586 //
00587 //   Revision 1.10  2001/07/11 09:16:16  vltsccm
00588 //   cdb1.10
00589 //
00590 //   Revision 1.6  2000/12/07 18:00:41  vltsccm
00591 //   cdb1.6
00592 //
00593 //   Revision 1.5  2000/11/17 13:14:58  vltsccm
00594 //   cdb1.5
00595 //
00596 //   Revision 1.4  2000/10/20 13:51:28  vltsccm
00597 //   cdb1.4
00598 //
00599 //   Revision 1.3  2000/10/20 13:51:27  vltsccm
00600 //   cdb1.3
00601 //
00602 //   Revision 1.2  2000/10/20 13:51:26  vltsccm
00603 //   cdb1.2
00604 //
00605 //   Revision 1.1  2000/10/20 13:51:26  vltsccm
00606 //   cdb1.1
00607 //
00608 //   Revision 1.0  2000/10/20 13:51:26  vltsccm
00609 //   cdb1.0
00610 //
00611 //   Revision 1.3  2000/10/13 16:03:02  vltsccm
00612 //   cdb1.3
00613 //
00614 //   Revision 1.2  2000/09/13 14:49:28  vltsccm
00615 //   cdb1.2
00616 //
00617 //   Revision 1.1  2000/09/06 15:42:11  vltsccm
00618 //   cdb1.1
00619 //
00620 //   Revision 1.1  2000/06/13 07:26:24  kzagar
00621 //   CDB, initial commit. Documentation not yet finished.
00622 //
00623 // ************************************************************************

Generated on Thu Jan 12 2012 23:13:50 for ACS-10.0 C++ API by  doxygen 1.7.0