示例#1
0
        private void WriteSourceFile(CppWriter cppWriter)
        {
            LangStreamWrapper stream = cppWriter.SourceStream;

            foreach (ClassFunction classFunc in _functions)
            {
                stream.NewLine();

                CppWriter.WriteFunctionString(stream, classFunc.functionObj, CppWriter.CreateNamespaceString(_className, _namespaceName));
                stream.NewLine();
                stream.WriteLine("{");

                stream.IncreaseTab();
                classFunc.functionObj.ContentDelegate?.Invoke(stream);
                stream.DecreaseTab();

                stream.WriteLine("}");
            }
        }
示例#2
0
        private void WriteHeaderFile(CppWriter cppWriter)
        {
            LangStreamWrapper stream = cppWriter.HeaderStream;

            var publicMembers    = new List <WriteToStream>();
            var protectedMembers = new List <WriteToStream>();
            var privateMembers   = new List <WriteToStream>();

            Action <AccessModifier, WriteToStream> EvaluateAccessModifier = (accessModifier, writeDelegate) =>
            {
                switch (accessModifier)
                {
                case AccessModifier.PRIVATE:
                    privateMembers.Add(writeDelegate);
                    break;

                case AccessModifier.PROTECTED:
                    protectedMembers.Add(writeDelegate);
                    break;

                default:     //ACCESS_PUBLIC
                    publicMembers.Add(writeDelegate);
                    break;
                }
            };

            //init member string
            {
                foreach (InnerClass innerClass in _innerClasses)
                {
                    EvaluateAccessModifier(innerClass.accessModifier, () =>
                    {
                        innerClass.classBuilder.WriteClass(cppWriter);
                        stream.NewLine();
                    });
                }

                foreach (ClassFunction classFunc in _functions)
                {
                    EvaluateAccessModifier(classFunc.accessModifier, () =>
                    {
                        CppWriter.WriteFunctionString(stream, classFunc.functionObj);
                        stream.WriteLine(";");
                    });
                }

                foreach (ClassMemeber classMemeber in _members)
                {
                    EvaluateAccessModifier(classMemeber.accessModifier, () =>
                    {
                        CppWriter.WriteVariableString(stream, classMemeber.variableObj);
                        stream.WriteLine(";");
                    });
                }
            }

            //write the file
            {
                stream.WriteLine("class " + _className);
                stream.WriteLine("{");
                {
                    var memberTuples = new List <Tuple <string, List <WriteToStream> > >();
                    memberTuples.Add(new Tuple <string, List <WriteToStream> >("public", publicMembers));
                    memberTuples.Add(new Tuple <string, List <WriteToStream> >("protected", protectedMembers));
                    memberTuples.Add(new Tuple <string, List <WriteToStream> >("private", privateMembers));

                    foreach (Tuple <string, List <WriteToStream> > memberTuple in memberTuples)
                    {
                        List <WriteToStream> writeMemberDelegates = memberTuple.Item2;
                        if (writeMemberDelegates.Count > 0)
                        {
                            stream.WriteLine(memberTuple.Item1 + ":");

                            stream.IncreaseTab();
                            foreach (WriteToStream writeMemberDelegate in writeMemberDelegates)
                            {
                                writeMemberDelegate.Invoke();
                            }
                            stream.DecreaseTab();

                            stream.NewLine();
                        }
                    }
                }
                stream.WriteLine("};");
            }
        }