Up until now I never really used the factory pattern that often in C++. Recently I found a use for it in a project I was working on and since I found it useful for my purposes, I thought I might share a tutorial on how the factory pattern can be used in C++.
Now I’m not entirely sure how closely my model fits to the typical factory pattern but as far as I understand factory pattern, it is pretty close if not exact.
Basically a factory consists of an interface class which is common to all of the implementation classes that the factory will create. Then you have the factory class which is usually a singleton class that spawns instances of these implementation classes.
This looked like a link that was fairly re-post worthy. This is practically a must for any .NET + LINQ + MSSQL developer out there. Very neat way of doing audit trails in MSSQL with LINQ and C#.
A couple months ago I wrote a basic set of extension methods to handle automatic auditing in LINQ to SQL. Well I have received a large number of emails regarding this particular project so I have decided to focus on cleaning up my v2 API and releasing it on CodePlex. There was a lot of room for improvement from version 1 and today I am going to post the all new LINQ Audit Trail code. This new version is significantly enhanced in the previous version.
I’ve been doing a decent amount of string manipulation lately and decided to combine that with my newfound knowledge about .NET extension methods. If you don’t know what extension methods are, they’re basically a way to extend a class without needing the source code to that particular class–hence why I can extend the System.String type by simply writing another class. The key is with the parameters of your methods. Here’s the basic gist of it:
So the key here is the “this” keyword before the type identifier in the parameter list of the method.
I’ve wrapped all of my extension methods into a single class simply called “ExtensionMethods” and added it to my project. The namespace doesn’t matter, so I haven’t included it in this example. You can either use the global namespace (though I don’t recommend it) or just create your own namespace called whatever you want.
Without further adue, here’s the code:
/// <summary>
/// Asserts the trailing path delimiter.
/// </summary>
/// <param name="InputPath">The input path.</param>
public static void AssertTrailingPathDelimiter(this string InputPath)
{
InputPath = InputPath.IncludeTrailingPathDelimiter();
}
/// <summary>
/// Trims the extension from a file name.
/// </summary>
/// <param name="InputFile">The input file.</param>
public static void TrimExtension(this string InputFile)
{
int start, count;
if ((start = InputFile.LastIndexOf(".")) > 0)
{
count = InputFile.Length – start;
InputFile = InputFile.Remove(start, count);
}
}
/// <summary>
/// Gets a file extension of a filename.
/// </summary>
/// <param name="InputFile">The input file.</param>
/// <returns>The file extension</returns>
public static string FileExtension(this string InputFile)
{
int start, count;
if ((start = InputFile.LastIndexOf(".")) > 0)
{
count = InputFile.Length – start;
return InputFile.Substring(start, count);
}
return string.Empty;
}
}
Now whenever you use a System.String object, you’ll be able to simply call these methods as if they were part of the System.String class. IE: string MyFileExtension = MyFilePath.FileExtension();
I’m sure I’ll add on to this as I go along.
I recently wrote up a template engine tool called Templatize. It started as a tool for my girlfriend so she could quickly generate HTML pages from CSV rows for use on eBay, but then quickly grew into a more robust template tool.
Basically it takes a set of input data, containing multiple entities (rows), each with multiple properties (columns), formatted from some type of delimited text file. Then it takes in a master template file and spits out multiple “data-injected” versions of that template.
View the full page here.
I’ve completed the modifications and package builds for KnowIT releast candidate 2.1. They are available from the KnowIT Google Code site. Dare I say, this is one of the best peices of software I have written in a long time. And the best part is, its open source!
Check out the Screenshots.
KnowIT works with Windows ONLY. There is currently not a Linux/UNIX scanner available for KnowIT, and the database back-end is a Microsoft product (MSSQL 2005). However, I did add ODBC support this time around, so it may work on other database types as well. If anybody gets it to work on MySQL or Oracle, let me know.