diff --git a/include/atmi/atmi++.hpp b/include/atmi/atmi++.hpp index e6a3626..1fad819 100644 --- a/include/atmi/atmi++.hpp +++ b/include/atmi/atmi++.hpp @@ -28,9 +28,11 @@ #include #include -#include +#include +#include #include #include +#include #include #include diff --git a/include/atmi/call_info.hpp b/include/atmi/call_info.hpp index 1c49d91..01c2e4c 100644 --- a/include/atmi/call_info.hpp +++ b/include/atmi/call_info.hpp @@ -8,7 +8,7 @@ #include #include -#include +#include #ifndef CPP_ATMI_CALL_INFO_HPP #define CPP_ATMI_CALL_INFO_HPP @@ -69,7 +69,7 @@ namespace atmi { private: buffer _buffer; - Tfield _ecid; + Tfield _ecid; }; /** @} */ diff --git a/include/atmi/carray_field.hpp b/include/atmi/carray_field.hpp index 5fe4a54..a68acee 100644 --- a/include/atmi/carray_field.hpp +++ b/include/atmi/carray_field.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #ifndef CPP_ATMI_CARRAY_FIELD_HPP #define CPP_ATMI_CARRAY_FIELD_HPP @@ -29,11 +29,17 @@ namespace atmi { * * This class is using a std::string object to hold and handle char * data * \copydoc atmi::field + * + * @tparam T field's backend data type. + * @tparam fid field ID */ - template <> class Tfield: public field { + template class Tfield: public field { public: - Tfield(): _length (0),_buffer_size(0), _value (NULL) { + /** create an instance of a specific FML field. + * + */ + Tfield(): _length (0),_buffer_size(0), _value (NULL), field(fid) { // intentional }; @@ -157,14 +163,9 @@ namespace atmi { return _value[index]; } - /* if you need to change the field's value, get a copy by calling get_char_array. - * - * @return address of first character in carray (is NULL if no carray data is available) - */ -// operator const char * () const { -// return _value ; -// } - + const std::string to_string() const { + return __FUNCTION__; + } protected: diff --git a/include/atmi/fields.hpp b/include/atmi/field.hpp similarity index 51% rename from include/atmi/fields.hpp rename to include/atmi/field.hpp index 1103247..324276e 100644 --- a/include/atmi/fields.hpp +++ b/include/atmi/field.hpp @@ -109,6 +109,8 @@ namespace atmi { return *this; }; + virtual const std::string to_string() const = 0; + protected: /** default constructor @@ -249,41 +251,6 @@ namespace atmi { } - /** set field id. - * - * This template only handles numerical field IDs. - * - * @param field_id the fml field id to setup (as defined in the FML tables) - */ -// TODO remove -// virtual void set_id(FLDID32 field_id){ -// -// /** This array is used to check that FML type matches template Tfield's type */ -// const char *TYPEID_NAMES[5] = { -// typeid(short).name(), -// typeid(long).name(), -// typeid(char).name(), -// typeid(float).name(), -// typeid(double).name() -// }; -// -// field::set_id ( field_id ); -// -// // check if type is matching declaration in FML table -// if ( type() >= FLD_STRING ) { // 0..FLD_STRING(5) correspond to numerical types -// -// throw atmi_exception ( "This template doesn't support the given type Tfield<%s>.", tname ()); -// -// } else if ( strcmp (typeid(_value).name (), TYPEID_NAMES[type()]) != 0 ) { -// -// throw atmi_exception ( "Tfield [%s] (id: %d) value is of type %s and the FML table decalares a type %s.", -// name().c_str(), -// field_id, -// typeid(_value).name(), -// tname()); -// } -// }; - /** dispose of resources */ virtual ~Tfield() { @@ -402,285 +369,8 @@ namespace atmi { }; - - /** Specialization of template Tfield which handles std::string typed fields. - * - * This class is using a std::string object to hold and handle std::string data - * - * \copydoc atmi::field - * - * @tparam T field's backend data type. - * @tparam fid field ID - */ - template - class Tfield: public field { - public: - - /** new instance. - */ - Tfield(): _value(""), field(fid){ - // intentional - }; - - /** Constructs a Tfield for the passed field id. - * - * The search is done in the tables identified by FLDTBLDIR32 and FIELDTBLS32 - * - * @param id the fml field id to setup (as defined in the FML tables) - */ - explicit Tfield ( FLDID32 id ): _value(""), field(id) { - - // check type mismatch - check_type_match(); - } - - /** Constructs a Tfield for the passed name. - * - * The search is done in the tables identified by FLDTBLDIR32 and FIELDTBLS32 - * - * @param name the fml field name to setup (as defined in the FML tables) - */ - explicit Tfield ( const char *name ): _value(""), field(name) { - - // check type mismatch - check_type_match(); - } - - virtual ~Tfield() { - // Intentionally unimplemented... - }; - - /** @return the std::string's length - */ - virtual FLDLEN32 length () { - - return (FLDLEN32)_value.length(); - }; - - /** @return the std::string's size - */ - virtual FLDLEN32 size () { - - return (FLDLEN32)_value.size(); - }; - - /** @return a C std::string (with \0) of current std::string's content. - */ - const char* c_str ( ) const { - return _value.c_str(); - } - - /** Appends a copy of the argument to the std::string. - * - * The new std::string content is the content existing in the std::string object before the call followed by the content of - * the argument. - * - * The append member function provides a similar functionality with additional options. - * - * @param str a copy of the content of this object is appended to the object's content. - * @return *this - */ - std::string& operator+= ( const std::string& str ){ - - _value += str; - return _value; - } - - /** Appends a copy of the argument to the std::string. - * - * The new std::string content is the content existing in the std::string object before the call followed by the content of - * the argument. - * - * The append member function provides a similar functionality with additional options. - * - * @param str a pointer to an array containing a null-terminated character sequence (C std::string), which is appended to the object's content. - * @return *this - */ - std::string& operator+= ( const char* str ){ - - _value += str; - return _value; - } - - /** Appends character to the std::string field. - * - * @param c character. This single character is appended to the std::string object's content. - * @return *this - */ - std::string& operator+= ( char c ){ - _value += c; - return _value; - } - - /** - * Returns a reference the character at position pos in the std::string. - * - * The function actually returns data()[ pos ]. - * - * The at member function has the same behavior as this operator function, except that at also performs a range - * check. - * - * @param pos position within the std::string of the character to be retrieved. Notice that the first character - * in the std::string has a position of 0, not 1. size_t is an unsigned integral type. - * - * @return The character at the specified position in the std::string. - */ - const char& operator[] ( size_t pos ) const { - - return _value[pos]; - } - - /** - * Returns a reference the character at position pos in the std::string. - * - * The function actually returns data()[ pos ]. - * - * The at member function has the same behavior as this operator function, except that at also performs a range - * check. - * - * @param pos position within the std::string of the character to be retrieved. Notice that the first character - * in the std::string has a position of 0, not 1. size_t is an unsigned integral type. - * - * @return The character at the specified position in the std::string. - */ - char& operator[] ( size_t pos ){ - - return _value[pos]; - } - - /** - * assigns values to the std::string field. - * - * @param str null terminated character array. - */ - virtual Tfield &operator= ( const char* str ) { - - _value = str; - return *this; - }; - - /** - * assigns values to the std::string field. - * - * @param str std::string to assign - */ - virtual Tfield &operator= ( const std::string &str ) { - - _value = str; - - return *this; - }; - - /** - * assigns values to the std::string field. - * - * @param c the content is set to a single character. - */ - virtual Tfield &operator= ( char &c ) { - - _value = c; - - return *this; - }; - - /** casts the field value - */ - operator std::string(){ - - return _value; - }; - - protected: - - virtual int set ( buffer &b) { - - int rc = -1; - - rc = Fchg32 ( b.get_buffer(), id(), occurence(), (char *) _value.c_str(), length() ); - if ( rc < 0 ) { - throw buffer_exception ( Ferror32, "FCHG32 Tfield::set failed for field %s (id: %d, occ: %d)", - name().c_str(), - id(), - occurence() ); - } - - return rc; - }; - - virtual int add ( buffer &b) { - - int rc = -1; - if ( length () > 0 ) { - try { - if ( (needed () + b.used()) >= b.size()) { - b.extend (); - } - } catch ( buffer_exception &buffErr ) { - throw atmi_exception ( "Add failed to estimate needed memory extension. Original message was : %s", buffErr.what() ); - } - - rc = Fadd32 ( b.get_buffer(), id(), (char *) _value.c_str(), length() ); - if ( rc < 0 ) { - throw buffer_exception ( Ferror32, "FADD32 Tfield::add failed for field %s (id: %d, occ: %d)", - name().c_str(), - id(), - occurence() ); - } else { - set_field_occurence ( (b.occurences ( *this ) == 0 ? 0 : b.occurences ( *this )-1)); - } - } else { - throw atmi_exception ("field %s's value is empty !!?? Cannot add an empty field value.", - name ().c_str()); - } - - return rc; - }; - - virtual int get ( buffer &b ){ - - return get ( b, occurence() ); - }; - - virtual int get ( buffer &b, FLDOCC32 occ ){ - - int rc = -1; - FLDLEN32 l = 0; - char *v = NULL; - set_field_occurence(occ); - - v = Fgetsa32 ( b.get_buffer(), id(), occurence(), &l ); - if ( v != NULL ) { - - rc=0; - _value = v; // copy v into std::string value - delete v; - - } else { - throw buffer_exception (Ferror32, "FGETSA32 Tfield::get failed to get field %s (id: %d, occ: %d).", - name().c_str(), - id(), - occurence() ); - } - - return rc; - }; - - void check_type_match(){ - // check type matching - if ( type() !=5 ) { - throw atmi_exception ( "Tfield [%s] (id: %d) value is of type %s and the FML table decalares a type %s.", - name().c_str(), - id(), - typeid(_value).name(), - tname()); - } - } - - std::string _value; //!< std::string field's value - }; - /** Helper that handles the operator << between output streams and field value */ - std::ostream &operator<< ( std::ostream &o, Tfield &f ); + std::ostream &operator<< ( std::ostream &o, field &f ); /** @} */ } // namespace atmi diff --git a/include/atmi/string_field.hpp b/include/atmi/string_field.hpp new file mode 100644 index 0000000..4020693 --- /dev/null +++ b/include/atmi/string_field.hpp @@ -0,0 +1,314 @@ +/* + * FML manipulation classes + * + * author: herbert koelman herbert.koelman@me.com + * creation date: 1/1/2006 + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#ifndef CPP_ATMI_FIELDS_HPP +#define CPP_ATMI_FIELDS_HPP + +// using namespace std; + +namespace atmi { + +/** \addtogroup fml + * + * @{ + */ + + /** Specialization of template Tfield which handles std::string typed fields. + * + * This class is using a std::string object to hold and handle std::string data + * + * \copydoc atmi::field + * + * @tparam T field's backend data type. + * @tparam fid field ID + */ + template + class Tfield: public field { + public: + + /** new instance. + */ + Tfield(): _value(""), field(fid){ + // intentional + }; + + /** Constructs a Tfield for the passed field id. + * + * The search is done in the tables identified by FLDTBLDIR32 and FIELDTBLS32 + * + * @param id the fml field id to setup (as defined in the FML tables) + */ + explicit Tfield ( FLDID32 id ): _value(""), field(id) { + + // check type mismatch + check_type_match(); + } + + /** Constructs a Tfield for the passed name. + * + * The search is done in the tables identified by FLDTBLDIR32 and FIELDTBLS32 + * + * @param name the fml field name to setup (as defined in the FML tables) + */ + explicit Tfield ( const char *name ): _value(""), field(name) { + + // check type mismatch + check_type_match(); + } + + virtual ~Tfield() { + // Intentionally unimplemented... + }; + + /** @return the std::string's length + */ + virtual FLDLEN32 length () { + + return (FLDLEN32)_value.length(); + }; + + /** @return the std::string's size + */ + virtual FLDLEN32 size () { + + return (FLDLEN32)_value.size(); + }; + + /** @return a C std::string (with \0) of current std::string's content. + */ + const char* c_str ( ) const { + return _value.c_str(); + } + + /** Appends a copy of the argument to the std::string. + * + * The new std::string content is the content existing in the std::string object before the call followed by the content of + * the argument. + * + * The append member function provides a similar functionality with additional options. + * + * @param str a copy of the content of this object is appended to the object's content. + * @return *this + */ + std::string& operator+= ( const std::string& str ){ + + _value += str; + return _value; + } + + /** Appends a copy of the argument to the std::string. + * + * The new std::string content is the content existing in the std::string object before the call followed by the content of + * the argument. + * + * The append member function provides a similar functionality with additional options. + * + * @param str a pointer to an array containing a null-terminated character sequence (C std::string), which is appended to the object's content. + * @return *this + */ + std::string& operator+= ( const char* str ){ + + _value += str; + return _value; + } + + /** Appends character to the std::string field. + * + * @param c character. This single character is appended to the std::string object's content. + * @return *this + */ + std::string& operator+= ( char c ){ + _value += c; + return _value; + } + + /** + * Returns a reference the character at position pos in the std::string. + * + * The function actually returns data()[ pos ]. + * + * The at member function has the same behavior as this operator function, except that at also performs a range + * check. + * + * @param pos position within the std::string of the character to be retrieved. Notice that the first character + * in the std::string has a position of 0, not 1. size_t is an unsigned integral type. + * + * @return The character at the specified position in the std::string. + */ + const char& operator[] ( size_t pos ) const { + + return _value[pos]; + } + + /** + * Returns a reference the character at position pos in the std::string. + * + * The function actually returns data()[ pos ]. + * + * The at member function has the same behavior as this operator function, except that at also performs a range + * check. + * + * @param pos position within the std::string of the character to be retrieved. Notice that the first character + * in the std::string has a position of 0, not 1. size_t is an unsigned integral type. + * + * @return The character at the specified position in the std::string. + */ + char& operator[] ( size_t pos ){ + + return _value[pos]; + } + + /** + * assigns values to the std::string field. + * + * @param str null terminated character array. + */ + virtual Tfield &operator= ( const char* str ) { + + _value = str; + return *this; + }; + + /** + * assigns values to the std::string field. + * + * @param str std::string to assign + */ + virtual Tfield &operator= ( const std::string &str ) { + + _value = str; + return *this; + }; + + /** + * assigns values to the std::string field. + * + * @param c the content is set to a single character. + */ + virtual Tfield &operator= ( char &c ) { + + _value = c; + return *this; + }; + + /** casts the field value + */ + operator std::string(){ + + return _value; + }; + + virtual const std::string to_string() const { + std::cout << __FUNCTION__ << std::endl; + return _value; + } + + protected: + + virtual int set ( buffer &b) { + + int rc = -1; + + rc = Fchg32 ( b.get_buffer(), id(), occurence(), (char *) _value.c_str(), length() ); + if ( rc < 0 ) { + throw buffer_exception ( Ferror32, "FCHG32 Tfield::set failed for field %s (id: %d, occ: %d)", + name().c_str(), + id(), + occurence() ); + } + + return rc; + }; + + virtual int add ( buffer &b) { + + int rc = -1; + if ( length () > 0 ) { + try { + if ( (needed () + b.used()) >= b.size()) { + b.extend (); + } + } catch ( buffer_exception &buffErr ) { + throw atmi_exception ( "Add failed to estimate needed memory extension. Original message was : %s", buffErr.what() ); + } + + rc = Fadd32 ( b.get_buffer(), id(), (char *) _value.c_str(), length() ); + if ( rc < 0 ) { + throw buffer_exception ( Ferror32, "FADD32 Tfield::add failed for field %s (id: %d, occ: %d)", + name().c_str(), + id(), + occurence() ); + } else { + set_field_occurence ( (b.occurences ( *this ) == 0 ? 0 : b.occurences ( *this )-1)); + } + } else { + throw atmi_exception ("field %s's value is empty !!?? Cannot add an empty field value.", + name ().c_str()); + } + + return rc; + }; + + virtual int get ( buffer &b ){ + + return get ( b, occurence() ); + }; + + virtual int get ( buffer &b, FLDOCC32 occ ){ + + int rc = -1; + FLDLEN32 l = 0; + char *v = NULL; + set_field_occurence(occ); + + v = Fgetsa32 ( b.get_buffer(), id(), occurence(), &l ); + if ( v != NULL ) { + + rc=0; + _value = v; // copy v into std::string value + delete v; + + } else { + throw buffer_exception (Ferror32, "FGETSA32 Tfield::get failed to get field %s (id: %d, occ: %d).", + name().c_str(), + id(), + occurence() ); + } + + return rc; + }; + + void check_type_match(){ + // check type matching + if ( type() !=5 ) { + throw atmi_exception ( "Tfield [%s] (id: %d) value is of type %s and the FML table decalares a type %s.", + name().c_str(), + id(), + typeid(_value).name(), + tname()); + } + } + + std::string _value; //!< std::string field's value + }; + + /** Helper that handles the operator << between output streams and field value */ + std::ostream &operator<< ( std::ostream &o, Tfield &f ); + +/** @} */ +} // namespace atmi +#endif diff --git a/include/atmi/template_field.hpp b/include/atmi/template_field.hpp new file mode 100644 index 0000000..6b97092 --- /dev/null +++ b/include/atmi/template_field.hpp @@ -0,0 +1,196 @@ +/* + * FML manipulation classes + * + * author: herbert koelman herbert.koelman@me.com + * creation date: 1/1/2006 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef CPP_ATMI_FIELDS_HPP +#define CPP_ATMI_FIELDS_HPP + +namespace atmi { + +/** \addtogroup fml + * + * @{ + */ + + /** Template that handles short, long, char, double data types. + * + * \copydoc atmi::field + * + * @tparam T field's backend data type. + * @tparam fid field ID (defaults to BADFLDID ) + * + */ + template + class Tfield : public field { + public: + + /** default constructor. + * + * The instance cannot be used until set_field_id is successfully called. + * + * @since v4.2.0 + */ + Tfield(): _value(0), field(fid){ + }; + + /** Constructs a Tfield for the passed field id + * + * The search is done in the tables identified by FLDTBLDIR32 and FIELDTBLS32 + * + * @param field_id the fml field id to setup (as defined in the FML tables) + */ + explicit Tfield ( FLDID32 field_id ): _value(0), field(field_id){ + // check data type is compatible + check_type_match(); + } + + /** Constructs a Tfield for the passed name + * + * The search is done in the tables identified by FLDTBLDIR32 and FIELDTBLS32 + * + * @param name the fml field name to setup (as defined in the FML tables) + */ + explicit Tfield ( const std::string &name ): _value(0), field (name) { + + // check data type is compatible + check_type_match(); + + } + + /** dispose of resources + */ + virtual ~Tfield() { + // Intentional... + }; + + /** @return de length (or size) of the field's data + */ + virtual FLDLEN32 length () { + + return sizeof ( _value ); + }; + + /** Assigns a value to the field + * ... + * Tfield f (fid); + * f = 156 ; // Set value to 156 + * ... + */ + T operator= ( T value) { + + _value = value; + + return *this; + }; + + /** casts the field value + * ... + * Tfield f (fid); + * f = 156 ; + * int x = f ; // returns 156 + * ... + */ + operator T(){ + + return _value; + }; + + const std::string to_string() const { + return __FUNCTION__; + } + + protected: + + virtual int set ( buffer &b) { + + int rc = -1; + + rc = Fchg32 ( b.get_buffer(), id(), occurence(), (char *) &_value, length() ); + if ( rc < 0 ) { + throw buffer_exception ( Ferror32, "FCHG32 Tfield::set failed for field %s (id: %d, occ: %d)", + name().c_str(), + id(), + occurence() ); + } + + return rc; + }; + + virtual int add ( buffer &b) { + + int rc = -1; + try { + if ( (needed () + b.used()) >= b.size()) { + b.extend (); + } + } catch ( buffer_exception &buffErr ) { + throw atmi_exception ( "Add failed to estimate needed memory extension. Original message was : %s", buffErr.what() ); + } + + rc = Fadd32 ( b.get_buffer(), id(), (char *) &_value, length() ); + if ( rc < 0 ) { + throw buffer_exception ( Ferror32, "FADD32 Tfield::add failed for field %s (id: %d, occ: %d)", + name().c_str(), + id(), + occurence() ); + } else { + set_field_occurence ( (b.occurences ( *this ) == 0 ? 0 : b.occurences ( *this )-1)); + } + + return rc; + }; + + virtual int get ( buffer &b ){ + + return get ( b, occurence() ); + }; + + virtual int get ( buffer &b, FLDOCC32 occ ){ + + int rc = -1; + FLDLEN32 l = length(); + set_field_occurence (occ); + + rc = Fget32 ( b.get_buffer(), id(), occurence(), (char *) &_value, &l ); + if ( rc == -1 ) { + throw buffer_exception (Ferror32, "FGET32 failed to get field %s (id: %d, occ: %d).", + name().c_str(), + id(), + occurence() ); + } + + return rc; + }; + + /** check if backend type is compatible with FML type + */ + void check_type_match(){ + // check type matching + if (strcmp (typeid(_value).name(), tname ()) != 0 ) { + throw atmi_exception ( "Tfield [%s] (id: %d) backend value is of type %s and the FML table decalares a type %s.", + name().c_str(), + id(), + typeid(_value).name(), + tname()); + } + } + + T _value; //!< field's current value + + }; + +/** @} */ +} // namespace atmi +#endif diff --git a/src/Makefile.in b/src/Makefile.in index 56357e6..c0722f6 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -73,7 +73,8 @@ libatmi++.a: $(ATMI_SRV_OBJS) $(INCDIR)/tuxedo.hpp $(INCDIR)/exceptions.hpp ${AR} ${LIBDIR}/$@ $(ATMI_SRV_OBJS) $(RANLIB) ${LIBDIR}/$@ -libfml++.a: $(BUFF_OBJS) $(INCDIR)/buffer.hpp $(INCDIR)/fields.hpp $(INCDIR)/exceptions.hpp + +libfml++.a: $(BUFF_OBJS) $(INCDIR)/buffer.hpp $(INCDIR)/field.hpp $(INCDIR)/carray_field.hpp $(INCDIR)/string_field.hpp $(INCDIR)/template_field.hpp ${AR} ${LIBDIR}/$@ $(BUFF_OBJS) $(RANLIB) ${LIBDIR}/$@ diff --git a/src/buffer.cpp b/src/buffer.cpp index 9ad3d73..89fb639 100644 --- a/src/buffer.cpp +++ b/src/buffer.cpp @@ -10,7 +10,7 @@ #include -#include "atmi/fields.hpp" +#include "atmi/field.hpp" #include "atmi/call_info.hpp" namespace atmi { diff --git a/src/field.cpp b/src/field.cpp index e295f2c..52da58d 100644 --- a/src/field.cpp +++ b/src/field.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include namespace atmi { @@ -52,25 +52,6 @@ namespace atmi { return Ftype32 ( _field_id ); }; -// TODO remove -// void field::set_id (FLDID32 field_id){ -// -// if ( field_id == 0 ){ -// // check that field exists in FML table referenced by FIELDTBLS32 -// // and FLDTBLDIR32 -// _field_name = Fname32( field_id ); -// -// if ( ! _field_name.empty() ) { // Fname32 found the field -// _field_id = field_id; -// _field_occurence = 0; -// } else { -// throw buffer_exception ( Ferror32, "Failed to initialize field %d. Check the values of FIELDTBLS32 and FLDTBLDIR32.", field_id ); -// } -// } else { -// _field_id = 0 ; -// } -// }; - void field::setup( FLDID32 field_id){ //TODO remove field::set_id(field_id); } @@ -145,9 +126,10 @@ namespace atmi { // operators -------------------------------------------------------------------------------- - std::ostream &operator<< ( std::ostream &out, Tfield &f ){ + std::ostream &operator<< ( std::ostream &out, field &f ){ - return out << (std::string)f; + std::cout << __FUNCTION__ << std::endl; + return out << f.to_string(); }; } diff --git a/tests/clients/field_test.bcl b/tests/clients/field_test.bcl index 585d58e..38203c7 100644 --- a/tests/clients/field_test.bcl +++ b/tests/clients/field_test.bcl @@ -14,101 +14,99 @@ #include "sample_fml_table.h" -template< class T, FLDID32 F = 0 > -class _field: public atmi::Tfield { - public: - _field(): atmi::Tfield(F){ - } +void line(){ + std::cout << std::endl << "---------------------------" << std::endl << std::endl; +} - _field( FLDID32 id ): atmi::Tfield(id){ - } +void test(const char *description){ + std::cout << "TEST >>>> " << description << std::endl; +} - T operator=( T v ){ - atmi::Tfield::value = v; +int string_field_tests(){ + int status = EXIT_SUCCESS; - return atmi::Tfield::value ; - } -}; + std::cout << std::endl << __FUNCTION__ << "---------------------------" << std::endl << std::endl; -typedef _field prenom_t; -typedef _field empid_t; -typedef _field void_t; + { + atmi::Tfield empname; + empname = "empname"; + std::cout << empname.name() << ": " << empname << ". " << empname.what() << std::endl ; -class fields { - public: - fields(){ - prenom = "hello world" ; - std::cout << __FUNCTION__ << ": " << prenom << std::endl ; - } + atmi::Tfield _empname(EMPNAME); + _empname = "herbert koelman"; + std::cout << _empname.name() << ": " << (std::string) _empname << ". " << _empname.what() << std::endl ; - private: - prenom_t prenom ; -}; + test("succesful"); + } + line(); -class field_empid: public atmi::Tfield { - public: - field_empid(): atmi::Tfield(EMPID){ - } + return status ; +} -}; +int template_field_tests(){ + int status = EXIT_SUCCESS; -// program main ------------------------------------------------- + std::cout << std::endl << __FUNCTION__ << "---------------------------" << std::endl << std::endl; -int main ( int argc, char **argv ) { + { + test("IMPID field ID: "); - auto status = EXIT_FAILURE; - try { + atmi::Tfield empid_(EMPID); + std::auto_ptr empid_ptr(new atmi::Tfield); + std::cout << empid_ptr->name() << "(PTR): " << empid_ptr->what() << std::endl; - std::cout << "field sample program (" << atmi::cpp_atmi_version() <<")." << std::endl; + atmi::Tfield empid; + empid = 10; + std::cout << empid.name() << ": " << empid << std::endl << " " << empid.what() << std::endl; - std::cout << std::endl << "---------------------------" << std::endl << std::endl; + test("succesful"); + } - { - std::cout << "TEST >>>> IMPID field ID: " << std::endl; + { + test ("IMPID field name"); - atmi::Tfield empid_(EMPID); - std::auto_ptr empid_ptr(new atmi::Tfield); - std::cout << empid_ptr->name() << "(PTR): " << empid_ptr->what() << std::endl; + atmi::Tfield empid("EMPID"); + empid = 10; + std::cout << empid.name() << ": " << empid << std::endl << " " << empid.what() << std::endl; - atmi::Tfield empid; - empid = 10; - std::cout << empid.name() << ": " << empid << std::endl << " " << empid.what() << std::endl; + test("succesful"); + } - std::cout << "TEST >>>> succesful" << std::endl ; - } + line(); - { - std::cout << "TEST >>>> IMPID field name: " << std::endl; + { + std::cout << "TEST >>>> Tfields type mismatch detection: " << std::endl; - atmi::Tfield empid("EMPID"); - empid = 10; - std::cout << empid.name() << ": " << empid << std::endl << " " << empid.what() << std::endl; + try { + atmi::Tfield empid(EMPID); + status = EXIT_FAILURE; + }catch ( std::exception &err ){ + std::cerr << err.what() << std::endl; + } - std::cout << "TEST >>>> succesful" << std::endl ; + try { + atmi::Tfield empid("EMPID"); + status = EXIT_FAILURE; + }catch ( std::exception &err ){ + std::cerr << err.what() << std::endl; } + } - std::cout << std::endl << "---------------------------" << std::endl << std::endl; + line(); - { - std::cout << "TEST >>>> Tfields type mismatch detection: " << std::endl; + return status ; +} - try { - atmi::Tfield empid(EMPID); - }catch ( std::exception &err ){ - std::cerr << "field test failed. " << err.what() << std::endl; - } +int main ( int argc, char **argv ) { - try { - atmi::Tfield empid("EMPID"); - }catch ( std::exception &err ){ - std::cerr << "field test failed. " << err.what() << std::endl; - } + auto status = EXIT_FAILURE; + try { - std::cout << "TEST >>>> succesful" << std::endl ; - } + std::cout << "START of field sample program (" << atmi::cpp_atmi_version() <<")." << std::endl; - std::cout << std::endl << "---------------------------" << std::endl << std::endl; + // status = template_field_tests(); + status = string_field_tests(); std::cout << "END of field sample program" << std::endl ; status = EXIT_SUCCESS;