Пример #1
0
        // Use the fragment dirctly
        static void CodeTest()
        {
            FragmentManager cpp_writer = new FragmentManager();
            cpp_writer.AddChild( new Description() );

            DefineGuards define_guards = new DefineGuards();
            cpp_writer.AddChild( define_guards );

            Headers headers = new Headers();
            cpp_writer.AddChildTo( define_guards , headers , 0 );
            headers.AddHeader( "iostrem" ,false);
            headers.AddHeader( "<fstream>" ,false);
            headers.AddHeader( "json.hpp" , true );

            NameSpace nmspace = new NameSpace();
            cpp_writer.AddChildTo( define_guards , nmspace , 0 );
            nmspace.AddNameSpace( "demo" );

            Class cls = new Class();
            cpp_writer.AddChildTo( nmspace , cls , 1 );
            cls.AddClass( "FirstClass" ,"ParentClass");
            cls.AddAccessModifer( "public" );
            Dictionary<string , string> param_list = new Dictionary<string , string>();
            param_list.Add( "int" , "num" );
            param_list.Add( "string" , "str" );
            param_list.Add( "float" , "flt" );
            cls.AddMethod( "int" , "method1" , param_list );
            cls.AddAccessModifer( "private" );
            cls.AddMethod( "int" , "method2" , null );

            cpp_writer.GenerateAll();
        }
        private void GenerateProtocolClassFile( HppFileDescrption hppFileDescrption )
        {
            fragment_root_.AddChild( new Description() );

            DefineGuards defineGuards = new DefineGuards();
            defineGuards.AddGuardMark( hppFileDescrption.DefineGuards );
            fragment_root_.AddChild( defineGuards );

            Headers headers = new Headers();
            fragment_root_.AddChildTo( defineGuards , headers , 0 );
            foreach ( var item in hppFileDescrption.HeaderDictionary )
            {
                headers.AddHeader( item.Key , item.Value );
            }

            NameSpace nmspace = new NameSpace();
            fragment_root_.AddChildTo( defineGuards , nmspace , 0 );
            nmspace.AddNameSpace( hppFileDescrption.NameSpaceString );

            Class cls = new Class();
            fragment_root_.AddChildTo( nmspace , cls , 1 );
            cls.AddClass( hppFileDescrption.ClassName , hppFileDescrption.ParentClassName );
            cls.AddAccessModifer( "public" );

            Dictionary<string , string> param_list = new Dictionary<string , string>();
            param_list.Add( "int"    , "num" );
            param_list.Add( "string" , "str" );
            param_list.Add( "float"  , "flt" );
            cls.AddMethod( "int" , "method1" , param_list );

            cls.AddAccessModifer( "private" );
            cls.AddMethod( "int" , "method2" , null );

            fragment_root_.GenerateAll();
        }