FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

IO style revisited
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic     Forum Index -> Mango
View previous topic :: View next topic  
Author Message
csauls



Joined: 27 Mar 2004
Posts: 278

PostPosted: Mon Feb 07, 2005 10:26 pm    Post subject: Reply with quote

kris wrote:
Should it use Walter's format() function instead of printf?

Most likely.

Anyway, I didn't have anything better to do, so I tossed together a concept example for that CSS-esque formatter. I'll e-mail it to you to see what you think. Be forewarned, it isn't exactly pretty at this point, and only has the three attributes I used in my Whisper example (length, align, pad) and support for int's and char[]'s. Its just a concept after all.
_________________
Chris Nicholson-Sauls
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
teqdruid



Joined: 11 May 2004
Posts: 390
Location: UMD

PostPosted: Tue Feb 08, 2005 11:16 am    Post subject: Formatter and OO Reply with quote

I'd prefer an OO approach to formatting.

Formatter f = new Formatter();
f.setPadding(3);
....

And for the people who perfer strings:
Formatter f = new Formatter("padding: 3");
Or something like that, so even this:

writer(myInt, new Formatter("padding: 3"));

The IFormatter interface probably only needs to have a few methods like:
char[] format(int i);
... Or something like that.

Thoughts?
Back to top
View user's profile Send private message Send e-mail AIM Address
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Tue Feb 08, 2005 12:40 pm    Post subject: Re: Formatter and OO Reply with quote

teqDruid wrote:
I'd prefer an OO approach to formatting.

Formatter f = new Formatter();
f.setPadding(3);
....

And for the people who perfer strings:
Formatter f = new Formatter("padding: 3");
Or something like that, so even this:

writer(myInt, new Formatter("padding: 3"));

The IFormatter interface probably only needs to have a few methods like:
char[] format(int i);
... Or something like that.

Thoughts?

I tend to agree. The current approach is similar -- one uses TextFormat to do traditional formatting, like so:

Code:
TextFormat format = new TextFormat;

Stdout (format ("?d green bottles", 10));

And the fancy ICU formatters follow the a similar pattern. Keep in mind that the formatters don't have to write into a lookaside buffer and return an array -- they can implement IWritable instead, and format directly to the IBuffer. Not a big deal, but worth noting.

What are your thoughts on the whisper format, TeqDruid?
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Tue Feb 08, 2005 12:53 pm    Post subject: Reply with quote

csauls wrote:
I tossed together a concept example for that CSS-esque formatter. I'll e-mail it to you to see what you think

Nice! And it follows the OO approach noted by TeqDruid. I don't know if you have time, Chris, but I imagine a well-rounded set of formatters like this would be attractive to many. To make it even more useful, the equivalent set of parsers would not go amiss Wink

If the underlying engine(s) were independent of the formatting tags, then one could expose an alternate 'skin', in addition to the CSS one. Something like TeqDruid was suggesting:

Code:
format.float (read x, uint decimals=2, bool exp = false);
Back to top
View user's profile Send private message
csauls



Joined: 27 Mar 2004
Posts: 278

PostPosted: Tue Feb 08, 2005 1:28 pm    Post subject: Reply with quote

Hmm... wow, you actually liked that foul beast? Okie then. I could try hybriding my idea and teq's idea into a Style class, or Format, or whatever, and leave a static opCall for using it my way and an instance opCall for the other. So, user code would be like:

Code:

Style titleStyle = new Style("length:72; align:center; pad:____; endline:yes;");
/+
  Or alternately:
  with (titleStyle = new Style) {
    length (72);
    align (Style.Align.Center);
    pad ("____");
    endline (true);
  }
+/

Stdout (titleStyle(foo.title)) (Style(foo.author, "length:71; align:right; endline:yes;")) ;

MultiStyle mstyle = new MultiStyle;
mstyle.add("left", "length:72; align:left; endline:yes;");
mstyle.add("right", "length:72; align:right; endline:yes;");

