Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Need help  with Template Problems
@ 1997-05-10  4:00 Jean-Claude Magras
  1997-05-10  4:00 ` Jason Merrill
  1997-05-11  4:00 ` Krishnan Subramani
  0 siblings, 2 replies; 5+ messages in thread
From: Jean-Claude Magras @ 1997-05-10  4:00 UTC (permalink / raw)



This is a multi-part message in MIME format.

--------------32D221DF4ECF
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Greetings fellow C++ programmers,

I am trying to compile the attached source files NODE.C and NODE.h
but I get this insistent error before many others....
NODE.h:98: field `IPsocket' has incomplete type

This worked once and should work. By default its type should
be whatever type paramater is passed(default is int). This
is on a solaris2.5.1-sparc-sun. I also have a DIGITAL alphastation.
This is g++ 2.7.2.2 and libg++ 2.7.2.

It also does not seem to like explicit insubstantiation via
template<> class NetProtocol<TCPIPd>;
Does any vendor compiler support this? Sun? DIGITAL? What version?
What cost?


Thanks in advance,

J.C. Magras

-- 
Unix Software Engineer looking for C++/UNIX/Motif/Perl/Tk/Flex 
Software Engineering position **NOW**. Currently in Austin at
(512) 672-5778/magrasjc@texas.net. have Answering machine.

--------------32D221DF4ECF
Content-Type: text/html; charset=us-ascii; name="NODE.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="NODE.h"

<BASE HREF="/export/home0/magrasjc/source/jware/NODE.h">

#ifdef HTML
<HTML>
#endif // HTML
#ifndef _NODE_H
#define _NODE_H

#include <netinet/in.h>
#include <bool.h>
#include "security.h"

#include "jWare.h"

// streambuf.h , #209
class filname_ {
public:
   filname_::filname_();
   filname_ & filname_::operator= ( filname_ &that);     
   bool       filname_::operator==( filname_ &that);
   bool       filname_::operator!=( filname_ &that);
   bstring *FILEname_bstrP;  
   ifstream *a_istrmP;
   ofstream *a_ostrmP;
   modeDEV  *filemodeP;
} ;
//
// filname_ :default constructor
//
filname_::filname_ () {
    a_istrmP      =0;
    a_ostrmP      =0;
    FILEname_bstrP=0;
    filemodeP     =0;
}

//
// filname_ :assignment constructor
//
filname_ & filname_::operator=( filname_ &that) {
    this->a_istrmP        = that.a_istrmP;
    this->a_ostrmP        = that.a_ostrmP;
    this->FILEname_bstrP  = that.FILEname_bstrP;
    this->filemodeP       = that.filemodeP;
}

//
// filname_ :overload of equality test operator
//
bool filname_::operator==( filname_ &that) {
    return ( (  this->a_istrmP        == that.a_istrmP )  &&
             (  this->a_ostrmP        == that.a_ostrmP )  &&
             (  this->FILEname_bstrP  == that.FILEname_bstrP ) );
}

//
// filname_ :overload of inequality test operator
//
 bool filname_::operator!=( filname_ &that) {
    return !( ( this->a_istrmP         == that.a_istrmP )  &&
              (  this->a_ostrmP        == that.a_ostrmP )  &&
              (  this->FILEname_bstrP  == that.FILEname_bstrP ) );
}


// unified address class
class addrINFO {
public:
  struct sockaddr_in  TCPaddr;
  filname_     FILEaddr;
} ;



#ifdef DOCUMENTATION
#define _BO <b>
#define BO_ </b>
_BOKeywordsBO_: template
_BOAuthorBO_: magras
_BOBase NameBO_:NetProtocol
_BODerived NamesBO_: <TCPIPd>pTCPIP, <filname_t>fileNODE, <bstring>strNODE
_BOclass ParamaterBO_: [ipcT]Descriptor for the communications medium being used

Serves as the actual object through which the user communcaties with the other
party.

addrINFO should probably be a typedef for for each class type derived from this template.

_BOenumerationsBO_: jIsEOFvalid --true if this a data container not a stream?
                    jHitEOF     --false if we have read to the very end of the
                                  file or if this a stream type data source
#endif //DOCUMENTATION
#pragma interface "NODE.h"
template<typename U>
class NetProtocol
{
protected:
    
    bool   accepted;       // this is used by server type instances
    U  IPsocket;       // an actual instance of the IPC being used
    bstring *error_pbstr;  // used to record error messages
public:
    enum           {jIsEOFvalid,jHitEOF};  
    // addressing information--addrINFO should probably be a typedef for for each class type derived from this template 
    addrINFO  ouraddr;
    // default constructor
    NetProtocol<class U>::NetProtocol();  
    // copy constructor
    NetProtocol<class U>(NetProtocol<class U> &old) ;
    ~NetProtocol();      // destructor 

    // assignment operator
    U&     operator= (const U&);

    // sole test operator used by ordering mechanisms in STL container classes
    bool      operator< (const U& that);

    // here for our use
    bool      operator==(const U& that);

    // public access to server mode connection data
    bool      NetProtocol<U>::jProto_is_accepted();
    void      NetProtocol<class U>::jProto_set_accepted(bool ) ;

    // indicate an error on this connection -- invalidate this descriptor
    void      jProto_set_error_string(bstring& error_);
    //  check if socket descriptor is valid and has no errors on the connection
    bool      jProto_get_status();
    // return the error string
    bstring&  jProto_get_error(); 

    // access the native descriptor
    void      jProto_set_native( U );  
    U      jProto_get_native();

    // descriptor semantics control
    bool      jProto_iocntrl(unsigned int);
};


#endif


--------------32D221DF4ECF
Content-Type: text/plain; charset=us-ascii; name="NODE.C"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="NODE.C"

#pragma implementation "NODE.h"
#include "NODE.h"

#ifndef _NODE_C

    template<class U>
    U& NetProtocol<class U>::
    operator=(const U& that) {
        this->IPsocket    = that->IPsocket;
        this->error_pbstr = that->error_pbstr;
        this->accepted    = that->accepted;
        memcpy(&(that->ouraddr), &(this->ouraddr),sizeof(struct addrINFO));
    }

    // default constructor
    template<class U>
    NetProtocol<class U>::
    NetProtocol() {
        this->IPsocket=0;       // invalid descriptor
        this->error_pbstr=0;    // no error string
        this->accepted=false;   // this descriptor has not accepted a connection
    }

    //
    //  This definition necessary for container class definition
    //  This is the sole comparison operator used by the STL
    //  Equality check by a<b && b<a both proving false
    //  Not provided by the compiler.
    template<class U>
    bool NetProtocol<class U>::
      operator<(const U& that) {
        return (this->IPsocket < that->IPsocket);
    }

    // equality test between instances --NOT needed by STL
    template<class U>
    bool NetProtocol<class U>::
        operator==(const U& that) {
        return (this->IPsocket == that->IPsocket);
    }

    // copy constructor 
    template<class U>
    NetProtocol<class U>::
    NetProtocol(NetProtocol<class U> &old) {
        this->IPsocket    = old.IPsocket;   // should this be dup() ?
        this->error_pbstr = old.error_pbstr;
        this->accepted    = old.accepted;
    }

    // Default template destructor
    template<class U>
      NetProtocol<class U>::
     ~NetProtocol() {

        // handle an error string attachment
       if (error_pbstr)
           delete error_pbstr;
    }


    // start of user functions

    // test to see if this server connection has accepted a client's 
    // connection attempt
    template<U>
    bool NetProtocol<U>::
    jProto_is_accepted() { return accepted; }  // simply return the variable 4 now

    // record that this server endpoint has accepted a client connect attempt
    template<class U>
    void NetProtocol<class U>::
     jProto_set_accepted(bool state) 
           { accepted = state; }


    // set the error string when an error is detected with this descriptor
    template<U>
    void NetProtocol<class U>::
    jProto_set_error_string(bstring& error_) {
       error_pbstr=new bstring(error_); // make a copy of the bstring passed in
       this->IPsocket=0;                // invalidate descriptor
    }

    // set the native descriptor -- this will probably be 
    // moved to protected status
    template<U>
    void NetProtocol<class U>::
    jProto_set_native(U socketno) {
        this->IPsocket=socketno;
        
    }

    // return the native descriptor -- this will probably be 
    // moved to protected status
     template<class U>
    U NetProtocol<class U>::
    jProto_get_native() { return (T)IPsocket; };

    // return true if the descriptor is valid (nocalls to set_error_string())
    // against it
    template<class U>
    bool NetProtocol<class U>::jProto_get_status() {
        if (IPsocket==0)
           return false;
        else
           return true;
    }

    // define a default semantics for a derived class
    template<class U>
    bool NetProtocol<class U>::jProto_iocntrl(unsigned int opcode) {
        switch (opcode) {
         case jIsEOFvalid: return false;   // semantics of stream object
         case jHitEOF:     return false;
         default     :     return false;
        };
    }

    // return the error string if the descriptor is invalid
    // if descriptor is valid it returns a bstring of ""
    template<class U>
    bstring &NetProtocol<class U>::
     jProto_get_error() {
       bstring *dflt_pbstr;

       // check if descriptor is valid-- which could be anything...
       if (this->jProto_get_status()==false && this->error_pbstr !=NULL)
          return(*error_pbstr);
       else {
          dflt_pbstr=new bstring("");
          return *dflt_pbstr;
       }
    }
#define _NODE_C
#endif

--------------32D221DF4ECF--




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Need help  with Template Problems
  1997-05-10  4:00 Need help with Template Problems Jean-Claude Magras
@ 1997-05-10  4:00 ` Jason Merrill
  1997-05-11  4:00   ` Jean-Claude Magras
  1997-05-11  4:00 ` Krishnan Subramani
  1 sibling, 1 reply; 5+ messages in thread
