compiler/cpp/src/generate/t_hs_generator.cc
/**
 * Generates a struct definition for a thrift data type.
 *
 * @param tstruct The struct definition
 */
Generates a struct definition for a thrift data type.
@param tstruct The struct definition
Generates a struct definition for a thrift data type . @param tstruct The struct definition
void t_hs_generator::generate_hs_struct_definition(ofstream& out,
                                                   t_struct* tstruct,
                                                   bool is_exception,
                                                   bool helper) {
  (void) helper;
  string tname = type_name(tstruct);
  string name = tstruct->get_name();
  const vector<t_field*>& members = tstruct->get_members();
  vector<t_field*>::const_iterator m_iter;
  indent(out) << "data " << tname << " = " << tname;
  if (members.size() > 0) {
    out << "{";
    bool first = true;
    for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
      string mname = (*m_iter)->get_name();
      out << (first ? "" : ",");
      out << "f_" << tname << "_" << mname << " :: Maybe " << render_hs_type((*m_iter)->get_type(), true);
      first = false;
    }
    out << "}";
  }
  out << " deriving (Show,Eq,Typeable)" << endl;
  if (is_exception)
    out << "instance Exception " << tname << endl;
  indent(out) << "instance Hashable " << tname << " where" << endl;
  indent_up();
  indent(out) << "hashWithSalt salt record = salt";
  for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
    string mname = (*m_iter)->get_name();
    indent(out) << " `hashWithSalt` " << "f_" << tname << "_" << mname << " record";
  }
  indent(out) << endl;
  indent_down();
  generate_hs_struct_writer(out, tstruct);
  generate_hs_struct_reader(out, tstruct);
}
void t_hs_generator :: generate_hs_struct_definition ( ofstream & out , t_struct * tstruct , bool is_exception , bool helper ) { ( void ) helper ; string tname = type_name ( tstruct ) ; string name = tstruct -> get_name ( ) ; const vector < t_field * > & members = tstruct -> get_members ( ) ; vector < t_field * > :: const_iterator m_iter ; indent ( out ) << " " << tname << " " << tname ; if ( members . size ( ) > 0 ) { out << " " ; bool first = true ; for ( m_iter = members . begin ( ) ; m_iter != members . end ( ) ; ++ m_iter ) { string mname = ( * m_iter ) -> get_name ( ) ; out << ( first ? " " : " " ) ; out << " " << tname << " " << mname << " " << render_hs_type ( ( * m_iter ) -> get_type ( ) , true ) ; first = false ; } out << " " ; } out << " " << endl ; if ( is_exception ) out << " " << tname << endl ; indent ( out ) << " " << tname << " " << endl ; indent_up ( ) ; indent ( out ) << " " ; for ( m_iter = members . begin ( ) ; m_iter != members . end ( ) ; ++ m_iter ) { string mname = ( * m_iter ) -> get_name ( ) ; indent ( out ) << " " << " " << tname << " " << mname << " " ; } indent ( out ) << endl ; indent_down ( ) ; generate_hs_struct_writer ( out , tstruct ) ; generate_hs_struct_reader ( out , tstruct ) ; }
Generates a struct definition for a thrift data type.
Generates a struct definition for a thrift data type .