Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-2304

Move client assignments from construtor in method

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • 0.9.1
    • 0.9.2
    • C++ - Compiler
    • None

    Description

      The current generated client code in C++ look like this
      (namespace removed, for better formatting):

      class MyServiceClient : virtual public MyServiceIf {
       public:
        MyServiceClient(shared_ptr< TProtocol> prot) :
          piprot_(prot),
          poprot_(prot) {
          iprot_ = prot.get();
          oprot_ = prot.get();
        }
       [...]
      

      The member variables are assigned in the constructor.
      The patch puts the assignment into its own method:

      class MyServiceClient : virtual public MyServiceIf {
       public:
        MyServiceClient(shared_ptr< TProtocol> prot) {
          setProtocol(prot);
        }
        [..]
      private:
        void setProtocol(shared_ptr< TProtocol> prot) {
           setProtocol(prot,prot);
        }
       void setProtocol(shared<:TProtocol> iprot,shared_ptr<TProtocol> oprot) {
          piprot_=iprot;
          poprot_=oprot;
          iprot_ = iprot.get();
          oprot_ = oprot.get();
        }
      

      This allows to change the TProtocol instance, after the Client creation. (With removing the private field or using a virtual method in a Service base class)

      Attachments

        Activity

          People

            roger Roger Meier
            mvogt1 Martin Vogt
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: