Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  // $Id$
  //
  // Narya library - tools for developing networked games
  // Copyright (C) 2002-2012 Three Rings Design, Inc., All Rights Reserved
  // http://code.google.com/p/narya/
  //
  // This library is free software; you can redistribute it and/or modify it
  // under the terms of the GNU Lesser General Public License as published
 // by the Free Software Foundation; either version 2.1 of the License, or
 // (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 package com.threerings.presents.tools.cpp;
 
 import static com.threerings.presents.tools.cpp.CPPUtil.makePath;
 
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import java.io.File;
 
 
 
 public class GenCPPReceiverTask extends GenReceiverTask
 {
     public void setCpproot (File asroot)
     {
          = asroot;
     }
 
     @Override
     protected void generateDecoder (Class<?> receiverFile sourceString rnameString rpackage,
         List<ServiceMethodmethodsImportSet importsString rcode)
         throws Exception
     {
         String dname = rname.replace("Receiver""Decoder");
 
         Map<StringObjectctx = Maps.newHashMap();
         List<Stringnamespaces = CPPUtil.makeNamespaces(receiver);
         ctx.put("receiverName"rname);
         ctx.put("decoderName"dname);
         ctx.put("namespaces"namespaces);
         ctx.put("namespace", CPPUtil.makeNamespace(receiver));
         ctx.put("package"rpackage);
         ctx.put("methods", MethodDescriptor.from(methods));
         ctx.put("receiverCode"rcode);
         ctx.put("argbuilder"new CPPArgBuilder());
 
         writeTemplate(makePath(namespacesdname".h"), ctx);
 
         Set<StringreceiverHeaderIncludes = Sets.newTreeSet();
         Set<StringdecoderImplIncludes = Sets.newTreeSet();
         for (ServiceMethod meth : methods) {
             for (Type type : meth.method.getGenericParameterTypes()) {
                 CPPType cppType = new CPPType(type);
                 if (cppType.primitive) {
                     decoderImplIncludes.add("presents/box/Boxed" + cppType.interpreter + ".h");
                 }
                 while (cppType != null) {
                     if (cppType.representationImport != null) {
                         receiverHeaderIncludes.add(cppType.representationImport);
                     }
                     cppType = cppType.dependent;
                 }
             }
         }
 
         ctx.put("includes"decoderImplIncludes);
         writeTemplate(makePath(namespacesdname".cpp"), ctx);
         ctx.put("includes"receiverHeaderIncludes);
         writeTemplate(makePath(namespacesrname".h"), ctx);
 
         super.generateDecoder(receiversourcernamerpackagemethodsimportsrcode);
     }
 
     protected File _cpproot;
 
     protected static final String RECEIVER_HEADER_TMPL =
         "com/threerings/presents/tools/cpp/receiver_h.mustache";
     protected static final String DECODER_HEADER_TMPL =
         "com/threerings/presents/tools/cpp/decoder_h.mustache";
     protected static final String DECODER_CPP_TMPL =
         "com/threerings/presents/tools/cpp/decoder_cpp.mustache";
New to GrepCode? Check out our FAQ X