1.0.4 • Published 10 months ago

nv-cli-creat-cstruct v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

nv-cli-creat-cstruct

install

  • npm install nv-cli-creat-cstruct -g

usage

simple

	Usage: nv_cli_creat_cstruct_simple [options] 
	Options:
	    -n, --name                    struct name, default SimpleData
	    -a, --using_flat_array        using flat array as input 
	    -i, --input                   input dict if mode is nest-dict(without using -a) ,default stdin
	    -o, --output                  output string,default stdout
	    -h, --help                    usage

detail

    TODO

example

simple mode : no padding

            #nv_cli_creat_cstruct_simple -n SimpleData

	{
	   a:'int64_t',
	   three_booleans: "bool[3]",
	   bbb:'bool',
	   cc: {
	       x:"double",
		   u16a:"uint16_t[2]",
		   yy:"double",
		   nest: {
		      u32a:"uint32_t[5]",
		      flag:"bool",
		   },
		   lst:"char[10]"
	   },
	   dd:"int",
	   ee:"uint32_t"
	}

            //press ctrl+D

	struct SimpleData {
	    
	    static constexpr auto LeafToStrLmbd=[](auto v,int64_t cnt_if_cary_ptr)->std::string { 
		using T=std::remove_cvref_t<decltype(v)>; 
		if constexpr(std::is_same_v<T,char*>)     { std::string s{"\""};s+=std::string(v);s+="\"";return(s);} 
		else if constexpr(std::is_same_v<T,bool>) { return(v?(std::string{"true"}):(std::string{"false"}));} 
		else if constexpr(std::is_pointer_v<T>)   {
		     using ET = std::remove_cvref_t<std::remove_pointer_t<T>>; 
		     std::string s{"["};
		     if(cnt_if_cary_ptr == 0) {
	    
		     } else {
			if constexpr(std::is_same_v<ET,bool>) {
			    for(int64_t i=0;i<cnt_if_cary_ptr-1;++i) {s+=(v[i]?(std::string{"true"}):(std::string{"false"}));s+=",";}
			    s+=(v[cnt_if_cary_ptr-1]?(std::string{"true"}):(std::string{"false"}));
			} else {
			    for(int64_t i=0;i<cnt_if_cary_ptr-1;++i) {s+=std::to_string(v[i]);s+=",";}
			    s+=std::to_string(v[cnt_if_cary_ptr-1]);                    
			}
		     }
		     s+="]";
		     return(s);
		} 
		else {return(std::to_string(v));}
	    };
	    
	    ////<data>
	    int64_t  a                ;
	    bool     three_booleans[3];
	    bool     bbb              ;
	    struct  {
		////<----data---->
		double   x      ;
		uint16_t u16a[2];
		double   yy     ;
		struct  {
		    ////<--------data-------->
		    uint32_t u32a[5];
		    bool     flag   ;
		    ////</--------data-------->
		    ////<--------show-------->
		    void show(bool endl=true, std::string_view indent= "        ") noexcept {
			std::cout << indent << "{" << std::endl;
			std::cout << indent << "    "  << "\"u32a\"" <<  " : " << LeafToStrLmbd(u32a,5 ) << " , " << std::endl;
			std::cout << indent << "    "  << "\"flag\"" <<  " : " << LeafToStrLmbd(flag,-0) << "   " << std::endl;
			std::cout << indent << "}";
			if(endl) {std::cout << std::endl;} else {}
		    }
		    ////</--------show-------->
		}        nest   ;
		char     lst[10];
		////</----data---->
		////<----show---->
		void show(bool endl=true, std::string_view indent= "    ") noexcept {
		    std::cout << indent << "{" << std::endl;
		    std::cout << indent << "    "  << "\"x\"   " <<  " : " << LeafToStrLmbd(x   ,-0) << " , " << std::endl;
		    std::cout << indent << "    "  << "\"u16a\"" <<  " : " << LeafToStrLmbd(u16a,2 ) << " , " << std::endl;
		    std::cout << indent << "    "  << "\"yy\"  " <<  " : " << LeafToStrLmbd(yy  ,-0) << " , " << std::endl;
		    std::cout << indent << "    "  << "\"nest\"" <<  " : "; nest.show(false,"        "); std::cout << " , " << std::endl;
		    std::cout << indent << "    "  << "\"lst\" " <<  " : " << LeafToStrLmbd(lst ,10) << "   " << std::endl;
		    std::cout << indent << "}";
		    if(endl) {std::cout << std::endl;} else {}
		}
		////</----show---->
	    }        cc               ;
	    int      dd               ;
	    uint32_t ee               ;
	    ////</data>
	    ////<show>
	    void show(bool endl=true, std::string_view indent= "") noexcept {
		std::cout << indent << "{" << std::endl;
		std::cout << indent << "    "  << "\"a\"             " <<  " : " << LeafToStrLmbd(a             ,-0) << " , " << std::endl;
		std::cout << indent << "    "  << "\"three_booleans\"" <<  " : " << LeafToStrLmbd(three_booleans,3 ) << " , " << std::endl;
		std::cout << indent << "    "  << "\"bbb\"           " <<  " : " << LeafToStrLmbd(bbb           ,-0) << " , " << std::endl;
		std::cout << indent << "    "  << "\"cc\"            " <<  " : "; cc.show(false,"    "); std::cout << " , " << std::endl;
		std::cout << indent << "    "  << "\"dd\"            " <<  " : " << LeafToStrLmbd(dd            ,-0) << " , " << std::endl;
		std::cout << indent << "    "  << "\"ee\"            " <<  " : " << LeafToStrLmbd(ee            ,-0) << "   " << std::endl;
		std::cout << indent << "}";
		if(endl) {std::cout << std::endl;} else {}
	    }
	    ////</show>
	};


      #nv_cli_creat_cstruct_simple -n SimpleData -a  [a:int64_t three_booleans:bool[3] bbb:bool cc:[ x:double u16:uint16_t[2] yy:double nest[u32a:uint32_t[5] flag:bool] lst:char[10]] dd:int ee:uint32_t ]

detail mode

    TODO

LICENSE

  • ISC