Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ TheIDE » U++ TheIDE: Other Features Wishlist and/or Bugs » Enhancing project templates (upt files)
Enhancing project templates (upt files) [message #5407] Tue, 19 September 2006 16:57 Go to next message
Werner is currently offline  Werner
Messages: 234
Registered: May 2006
Location: Cologne / Germany
Experienced Member
It seems to be a well-established standard to write CAPITALIZED include guards. But this is not possible when using project templates.

As I'm writing my own project templates anyway, I decided to patch Template.cpp to enable uppercase include guards (which might be selected by a corresponding option).

The patch requires just a minor change of a single function:

Original function
ArrayMap<String, EscValue> TemplateDlg::MakeVars0()
{
	ArrayMap<String, EscValue> var;
	String n = ~package;
	int q = n.ReverseFind('/');
	var.Add("PACKAGE", q >= 0 ? n.Mid(q + 1) : n);
	return var;
}


Patched function
ArrayMap<String, EscValue> TemplateDlg::MakeVars0()
{
	ArrayMap<String, EscValue> var;
	String n = ~package;
	int q = n.ReverseFind('/');
	n = q >= 0 ? n.Mid(q + 1) : n;
	var.Add("PACKAGE", n);
	var.Add("PACKAGE_UPPERCASE", ToUpper(n));
	return var;
}


Might I suggest to consider the adoption of this patch into the official Ultimate++ release? Rolling Eyes

If so, please let me know as soon as possible, as I'm writing a project template documentation. Very Happy

Werner
Re: Enhancing project templates (upt files) [message #5408 is a reply to message #5407] Tue, 19 September 2006 18:27 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK, patch accepted.

Mirek
Re: Enhancing project templates (upt files) [message #5414 is a reply to message #5408] Wed, 20 September 2006 10:12 Go to previous messageGo to next message
Werner is currently offline  Werner
Messages: 234
Registered: May 2006
Location: Cologne / Germany
Experienced Member
luzr wrote on Tue, 19 September 2006 18:27

OK, patch accepted.

Mirek


Thanks.

Project template documentation in full progress ...

Please let me know if you change the identifier (key) "PACKAGE_UPPERCASE". Otherwise I assume for documentation purposes that this feature will be part of the next development release.

Werner
Re: Enhancing project templates (upt files) [message #5415 is a reply to message #5414] Wed, 20 September 2006 10:30 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I have kept your patch as suggested.
Re: Enhancing project templates (upt files) [message #5428 is a reply to message #5415] Thu, 21 September 2006 11:25 Go to previous messageGo to next message
Werner is currently offline  Werner
Messages: 234
Registered: May 2006
Location: Cologne / Germany
Experienced Member
When working on the project template documentation, I noticed that the "Console application (no U++)" template defines a non-standard main function:

The standard requires main() to return an int.

Furthermore the standard requires the strings to which argv[] points not to be constant.

Last but not least "stdio.h" should be "<iostream>".

After all, if somebody exploits TheIDE to write plain C++ programs, he or she should get the plain standard. Laughing

Werner
Re: Enhancing project templates (upt files) [message #5436 is a reply to message #5428] Thu, 21 September 2006 15:50 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Werner wrote on Thu, 21 September 2006 05:25

When working on the project template documentation, I noticed that the "Console application (no U++)" template defines a non-standard main function:

The standard requires main() to return an int.

Furthermore the standard requires the strings to which argv[] points not to be constant.

Last but not least "stdio.h" should be "<iostream>".

After all, if somebody exploits TheIDE to write plain C++ programs, he or she should get the plain standard. Laughing

Werner




Thanks. As I am not planning to do anything with templates in near future.. what about posting here all your templates when you are finished? Smile
Re: Enhancing project templates (upt files) [message #5440 is a reply to message #5436] Thu, 21 September 2006 20:46 Go to previous messageGo to next message
Werner is currently offline  Werner
Messages: 234
Registered: May 2006
Location: Cologne / Germany
Experienced Member
luzr wrote on Thu, 21 September 2006 15:50

As I am not planning to do anything with templates in near future.. what about posting here all your templates when you are finished? Smile


Just wait for my project template documentation Cool which I hope to complete by the weekend. Rolling Eyes

As soon as it is published you will be swamped with templates ... Laughing Laughing Laughing

Seriously: as soon as the documentation is completed I have to switch back to a project which I pushed on the stack for some days. But I'll remember your suggestion in my own good time. Very Happy

Werner
Re: Enhancing project templates (upt files) [FEATURE REQUEST] [message #5480 is a reply to message #5415] Tue, 26 September 2006 12:17 Go to previous messageGo to next message
Werner is currently offline  Werner
Messages: 234
Registered: May 2006
Location: Cologne / Germany
Experienced Member
Thank you for adopting my suggestion.

After using "PACKAGE_UPPERCASE" for a couple of days, I'm no longer happy with the simplistic creation of its content. This was obviously an over-quick suggestion. Sorry!

As far as I can see, it is quite common - and I adhere to this quasi-standard - to capitalize mixed-uppercase-lowercase identifiers by inserting an underscore ("_") when the change from a lowercase letter to an uppercase letter indicates a new component.

That is why I wrote the following tiny function, which I suggest to include into Ultimate++, maybe into "uppsrc/ide".

I intentionally wrote it as a non-menber function of "String" (compare e. g., Stroustrup, The C++ Programming Language, Special Edition, 10.3.2; Sutter, Alexandrescu, C++ Coding Standards, 44; Meyers, Effective C++, 4.6 / 23).

String MkInclGuard(const String& name)
{
	String output("");
	int str_len = name.GetLength();
	for (int i = 0; i < str_len; ++i)
	{
		int ch = name[i];
		if (IsAlNum(ch))
		{
			output += ToUpper(ch);
			if (i < str_len - 1)
				if (IsLower(ch) && IsUpper(name[i + 1]))
					output += '_';
		}
		else
			output += '_';
	}
	return output;
}


The patched function then reads:
ArrayMap<String, EscValue> TemplateDlg::MakeVars0()
{
	ArrayMap<String, EscValue> var;
	String n = ~package;
	int q = n.ReverseFind('/');
	n = q >= 0 ? n.Mid(q + 1) : n;
	var.Add("PACKAGE", n);
	var.Add("PACKAGE_UPPERCASE", MkInclGuard(n));
	return var;
}


Werner

[Updated on: Tue, 26 September 2006 12:24]

Report message to a moderator

Re: Enhancing project templates (upt files) [FEATURE REQUEST] [message #5481 is a reply to message #5480] Tue, 26 September 2006 12:26 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Werner wrote on Tue, 26 September 2006 06:17

Thank you for adopting my suggestion.

After using "PACKAGE_UPPERCASE" for a couple of days, I'm no longer happy with the simplistic creation of its content. This was obviously an over-quick suggestion. Sorry!

As far as I can see, it is quite common - and I adhere to this quasi-standard - to capitalize mixed-uppercase-lowercase identifiers by inserting an underscore ("_") when the change from a lowercase letter to an uppercase letter indicates a new component.

That is why I wrote the following tiny function, which I suggest to include into Ultimate++, maybe into "uppsrc/ide".

I intentionally wrote it as a non-menber function of "String" (compare e. g., Stroustrup, The C++ Programming Language, Special Edition, 10.3.2; Sutter, Alexandrescu, C++ Coding Standards, 44; Meyers, Effective C++, 4.6 / 23).

String MkInclGuard(const String& name)
{
	String output("");
	int str_len = name.GetLength();
	for (int i = 0; i < str_len; ++i)
	{
		int ch = name[i];
		if (IsAlNum(ch))
		{
			output += ToUpper(ch);
			if (i < str_len - 1)
				if (IsLower(ch) && IsUpper(name[i + 1]))
					output += '_';
		}
		else
			output += '_';
	}
	return output;
}


The patched function then reads:
ArrayMap<String, EscValue> TemplateDlg::MakeVars0()
{
	ArrayMap<String, EscValue> var;
	String n = ~package;
	int q = n.ReverseFind('/');
	n = q >= 0 ? n.Mid(q + 1) : n;
	var.Add("PACKAGE", n);
	var.Add("PACKAGE_UPPERCASE", MkInclGuard(n));
	return var;
}


Werner



I think we should add it to the Core, it is a nice complement to "InitCaps" sort of function.

I only do not quite like the name (because it is not necessarily related to include guards) - what about something like "ToLowerUnderscoreCaps"? Smile
Re: Enhancing project templates (upt files) [FEATURE REQUEST] [message #5482 is a reply to message #5481] Tue, 26 September 2006 13:52 Go to previous messageGo to next message
Werner is currently offline  Werner
Messages: 234
Registered: May 2006
Location: Cologne / Germany
Experienced Member
luzr wrote on Tue, 26 September 2006 12:26


I think we should add it to the Core, it is a nice complement to "InitCaps" sort of function.

I only do not quite like the name (because it is not necessarily related to include guards) - what about something like "ToLowerUnderscoreCaps"? Smile



I don't stick to the name. But I think it shouldn't start with "ToLower" because it's more "ToUpper". Rolling Eyes And it shouldn't be to long.

What about "ToUpperMixedCase"?

[Updated on: Tue, 26 September 2006 13:58]

Report message to a moderator

Re: Enhancing project templates (upt files) [FEATURE REQUEST] [message #5483 is a reply to message #5482] Tue, 26 September 2006 14:03 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Werner wrote on Tue, 26 September 2006 07:52

luzr wrote on Tue, 26 September 2006 12:26


I think we should add it to the Core, it is a nice complement to "InitCaps" sort of function.

I only do not quite like the name (because it is not necessarily related to include guards) - what about something like "ToLowerUnderscoreCaps"? Smile



I don't stick to the name. But I think it shouldn't start with "ToLower" because it's more "ToUpper".



Right Smile But we can have both.

Quote:


What about "ToUpperMixedCase"?




I got it: ToUpper_Caps Smile
Re: Enhancing project templates (upt files) [FEATURE REQUEST] [message #5484 is a reply to message #5483] Tue, 26 September 2006 16:25 Go to previous messageGo to next message
Werner is currently offline  Werner
Messages: 234
Registered: May 2006
Location: Cologne / Germany
Experienced Member
luzr wrote on Tue, 26 September 2006 14:03

I got it: ToUpper_Caps Smile



"Aye. I could do that."

It's up to you to decide. Just let me know your final decision, so that I can take it into account when upgrading the UPT documentation (refer to message #5463).

Werner

Re: Enhancing project templates (upt files) [FEATURE REQUEST] [message #5485 is a reply to message #5481] Tue, 26 September 2006 21:02 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
ArrayMap<String, EscValue> TemplateDlg::MakeVars0()
{
	ArrayMap<String, EscValue> var;
	String n = ~package;
	int q = n.ReverseFind('/');
	var.Add("PACKAGE", q >= 0 ? n.Mid(q + 1) : n);
	var.Add("PACKAGE_TOUPPER", ToUpper(n));
	var.Add("PACKAGE_TOUPPER_CAPS", ToUpper_Caps(n));
	return var;
}



Mirek
Re: Enhancing project templates (upt files) [FEATURE REQUEST] [message #5486 is a reply to message #5485] Tue, 26 September 2006 21:36 Go to previous messageGo to next message
Werner is currently offline  Werner
Messages: 234
Registered: May 2006
Location: Cologne / Germany
Experienced Member
luzr wrote on Tue, 26 September 2006 21:02

ArrayMap<String, EscValue> TemplateDlg::MakeVars0()
{
	ArrayMap<String, EscValue> var;
	String n = ~package;
	int q = n.ReverseFind('/');
	var.Add("PACKAGE", q >= 0 ? n.Mid(q + 1) : n);
	var.Add("PACKAGE_TOUPPER", ToUpper(n));
	var.Add("PACKAGE_TOUPPER_CAPS", ToUpper_Caps(n));
	return var;
}



Mirek


If "package" holds a path and a filename,

only the filename goes into "PACKAGE", but
both the path and the filename go into "PACKAGE_TOUPPER" and
both the path and the filename go into "PACKAGE_TOUPPER_CAPS".

Is that what you want?

I myself would prefer to find just the filename in ("PACKAGE_TOUPPER" and) "PACKAGE_TOUPPER_CAPS".

Werner

Re: Enhancing project templates (upt files) [FEATURE REQUEST] [message #5488 is a reply to message #5486] Tue, 26 September 2006 22:58 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
If I remember well, it should be "package/filename.h"

As there is high probability that that two packages have the same header, I think it is a good idea to add package name to the mix.

Mirek
Re: Enhancing project templates (upt files) [message #6886 is a reply to message #5436] Sun, 03 December 2006 13:43 Go to previous message
Werner is currently offline  Werner
Messages: 234
Registered: May 2006
Location: Cologne / Germany
Experienced Member
luzr wrote on Thu, 21 September 2006 15:50

As I am not planning to do anything with templates in near future.. what about posting here all your templates when you are finished? Smile



You can find the first two in

Extra libraries, Code snippets, applications etc. » Applications created with U++ » New UPTs: "Function Test Frame" and "Function Test"

I couldn't find a more suitable topic.

Werner
Previous Topic: Assamblies and nests
Next Topic: Ctrl Documentation Bug?
Goto Forum:
  


Current Time: Thu Mar 28 11:47:28 CET 2024

Total time taken to generate the page: 0.01440 seconds