bit odd = true;
foreach (char[] line; foo.content) {
  Stdout (mstyle(line, odd ? "left" : "right")) ;
}


_________________
Chris Nicholson-Sauls
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Tue Feb 08, 2005 2:20 pm    Post subject: Reply with quote

csauls wrote:
Hmm... wow, you actually liked that foul beast?

It could use some optimizations but, as you said, it was a PoC (proof-of-concept; not piece-of-crap!).

I think you're on to something with the style notions. There are several ways to interface this kind of this to Mango.io -- I'll note two of them:

- have the Style class maintain a lookaside buffer, and stuff all the output in there. You'll have to figure out whether to do a dchar[] buffer, a templated variety, or something else. mango.io.TextLayout takes a templated approach, whereas Mango.TextFormat will take a dchar[] approach with Walter's format() routine.

- have each Style expose an instance of IWritable, which has the following signature:

Code:
void writer (IWriter w);

The latter could be set up as an inner-class when the Style is created.
Back to top
View user's profile Send private message
csauls



Joined: 27 Mar 2004
Posts: 278

PostPosted: Sat Feb 12, 2005 4:41 am    Post subject: Reply with quote

I've started toying with this now... at present I have an IStyle interface inheriting from IWritable, and a Style class implementing it. It uses a local dchar[] for storing the stylized text. I tossed in a .content() method to get a copy of the buffer. Never know when something like that might be useful.

I'm thinking about your idea of seperating the internal "engine" from the interface for describing the style; or to use your term, the "skin". Not sure how I might do it... definitely means mapping out all possible attributes and their dependancies (like 'pad' meaning nothing if 'length' is default). Also thinking of allowing one to store a style -- or even a /collection/ of styles! -- in a file, using the appropriate format. That would make it even more CSS-esque. So you could do something like:

Code:

  import ...style;

  IWriter writer;
  // ...
  StyleCollection sc = new StyleCollection;
  sc.load("mystyles.mss");

  Style two = sc["two"];

  write (sc["one"]( blah )) (two( moreblah )) ;


The "mystyles.mss" file might look like
Code:

  one {
    length: 15;
    align: left;
  }

  two {
    length: 5;
    align: right;
    pad: "0";
  }

  three {
    case: upper;
    end line: yes;
  }


So suppose Bob changes the way such-and-such database expects certain data... no problem, just change two.length in "mystles.mss" from a 5 to a 10. No recompile. Just run the program as normal, and voila. Smile
_________________
Chris Nicholson-Sauls
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Sat Mar 05, 2005 12:38 am    Post subject: Reply with quote

Chris ~

You might find some use for the mango.format package? It has a few low-level numeric formatting and parsing functions, including floating-point.
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Sat Mar 05, 2005 12:42 am    Post subject: Reply with quote

csauls wrote:
The "mystyles.mss" file might look like
Code:

  one {
    length: 15;
    align: left;
  }

  two {
    length: 5;
    align: right;
    pad: "0";
  }

  three {
    case: upper;
    end line: yes;
  }


So suppose Bob changes the way such-and-such database expects certain data... no problem, just change two.length in "mystles.mss" from a 5 to a 10. No recompile. Just run the program as normal, and voila

If you added an optional name attribute, it could be used to bind each field to a datastore. If you did that, you'd probably need two seperate formats: one to indicate the stored representation, and one to indicate the display variation. Such things are often done with "picture edits", and/or a limited form of regex.

That's probably overloading things somewhat, but might be worth considering for an extended version?
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Sun Mar 06, 2005 3:24 am    Post subject: Reply with quote

JJR wrote:
I've compiled lineio.d example on Linux, and it worked perfectly. I'm liking the "whisper" notation more all the time. As a bonus, the linux executable is 303,942 bytes verses the win32 versions 424,136 bytes

Build.exe produces a lineio.exe at 181KB on Win32. That's a bit better than before, and should become quite a bit less once printf is finally removed from Object.d (Mango doesn't implicitly use printf or format.d)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Mango All times are GMT - 6 Hours
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group