From: Jason Merrill @ 1997-05-10  4:00 UTC (permalink / raw)



>>>>> Jean-Claude Magras <magrasjc@texas.net> writes:

> It also does not seem to like explicit insubstantiation via
> template<> class NetProtocol<TCPIPd>;

That's not the syntax.  The syntax is

  template class NetProtocol<TCPIPd>;

which is supported by g++.  See 

  http://www.cygnus.com/misc/wp/dec96pub/template.html#temp.explicit

Jason



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Need help  with Template Problems
  1997-05-10  4:00 ` Jason Merrill
@ 1997-05-11  4:00   ` Jean-Claude Magras
  1997-05-11  4:00     ` Jean-Claude Magras
  0 siblings, 1 reply; 5+ messages in thread
From: Jean-Claude Magras @ 1997-05-11  4:00 UTC (permalink / raw)



This is a multi-part message in MIME format.

--------------5A995B113C6C
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Jason Merrill wrote:
> 
> >>>>> Jean-Claude Magras <magrasjc@texas.net> writes:
> 
> > It also does not seem to like explicit insubstantiation via
> > template<> class NetProtocol<TCPIPd>;
> 
> That's not the syntax.  The syntax is
> 
>   template class NetProtocol<TCPIPd>;
> which is supported by g++.  See
This is not supported based on the following errors when I tried
to compile the program from the attached files...

NODE.h:94: sorry, not implemented: aggregate template parameter types
In file included from NODE.C:2,
                 from testT.C:3:
NODE.h:98: declaration of template `template <class U> class
NetProtocol'
NODE.h:94: conflicts with previous declaration `template <void const
{anon}> class NetProtocol'
In file included from testT.C:3:
NODE.h:102: field `IPsocket' has incomplete type
NODE.h:102:   in instantiation of template `NetProtocol<U>'
NODE.h:109: cannot declare member function `NetProtocol<U>::NetProtocol'
within `NetProtocol<int>'
NODE.h:124: cannot declare member function
`NetProtocol<U>::jProto_is_accepted' within `NetProtocol<int>'
NODE.h:125: cannot declare member function
`NetProtocol<U>::jProto_set_accepted' within `NetProtocol<int>'
testT.C:11: inconsistent return types for method `jProto_get_native' in
class `NetProtocol<int>'
testT.C:11: template for method `jProto_set_native' doesn't match any in
class `NetProtocol<int>'
NODE.C:89: in attempt to instantiate `template <class U>
NetProtocol<...>::jProto_set_native(U)' declared at this point in file
testT.C:11: method `jProto_set_accepted' not found in class
`NetProtocol<int>'
NODE.C:74: in attempt to instantiate `template <class U>
NetProtocol<...>::jProto_set_accepted(bool)' declared at this point in
file
testT.C:11: method `jProto_is_accepted' not found in class
`NetProtocol<int>'
NODE.C:68: in attempt to instantiate `template <class U>
NetProtocol<...>::jProto_is_accepted()' declared at this point in file
testT.C:11: template for method `NetProtocol' doesn't match any in class
`NetProtocol<int>'
NODE.C:45: in attempt to instantiate `template <class U>
NetProtocol<...>::NetProtocol(NetProtocol<U> &)' declared at this point
in file
testT.C:11: template for method `operator ==' doesn't match any in class
`NetProtocol<int>'
NODE.C:38: in attempt to instantiate `template <class U>
NetProtocol<...>::operator ==(U &)' declared at this point in file
testT.C:11: template for method `operator <' doesn't match any in class
`NetProtocol<int>'
NODE.C:31: in attempt to instantiate `template <class U>
NetProtocol<...>::operator <(U &)' declared at this point in file
testT.C:11: template for method `NetProtocol' which has default
implementation in class `NetProtocol<int>'
NODE.C:18: in attempt to instantiate `template <class U>
NetProtocol<...>::NetProtocol()' declared at this point in file
testT.C:11: template for method `operator =' doesn't match any in class
`NetProtocol<int>'
NODE.C:8: in attempt to instantiate `template <class U>
NetProtocol<...>::operator =(U &)' declared at this point in file
NODE.C: In method `class U NetProtocol<int>::jProto_get_native()':
NODE.C:98: return-type `U' is an incomplete type
NODE.C:98: `T' undeclared (first use this function)
NODE.C:98: (Each undeclared identifier is reported only once
NODE.C:98: for each function it appears in.)
NODE.C:98: parse error before `;'
testT.C: At top level:
testT.C:11: template for method `jProto_set_native' doesn't match any in
class `NetProtocol<int>'
NODE.C:89: in attempt to instantiate `template <class U>
NetProtocol<...>::jProto_set_native(U)' declared at this point in file
testT.C:11: method `jProto_set_accepted' not found in class
`NetProtocol<int>'
NODE.C:74: in attempt to instantiate `template <class U>
NetProtocol<...>::jProto_set_accepted(bool)' declared at this point in
file
testT.C:11: method `jProto_is_accepted' not found in class
`NetProtocol<int>'
NODE.C:68: in attempt to instantiate `template <class U>
NetProtocol<...>::jProto_is_accepted()' declared at this point in file
testT.C:11: template for method `NetProtocol' doesn't match any in class
`NetProtocol<int>'
NODE.C:45: in attempt to instantiate `template <class U>
NetProtocol<...>::NetProtocol(NetProtocol<U> &)' declared at this point
in file
testT.C:11: template for method `operator ==' doesn't match any in class
`NetProtocol<int>'
NODE.C:38: in attempt to instantiate `template <class U>
NetProtocol<...>::operator ==(U &)' declared at this point in file
testT.C:11: template for method `operator <' doesn't match any in class
`NetProtocol<int>'
NODE.C:31: in attempt to instantiate `template <class U>
NetProtocol<...>::operator <(U &)' declared at this point in file
testT.C:11: template for method `NetProtocol' which has default
implementation in class `NetProtocol<int>'
NODE.C:18: in attempt to instantiate `template <class U>
NetProtocol<...>::NetProtocol()' declared at this point in file
testT.C:11: template for method `operator =' doesn't match any in class
`NetProtocol<int>'
NODE.C:8: in attempt to instantiate `template <class U>
NetProtocol<...>::operator =(U &)' declared at this point in file

