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

cdbField.h

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

Generated on Thu Jul 8 2010 19:47:47 for ACS-9.0 C++ API by  doxygen 1.7.0