Re: DUB and ddoc - howto?

2019-06-28 Thread Martin Tschierschke via Digitalmars-d-learn

On Friday, 28 June 2019 at 13:03:17 UTC, Daniel Kozak wrote:

Did you try dub build --help?


Oh, thank you! I just looked at dub --help | grep -i doc ... and 
several other places...




Blog Post #0048: Model, View, Controller

2019-06-28 Thread Ron Tarrant via Digitalmars-d-learn
Today's post on gtkdcoding.com is the first in a 9-part series 
covering GTK's model/view/controller mechanism and how it's used 
in various widgets including the TreeView. Today is mostly 
theory, a reference (if you will) for the rest of the series.


You can read it here: 
https://gtkdcoding.com/2019/06/28/0048-mvc-i-introduction.html


Re: DUB and ddoc - howto?

2019-06-28 Thread Daniel Kozak via Digitalmars-d-learn
But I am using this one: https://github.com/adamdruppe/adrdox

On Fri, Jun 28, 2019 at 2:45 PM Martin Tschierschke via Digitalmars-d-learn
 wrote:

> A very simple question, is there an example how to generate
> documentation with dub?
> (like dmd -D)
>
> My internet search was not successful.
>
>


Re: DUB and ddoc - howto?

2019-06-28 Thread Daniel Kozak via Digitalmars-d-learn
Did you try dub build --help?

-b  --build=VALUE Specifies the type of build to perform. Note that
setting the DFLAGS environment variable will
override
the build type with custom flags.
Possible names:
  debug (default), plain, release, release-debug,
  release-nobounds, unittest, profile, profile-gc,
  docs, ddox, cov, unittest-cov, syntax and custom
  types

So I guess something like this could work:

dub build -b ddox
or

dub build -b docs

On Fri, Jun 28, 2019 at 2:45 PM Martin Tschierschke via Digitalmars-d-learn
 wrote:

> A very simple question, is there an example how to generate
> documentation with dub?
> (like dmd -D)
>
> My internet search was not successful.
>
>


DUB and ddoc - howto?

2019-06-28 Thread Martin Tschierschke via Digitalmars-d-learn
A very simple question, is there an example how to generate 
documentation with dub?

(like dmd -D)

My internet search was not successful.



Re: Variadic template parameters, refactor a long chain of static if's to 'functions'.

2019-06-28 Thread realhet via Digitalmars-d-learn

On Tuesday, 11 June 2019 at 13:22:26 UTC, Adam D. Ruppe wrote:

On Tuesday, 11 June 2019 at 09:26:56 UTC, realhet wrote:

  static bool processId(bool captureIntId, alias r, alias a)(){
mixin("alias ta = typeof("~a.stringof~");");


As I have been saying a lot, mixin and stringof should almost 
never be used together. You could write this a lot easier:

...


Thank you for the long example, it helped me a lot!

The thing is now capable of:

- getting a specific type of parameter -> 
args.paramByType!(string[int]).writeln;


- including wrapper structs. In that case, optionally can fall 
back to the type inside the struct.


- handle and call events (structs or fallback as well)

- It is super easy now to make a function that can process a 
specific set of events:

struct onClick  { void delegate() val; }
...
struct onHold   { void delegate() val; }

void processBtnEvents(T...)(bool click, bool state, bool chg, 
T args){
  if(click) args.paramCall!(onClick, true/*fallback to pure 
delegate*/);

  if(state) args.paramCall!onHold;
  if(chg){
args.paramCall!onChange;
if(state) args.paramCall!onPress;
 else args.paramCall!onRelease;
  }
}

- Also I've found a way to exchange state values (for example a 
bool for a CheckBox control):

  - I can give it a pointer to a bool
  - Or I can give a getter and 0 or more setter(s): bool 
delegate(), void delegate(bool)

  - Can be functionPointers too, not just delegates.
  - example:
void fIncrementer(T...)(T args){
  paramGetterType!T x;
  args.paramGetter(x);
  x = (x + 1).to!(paramGetterType!T);
  args.paramSetter(x);
}
  - it is letting me use enumerated types too -> I will not have 
to write anything, and there will be an automatic 
RadioButtonGroup on the screen, just bu mentioning that variable. 
It will be awesome!


- Sorry for the lot of string processing and some mixin()s :D At 
the end of the code below, I've learned a lot while being able to 
write nicer code.


Thank you for your example code, I've learned a lot from it.

--
private{
  bool is2(A, B)() { return is(immutable(A)==immutable(B)); }

  bool isBool  (A)(){ return is2!(A, bool  ); }
  bool isInt   (A)(){ return is2!(A, int   ) || is2!(A, uint  ); }
  bool isFloat (A)(){ return is2!(A, float ) || is2!(A, double); }
  bool isString(A)(){ return is2!(A, string); }

  bool isSimple(A)(){ return isBool!A || isInt!A || isFloat!A || 
isString!A; }


  bool isGetter(A, T)(){
enum a = A.stringof, t = T.stringof;
return a.startsWith(t~" delegate()")
|| a.startsWith(t~" function()");
  }
  bool isSetter(A, T)(){
enum a = A.stringof, t = T.stringof;
return a.startsWith("void delegate("~t~" ")
|| a.startsWith("void function("~t~" ");
  }
  bool isEvent(A)(){ return isGetter!(A, void); } //event = void 
getter


  bool isCompatible(TDst, TSrc, bool compiles, bool 
compilesDelegate)(){

return (isBool  !TDst && isBool  !TSrc)
|| (isInt   !TDst && isInt   !TSrc)
|| (isFloat !TDst && isFloat !TSrc)
|| (isString!TDst && isString!TSrc)
|| !isSimple!TDst && (compiles || compilesDelegate); 
//assignment is working. This is the last priority

  }
}

auto paramByType(Tp, bool fallback=false, T...)(T args){
  Tp res;

  enum isWrapperStruct = __traits(hasMember, Tp, "val") && 
Fields!Tp.length==1; //is it encapsulated in a wrapper struct?  
-> struct{ type val; }


  enum checkDuplicatedParams = q{
static assert(!__traits(compiles, duplicated_parameter), 
"Duplicated parameter type: %s%s".format(Tp.stringof, fallback ? 
"("~typeof(Tp.val).stringof~")" : ""));

enum duplicated_parameter = 1;
  };

  static foreach_reverse(idx, t; T){
//check simple types/structs
static if(isCompatible!(typeof(res), t, __traits(compiles, 
res = args[idx]), __traits(compiles, res = 
args[idx].toDelegate))){
  static if(__traits(compiles, res = args[idx]))   
res = args[idx];else res = args[idx].toDelegate;

  mixin(checkDuplicatedParams);
}else
//check fallback struct.val
static if(fallback && isWrapperStruct && 
isCompatible!(typeof(res.val), t, __traits(compiles, res.val = 
args[idx]), __traits(compiles, res.val = args[idx].toDelegate))){
  static if(__traits(compiles, res.val = args[idx]))  
res.val = args[idx];  
  else res.val = args[idx].toDelegate;

  mixin(checkDuplicatedParams);
}
  }

  static if(isWrapperStruct) return res.val;
else return res;
}

void paramCall(Tp, bool fallback=false, T...)(T args){
  auto e = paramByType!(Tp, fallback)(args);
  static assert(isEvent!(typeof(e)), "paramCallEvent() error: %s 
is not an event.".format(Tp.stringof));

  if(e !is null) e();
}

template paramGetterType(T...){
  static foreach(t; T){
static if(isPoint