>   http://www.cygnus.com/misc/wp/dec96pub/template.html#temp.explicit
> 
> Jason
This is using g++ 2.7.2.1 on Solaris2.5.1-sparc and libg++ 2.7.2
Any help Appreciated...this code once worked (send diffs will
post followup with my lessons on templates, typedefs, etc.
What is the relationship between templates and typedefs?

Suggestions for books (not STL!) on template use appreciated.

Thanks in advance,

J.C. Magras
-- 
Why are the Israelis invoking the death penalty for an Israeli
selling land to a Palestinian?  (This according to Editorial of NY
Times--available on Yahoo)
Unix Software Engineer looking for C++/UNIX/Motif/Perl/Tk/Flex 
Software Engineering position **NOW**. Currently in Austin at
(512) 672-5778/magrasjc@texas.net. have Answering machine.

--------------5A995B113C6C
Content-Type: text/plain; charset=us-ascii; name="testT.C"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="testT.C"

#pragma implementation "NODE.C"

#include "NODE.C"


main() {

NetProtocol<int>   n1;

}

--------------5A995B113C6C
Content-Type: text/plain; charset=us-ascii; name="NODE.C"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="NODE.C"


#include "NODE.h"

#ifndef _NODE_C
template class NetProtocol<int> ;
    template<typename U>
    U& NetProtocol<U>::
    operator=(const U& that) {
        this->IPsocket    = that->IPsocket;
        this->error_pbstr = that->error_pbstr;
        this->accepted    = that->accepted;
        memcpy(&(that->ouraddr), &(this->ouraddr),sizeof(struct addrINFO));
    }

    // default constructor
    template<typename U>
    NetProtocol< U>::
    NetProtocol() {
        this->IPsocket=0;       // invalid descriptor
        this->error_pbstr=0;    // no error string
        this->accepted=false;   // this descriptor has not accepted a connection
    }

    //
    //  This definition necessary for container class definition
    //  This is the sole comparison operator used by the STL
    //  Equality check by a<b && b<a both proving false
    //  Not provided by the compiler.
    template<typename U>
    bool NetProtocol<U>::
      operator<(const U& that) {
        return (this->IPsocket < that->IPsocket);
    }

    // equality test between instances --NOT needed by STL
    template<typename U>
    bool NetProtocol<U>::
        operator==(const U& that) {
        return (this->IPsocket == that->IPsocket);
    }

    // copy constructor 
    template<typename U>
    NetProtocol<U>::
    NetProtocol(NetProtocol<class U> &old) {
        this->IPsocket    = old.IPsocket;   // should this be dup() ?
        this->error_pbstr = old.error_pbstr;
        this->accepted    = old.accepted;
    }

    // Default template destructor
    template<typename U>
      NetProtocol<U>::
     ~NetProtocol() {

        // handle an error string attachment
       if (error_pbstr)
           delete error_pbstr;
    }


    // start of user functions

    // test to see if this server connection has accepted a client's 
    // connection attempt
    template<typename U>
    bool NetProtocol<U>::
    jProto_is_accepted() { return accepted; }  // simply return the variable 4 now

    // record that this server endpoint has accepted a client connect attempt
    template<typename U>
    void NetProtocol<U>::
     jProto_set_accepted(bool state) 
           { accepted = state; }


    // set the error string when an error is detected with this descriptor
    template<typename U>
    void NetProtocol< U>::
    jProto_set_error_string(bstring& error_) {
       error_pbstr=new bstring(error_); // make a copy of the bstring passed in
       this->IPsocket=0;                // invalidate descriptor
    }

    // set the native descriptor -- this will probably be 
    // moved to protected status
    template<typename U>
    void NetProtocol< U>::
    jProto_set_native(U socketno) {
        this->IPsocket=socketno;
        
    }

    // return the native descriptor -- this will probably be 
    // moved to protected status
     template<typename U>
    U NetProtocol< U>::
    jProto_get_native() { return (T)IPsocket; };

    // return true if the descriptor is valid (nocalls to set_error_string())
    // against it
    template<typename U>
    bool NetProtocol< U>::jProto_get_status() {
        if (IPsocket==0)
           return false;
        else
           return true;
    }

    // define a default semantics for a derived class
    template<typename U>
    bool NetProtocol<U>::jProto_iocntrl(unsigned int opcode) {
        switch (opcode) {
         case jIsEOFvalid: return false;   // semantics of stream object
         case jHitEOF:     return false;
         default     :     return false;
        };
    }

    // return the error string if the descriptor is invalid
    // if descriptor is valid it returns a bstring of ""
    template<typename U>
    bstring &NetProtocol<U>::
     jProto_get_error() {
       bstring *dflt_pbstr;

       // check if descriptor is valid-- which could be anything...
       if (this->jProto_get_status()==false && this->error_pbstr !=NULL)
          return(*error_pbstr);
       else {
          dflt_pbstr=new bstring("");
          return *dflt_pbstr;
       }
    }


#define _NODE_C
#endif

--------------5A995B113C6C
Content-Type: text/html; charset=us-ascii; name="NODE.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="NODE.h"

<BASE HREF="/export/home0/magrasjc/source/jware/NODE.h">

#ifdef HTML
<HTML>
#endif // HTML
#ifndef _NODE_H
#define _NODE_H

#include <netinet/in.h>
#include <bool.h>
#include "security.h"

#include "jWare.h"

// streambuf.h , #209
class filname_ {
public:
   filname_::filname_();
   filname_ & filname_::operator= ( filname_ &that);     
   bool       filname_::operator==( filname_ &that);
   bool       filname_::operator!=( filname_ &that);
   bstring *FILEname_bstrP;  
   ifstream *a_istrmP;
   ofstream *a_ostrmP;
   modeDEV  *filemodeP;
} ;
//
// filname_ :default constructor
//
filname_::filname_ () {
    a_istrmP      =0;
    a_ostrmP      =0;
    FILEname_bstrP=0;
    filemodeP     =0;
}

//
// filname_ :assignment constructor
//
filname_ & filname_::operator=( filname_ &that) {
    this->a_istrmP        = that.a_istrmP;
    this->a_ostrmP        = that.a_ostrmP;
    this->FILEname_bstrP  = that.FILEname_bstrP;
    this->filemodeP       = that.filemodeP;
}

//
// filname_ :overload of equality test operator
//
bool filname_::operator==( filname_ &that) {
    return ( (  this->a_istrmP        == that.a_istrmP )  &&
             (  this->a_ostrmP        == that.a_ostrmP )  &&
             (  this->FILEname_bstrP  == that.FILEname_bstrP ) );
}

//
// filname_ :overload of inequality test operator
//
 bool filname_::operator!=( filname_ &that) {
    return !( ( this->a_istrmP         == that.a_istrmP )  &&
              (  this->a_ostrmP        == that.a_ostrmP )  &&
              (  this->FILEname_bstrP  == that.FILEname_bstrP ) );
}


// unified address class
class addrINFO {
public:
  struct sockaddr_in  TCPaddr;
  filname_     FILEaddr;
} ;



#ifdef DOCUMENTATION
#define _BO <b>
#define BO_ </b>
_BOKeywordsBO_: template
_BOAuthorBO_: magras
_BOBase NameBO_:NetProtocol
_BODerived NamesBO_: <TCPIPd>pTCPIP, <filname_t>fileNODE, <bstring>strNODE
_BOclass ParamaterBO_: [ipcT]Descriptor for the communications medium being used

Serves as the actual object through which the user communcaties with the other
party.

addrINFO should probably be a typedef for for each class type derived from this template.

_BOenumerationsBO_: jIsEOFvalid --true if this a data container not a stream?
                    jHitEOF     --false if we have read to the very end of the
                                  file or if this a stream type data source
#endif //DOCUMENTATION
#pragma interface "NODE.h"
typedef  struct  { int IPsocket; } TCPIPd;

template<TCPIPd> class NetProtocol;

template<typename U>
class NetProtocol
{
protected:
    
    bool   accepted;       // this is used by server type instances
    U  IPsocket;       // an actual instance of the IPC being used
    bstring *error_pbstr;  // used to record error messages
public:
    enum           {jIsEOFvalid,jHitEOF};  
    // addressing information--addrINFO should probably be a typedef for for each class type derived from this template 
    addrINFO  ouraddr;
    // default constructor
    NetProtocol<class U>::NetProtocol();  
    // copy constructor
    NetProtocol<class U>(NetProtocol<class U> &old) ;
    ~NetProtocol();      // destructor 

    // assignment operator
    U&     operator= (const U&);

    // sole test operator used by ordering mechanisms in STL container classes
    bool      operator< (const U& that);

    // here for our use
    bool      operator==(const U& that);

    // public access to server mode connection data
    bool      NetProtocol<U>::jProto_is_accepted();
    void      NetProtocol<class U>::jProto_set_accepted(bool ) ;

    // indicate an error on this connection -- invalidate this descriptor
    void      jProto_set_error_string(bstring& error_);
    //  check if socket descriptor is valid and has no errors on the connection
    bool      jProto_get_status();
    // return the error string
    bstring&  jProto_get_error(); 

    // access the native descriptor
    void      jProto_set_native( U );  
    U      jProto_get_native();

    // descriptor semantics control
    bool      jProto_iocntrl(unsigned int);
};


#endif


--------------5A995B113C6C--




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Need help  with Template Problems
  1997-05-11  4:00   ` Jean-Claude Magras
@ 1997-05-11  4:00     ` Jean-Claude Magras
  0 siblings, 0 replies; 5+ messages in thread
From: Jean-Claude Magras @ 1997-05-11  4:00 UTC (permalink / raw)



This is a multi-part message in MIME format.

--------------2E266F0C4459
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Greetings,

I apologize about the problems with the files sent before.
Solaris2.5.1-sparc-2.7.2.1 and libg++ 2.7.2

Again.
Any help appreciated. Book references,code diffs,etc. This code once
worked but After I returned to it from a hiatus it didnt. The previous
post enumerates the errors received.

Sincerely,

J.C. Magras

-- 
Why are the Israelis invoking the death penalty for an Israeli
selling land to a Palestinian?  (This according to Editorial of NY
>Times--available on Yahoo)
Unix Software Engineer looking for C++/UNIX/Motif/Perl/Tk/Flex 
Software Engineering position **NOW**. Currently in Austin at
(512) 672-5778/magrasjc@texas.net. have Answering machine.

--------------2E266F0C4459
Content-Type: text/plain; charset=us-ascii; name="NODE.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="NODE.h"

#ifndef _NODE_H
#define _NODE_H

#include <netinet/in.h>
#include <bool.h>
#include "security.h"

#include "jWare.h"

// streambuf.h , #209
class filname_ {
public:
   filname_::filname_();
   filname_ & filname_::operator= ( filname_ &that);     
   bool       filname_::operator==( filname_ &that);
   bool       filname_::operator!=( filname_ &that);
   bstring *FILEname_bstrP;  
   ifstream *a_istrmP;
   ofstream *a_ostrmP;
   modeDEV  *filemodeP;
} ;
//
// filname_ :default constructor
//
filname_::filname_ () {
    a_istrmP      =0;
    a_ostrmP      =0;
    FILEname_bstrP=0;
    filemodeP     =0;
}

//
// filname_ :assignment constructor
//
filname_ & filname_::operator=( filname_ &that) {
    this->a_istrmP        = that.a_istrmP;
    this->a_ostrmP        = that.a_ostrmP;
    this->FILEname_bstrP  = that.FILEname_bstrP;
    this->filemodeP       = that.filemodeP;
}

//
// filname_ :overload of equality test operator
//
bool filname_::operator==( filname_ &that) {
    return ( (  this->a_istrmP        == that.a_istrmP )  &&
             (  this->a_ostrmP        == that.a_ostrmP )  &&
             (  this->FILEname_bstrP  == that.FILEname_bstrP ) );
}

//
// filname_ :overload of inequality test operator
//
 bool filname_::operator!=( filname_ &that) {
    return !( ( this->a_istrmP         == that.a_istrmP )  &&
              (  this->a_ostrmP        == that.a_ostrmP )  &&
              (  this->FILEname_bstrP  == that.FILEname_bstrP ) );
}


// unified address class
class addrINFO {
public:
  struct sockaddr_in  TCPaddr;
  filname_     FILEaddr;
} ;



#ifdef DOCUMENTATION
#define _BO <b>
#define BO_ </b>
_BOKeywordsBO_: template
_BOAuthorBO_: magras
_BOBase NameBO_:NetProtocol
_BODerived NamesBO_: <TCPIPd>pTCPIP, <filname_t>fileNODE, <bstring>strNODE
_BOclass ParamaterBO_: [ipcT]Descriptor for the communications medium being used

Serves as the actual object through which the user communcaties with the other
party.

addrINFO should probably be a typedef for for each class type derived from this template.

_BOenumerationsBO_: jIsEOFvalid --true if this a data container not a stream?
                    jHitEOF     --false if we have read to the very end of the
                                  file or if this a stream type data source
#endif //DOCUMENTATION
#pragma interface "NODE.h"
typedef  struct  { int IPsocket; } TCPIPd;

template<TCPIPd> class NetProtocol;

template<class U>
class NetProtocol
{
protected:
    
    bool   accepted;       // this is used by server type instances
    U  IPsocket;       // an actual instance of the IPC being used
    bstring *error_pbstr;  // used to record error messages
public:
    enum           {jIsEOFvalid,jHitEOF};  
    // addressing information--addrINFO should probably be a typedef for for each class type derived from this template 
    addrINFO  ouraddr;
    // default constructor
    NetProtocol<class U>::NetProtocol();  
    // copy constructor
    NetProtocol<class U>(NetProtocol<class U> &old) ;
    ~NetProtocol();      // destructor 

    // assignment operator
    NetProtocol<U>&     operator= (const NetProtocol<U>&);

    // sole test operator used by ordering mechanisms in STL container classes
    bool      operator< (const NetProtocol<U>& that);

    // here for our use
    bool      operator==(const U& that);

    // public access to server mode connection data
    bool      NetProtocol<U>::jProto_is_accepted();
    void      NetProtocol<U>::jProto_set_accepted(bool ) ;

    // indicate an error on this connection -- invalidate this descriptor
    void      jProto_set_error_string(bstring& error_);
    //  check if socket descriptor is valid and has no errors on the connection
    bool      jProto_get_status();
    // return the error string
    bstring&  jProto_get_error(); 

    // access the native descriptor
    void      jProto_set_native( U );  
    U      jProto_get_native();

    // descriptor semantics control
    bool      jProto_iocntrl(unsigned int);
};


#endif


--------------2E266F0C4459
Content-Type: text/plain; charset=us-ascii; name="NODE.C"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="NODE.C"


#include "NODE.h"

#ifndef _NODE_C
template class NetProtocol<int> ;
    template<typename U>
    U& NetProtocol<U>::
    operator=(const U& that) {
        this->IPsocket    = that->IPsocket;
        this->error_pbstr = that->error_pbstr;
        this->accepted    = that->accepted;
        memcpy(&(that->ouraddr), &(this->ouraddr),sizeof(struct addrINFO));
    }

    // default constructor
    template<typename U>
    NetProtocol< U>::
    NetProtocol() {
        this->IPsocket=0;       // invalid descriptor
        this->error_pbstr=0;    // no error string
        this->accepted=false;   // this descriptor has not accepted a connection
    }

    //
    //  This definition necessary for container class definition
    //  This is the sole comparison operator used by the STL
    //  Equality check by a<b && b<a both proving false
    //  Not provided by the compiler.
    template<typename U>
    bool NetProtocol<U>::
      operator<(const U& that) {
        return (this->IPsocket < that->IPsocket);
    }

    // equality test between instances --NOT needed by STL
    template<typename U>
    bool NetProtocol<U>::
        operator==(const U& that) {
        return (this->IPsocket == that->IPsocket);
    }

    // copy constructor 
    template<typename U>
    NetProtocol<U>::
    NetProtocol(NetProtocol<class U> &old) {
        this->IPsocket    = old.IPsocket;   // should this be dup() ?
        this->error_pbstr = old.error_pbstr;
        this->accepted    = old.accepted;
    }

    // Default template destructor
    template<typename U>
      NetProtocol<U>::
     ~NetProtocol() {

        // handle an error string attachment
       if (error_pbstr)
           delete error_pbstr;
    }


    // start of user functions

    // test to see if this server connection has accepted a client's 
    // connection attempt
    template<typename U>
    bool NetProtocol<U>::
    jProto_is_accepted() { return accepted; }  // simply return the variable 4 now

    // record that this server endpoint has accepted a client connect attempt
    template<typename U>
    void NetProtocol<U>::
     jProto_set_accepted(bool state) 
           { accepted = state; }


    // set the error string when an error is detected with this descriptor
    template<typename U>
    void NetProtocol< U>::
    jProto_set_error_string(bstring& error_) {
       error_pbstr=new bstring(error_); // make a copy of the bstring passed in
       this->IPsocket=0;                // invalidate descriptor
    }

    // set the native descriptor -- this will probably be 
    // moved to protected status
    template<typename U>
    void NetProtocol< U>::
    jProto_set_native(U socketno) {
        this->IPsocket=socketno;
        
    }

    // return the native descriptor -- this will probably be 
    // moved to protected status
     template<typename U>
    U NetProtocol< U>::
    jProto_get_native() { return (T)IPsocket; };

    // return true if the descriptor is valid (nocalls to set_error_string())
    // against it
    template<typename U>
    bool NetProtocol< U>::jProto_get_status() {
        if (IPsocket==0)
           return false;
        else
           return true;
    }

    // define a default semantics for a derived class
    template<typename U>
    bool NetProtocol<U>::jProto_iocntrl(unsigned int opcode) {
        switch (opcode) {
         case jIsEOFvalid: return false;   // semantics of stream object
         case jHitEOF:     return false;
         default     :     return false;
        };
    }

    // return the error string if the descriptor is invalid
    // if descriptor is valid it returns a bstring of ""
    template<typename U>
    bstring &NetProtocol<U>::
     jProto_get_error() {
       bstring *dflt_pbstr;

       // check if descriptor is valid-- which could be anything...
       if (this->jProto_get_status()==false && this->error_pbstr !=NULL)
          return(*error_pbstr);
       else {
          dflt_pbstr=new bstring("");
          return *dflt_pbstr;
       }
    }


#define _NODE_C
#endif

--------------2E266F0C4459
Content-Type: text/plain; charset=us-ascii; name="testT.C"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="testT.C"

#pragma implementation "NODE.C"

#include "NODE.C"


main() {

NetProtocol<int>   n1;

}

--------------2E266F0C4459--




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Need help  with Template Problems
  1997-05-10  4:00 Need help with Template Problems Jean-Claude Magras
  1997-05-10  4:00 ` Jason Merrill
@ 1997-05-11  4:00 ` Krishnan Subramani
  1 sibling, 0 replies; 5+ messages in thread
From: Krishnan Subramani @ 1997-05-11  4:00 UTC (permalink / raw)



Jean-Claude Magras wrote:
> but I get this insistent error before many others....
> NODE.h:98: field `IPsocket' has incomplete type
> 

This is probably because you have not given a forward declaration of U,
the type of IPsocket.  This is not sufficient since you are trying to
instantiate an object IPsocket, of type U.  The compiler MUST know how
much memory it has to allocate for the object, the objects in the class
U (if any), etc.  You have to include the class definition of U before
you can instantiate any object of type U.

Hope this helps.

-- 
Krishnan Subramani		  Phone  : 513-961-7812
375, Probasco Street #2		  E-mail : skrish@ececs.uc.edu
Cincinnati, Ohio 45220		  URL    : http://www.ececs.uc.edu/~skrish



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1997-05-11  4:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-05-10  4:00 Need help with Template Problems Jean-Claude Magras
1997-05-10  4:00 ` Jason Merrill
1997-05-11  4:00   ` Jean-Claude Magras
1997-05-11  4:00     ` Jean-Claude Magras
1997-05-11  4:00 ` Krishnan Subramani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox