![]() |
|
Automatic syntax line break C++ |
Mark Oates
Member #1,146
March 2001
![]() |
Hey guys, I'm working on documentation and have definitions that are too long to fit on a single line: {"name":"610553","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/0\/2026d678149903eb86fd0e6adc9902f3.png","w":844,"h":144,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/0\/2026d678149903eb86fd0e6adc9902f3"} The code is automatically parsed from the source and then regenerated by the parser so I can't just properly format it in the source itself. I'm looking for something, preferably in python, that can properly add line breaks in the appropriate places. Any ideas? -- |
torhu
Member #2,727
September 2002
![]() |
Uh, have you tried using Doxygen? |
Mark Oates
Member #1,146
March 2001
![]() |
Doxygen is pretty hideous in my opinion. I chose to go the custom route so that I could keep my commenting and code style clean. -- |
torhu
Member #2,727
September 2002
![]() |
How does Doxygen care about your coding style? And you can enable Javadoc style comments, they look much better than the default Qt style |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Mark Oates said: The code is automatically parsed from the source and then regenerated by the parser so I can't just properly format it in the source itself. I'm not sure what you mean by that. Are you saying you can't do something like this? int my_really_long_function( parameter 1, parameter 2, other_parameter 3 );
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
SiegeLord
Member #7,827
October 2006
![]() |
Are you in control of the parser/formatter? If so, why not do it there? "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
bamccaig
Member #7,536
July 2006
![]() |
I'm not sure it's so much "science" wrapping long lines as art. I'm not sure there's existing software that will get this right, even if you could interface it with your documentation engine. That said, I'm assuming this is HTML/CSS being rendered in a browser. If so I imagine fixing the styling of that (i.e, getting that to wrap) will be easier and sufficient to make the documentation usable. Am I way off? Thoughts? -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Mark Oates
Member #1,146
March 2001
![]() |
torhu said: How does Doxygen care about your coding style? And you can enable Javadoc style comments, they look much better than the default Qt style Haha, that's pretty much what I was referring to. SiegeLord said: Are you in control of the parser/formatter? If so, why not do it there? Hmm, that's a possibility. I am considering filtering the string to remove extra spaces between the '<' and '>' characters that are introduced by the parser. It might be easiest to introduce a simple rule for lines that are too long. A rule like "line breaks at non-nested commas if a line is too long" could do the job. Bjarne Stroustrup might say I should simplify my code, and that's also a good suggestion. I could use more typedefs to simplify this: static bool Attributes::create_datatype_definition(std::string datatype_identifier, bool (*)( void *,::std::string ) * to_val_func, std::string (*)( void * ) * to_str_func) to this: static bool Attributes::create_datatype_definition( std::string datatype_identifier, ToValueFunc *to_val_func, ToStringFunc *to_str_func) But I wonder if that would be helping or hurting. -- |
Polybios
Member #12,293
October 2010
|
I've come to like doxygen, it pretty much just works. Didn't like documentation in the source either, but you can write separate files, too. Btw., why not use std::function here? |
Mark Oates
Member #1,146
March 2001
![]() |
Polybios said: Btw., why not use std::function here? I've never actually used std::function, and I'm not sure what advantage it might provide. My naive guess would be to implement it like this: static bool Attributes::create_datatype_definition( std::string datatype_identifier, std::function<bool(void*, std::string)> to_val_func, std::function<std::string(void*)> to_str_func)
-- |
Polybios
Member #12,293
October 2010
|
Advantages: Disadvantage: Examples: I've found it especially useful to bind a member function to an object's instance ("this" pointer), e.g. 1#include <functional>
2#include <iostream>
3
4class Foo {
5 public:
6 void bar() {
7 std::cout << "bar called" << std::endl;
8 }
9
10 void bar2(int i, int j) {
11 std::cout << "bar2 called: " << i << ", " << j << std::endl;
12 }
13};
14
15
16int main() {
17 Foo foo;
18
19 std::function<void()> f = std::bind(&Foo::bar, &foo);
20 std::function<void()> g = std::bind(&Foo::bar2, &foo, 2, 4);
21 std::function<void(int,int)> h = std::bind(&Foo::bar2, &foo, std::placeholders::_1, std::placeholders::_2);
22 std::function<void(int,int)> t = std::bind(&Foo::bar2, &foo, std::placeholders::_2, std::placeholders::_1);
23 std::function<void(int,int)> u = std::bind(&Foo::bar, &foo);
24
25
26 f(); // will call foo.bar()
27 g(); // will call foo.bar2(2, 4)
28 h(2, 4); // will also call foo.bar2(2, 4)
29 t(4, 2); // will also call foo.bar2(2, 4) ;)
30 u(4, 2); // will omit the arguments and call bar
31}
32
33/** output:
34bar called
35bar2 called: 2, 4
36bar2 called: 2, 4
37bar2 called: 2, 4
38bar called
39**/
Edit: Lambdas without captures will decay (I think that's how they call it) into a function pointer, but for lambdas with captures, you'll need a std::function. |
Gideon Weems
Member #3,925
October 2003
|
|