Archive for May, 2006

C++ Boost Filesystem Library(Part III): Example Programs

8

My earlier posts on C++ Boost Libraries introduced the Boost Filesystem Library and discussed some example programs that make use of it. I discuss two more examples in this post. (Be sure to include the needed boost header files as noted in the earlier posts, including creation of the alias to the boost filesystem namespace: namespace bfs = boost::filesystem; )

1. A function to search for a file.
[cpp]
// Search for a file with the name ‘filename’ starting in directory ‘dir_path’, copy the path of the file in ‘pfound’ if found, and return true.
// Else return false.
bool find_file(const bfs::path & dir_path, const std::string & file_name, bfs::path & pfound)
{
if( !exists(dir_path) || !is_directory(dir_path) )
return false;
bfs::directory_iterator iter(dir_path), end_iter;
for(; iter!= end_iter; ++iter)
{
if( bfs::is_directory(*iter) )
{
if( find_file(*iter, file_name, pfound) )
return true;
}
else if( iter->leaf() == file_name )
{
pfound = *iter;
return true;
}
}
return false;
}
[/cpp]
The function first verifies if the path passed in ‘path_dir’ exists and if it is a directory. Then it creates a ‘directory_iterator’ object(introduced in the previous post) by passing this path to its constructor. The loop then iterates over all the contents of the directory, and for every sub-directory found, it calls itself recursively passing this new directory as the starting point. Every file that is found is compared with the file that is to be searched(file_name), and if a match is found, the path is copied into ‘pfound’ and function returns true. If nothing is found by the end of the loop, ‘false’ is returned. Remember that as discussed earlier, iter->leaf() returns the last part of a path – the file name. Applying indirection operator to the directory_iterator object returns the file it is pointing to.

2. A simple directory listing (ls/dir) program.
[cpp]
void sls(const bfs::path & p)
{
unsigned long fc=0, dc=0;
if( !bfs::exists(p) )
std::cout<<"\nFile Not Found:"<

else if( !bfs::is_directory(p) )
std::cout<<"\nFound: " << p.native_file_string() << "\n";

std::cout<<"In directory:"< bfs::directory_iterator iter(p), end_iter;
for(; iter != end_iter; ++iter)
{
try {
if(bfs::is_directory(*iter))
{
++dc;
std::cout<leaf()<<"[Directory]\n";
}
else
{
++fc;
std::cout<leaf()<<"\n";
}
} catch(const std::exception & ex) {
std::cout<leaf() << ": " << ex.what() << std::endl;
}
std::cout< } //for
} //sls
[/cpp]
The function simply iterates over all the contents of the directory passed to it(p) and prints every file and directory that is found. [Directory] tag is added to the directory names, and at the end of the program the total count of the files and directories is printed. This program only prints the contents of the directory passed, it doesn’t traverse its sub-directories. Can you combine the general idea of the above two examples to create a directory listing program that displays the files of all the sub-directories recursively? You can also print more information about the files by using boost filesystem functions like is_symbolic_link(), file_size(), last_write_time() etc[discussed in the earlier posts].

Most of the examples inspired/taken from the Boost website. The website documentation also contains more help on the various formats in which the paths to the files can be represented. The function ‘native_file_string()’ used in the Example 2 above returns the path in the native format(using ‘/’ as a file separator on Unix platforms and ‘\’ on Windows platforms, for example). To pass the path names as ‘path’ objects, use the services from fstream.hpp. All Filesystem library related exceptions are available in exception.hpp. The header convenience.hpp contains a few convenience functions(like change_extension()). You can start from the documentation page on the website for further information.

WordPress Plugin and Theme Cheatsheets

4

If you are a plugin or a theme developer for the WordPress software, then you probably are going to love these two cheatsheets – created as JPG images so that they can be set as a desktop wallpaper! Screenshots for the Plugin cheatsheet and the Theme cheatsheet are available at the headzoo.com website. Send suggestions or any other feedback to the author.

More cheatsheets related to programming technologies are available here.
Official google cheatsheet is here but I think you will like this google cheatsheet more.

For more such cheatsheets, there is always Google Search :)

C++ Boost Filesystem Library(Part II): Example Programs

11

Beyond the C++ Standard Library : An Introduction to BoostContinuing from where I had left in my earlier post containing the basics of the C++ Boost Filesystem Library, below are some example programs that make use of some common facilities available in the Boost Filesystem Library. I assume that all the code snippets shown in this post are properly nested within the main() function apart from including the following things:
[cpp]
#include
#include
#include
namespace bfs=boost::filesystem;
[/cpp]

1. Simple program to demonstrate the use of file creation and removal operations:
[cpp]
std::cout<<"Enter your choice:\n";
std::cout<<"1. Create folder\n2. Rename File\n3. Remove File\n4. Copy File\n";
char ch;
std::cin>>ch;
std::string name, new_name;
switch(ch)
{
case ’1′:
std::cout<<"Enter folder name:";
std::cin>>name;
bfs::create_directory(bfs::path(name));
break;
case ’2′:
std::cout<<"Enter file name:";
std::cin>>name;
std::cout<<"Enter new name:";
std::cin>>new_name;
bfs::rename(name, new_name);
break;
case ’3′:
std::cout<<"Enter file name:";
std::cin>>name;
bfs::remove(bfs::path(name));
break;
case ’4′:
std::cout<<"Enter file name:";
std::cin>>name;
std::cout<<"Enter new name:";
std::cin>>new_name;
bfs::copy_file(name, new_name);
break;
}
std::cout<<"Operation finished."< }
[/cpp]
Pay attention to the following four Boost Filesystem functions used:
[cpp]
bfs::create_directory(bfs::path(name));
bfs::rename(name, new_name);
bfs::remove(bfs::path(name));
bfs::copy_file(name, new_name);
[/cpp]
They all do what their function names suggest. Like its always the case with the simple example programs, no error checking is done here ;)

2. Removing all the files from a directory:
[cpp]
std::cout<<"Enter the name of the folder to empty:";
std::string name;
std::cin>>name;
bfs::remove_all(bfs::path(name));
std::cout<<"Operation completed."< [/cpp]

The other examples needs an introduction to the directory_iterator class which is used to iterate over the contents of a directory. A simple usage looks like this:
[cpp]
bfs::path p(“folder”);
bfs::directory_iterator dir_iter(p), dir_end;
for(;dir_iter != dir_end; ++dir_iter)
{
std::cout<<(*dir_iter).leaf();
}
[/cpp]
C++ Template Metaprogramming : Concepts, Tools, and Techniques from Boost and Beyond (C++ in Depth Series)A directory_iterator object can be created by passing it a name of a directory. Applying the prefix increment operator(++) to it makes it point to the next file in the directory. Applying the indirection operator(*) returns the file currently being pointed to, as a ‘path’ object. We call the leaf() method on the returned ‘path’ object to print the file name. Using ‘dir_iter->leaf()’ instead of ‘(*dir_iter).leaf()’ has the same effect.

Using a ‘directory_iter’ object, we can create a function similar to the ‘remove_all()’ function that we used in Example 2.
3. Removing all the files from a directory by iteration:
[cpp]
std::cout<<"Enter the name of the folder to empty:";
std::string name;
std::cin>>name;
bfs::path p(name);
if(!bfs::exists(p) || !bfs::is_directory(p))
{
std::cout<<"Invalid input."< exit(-1);
}
bfs::directory_iterator dir_iter(p), dir_end;
for(;dir_iter != dir_end; ++dir_iter)
{
std::cout<<"Removing file: "<leaf();
bfs::remove(*dir_iter);
}
std::cout<<"Operation Completed."< [/cpp]
Simple error checking is done on the input before calling the remove()function on all the files present in the specified folder. Will follow up with more examples using the Boost Filesystem Library.

Movable Type 3.3 Beta To Be Released On May 31

1

Its close to one year now since the 3.2 version of the Movable Type blog publishing software was released last year. Jay Allen, Product Manager at Six Apart, has announced yesterday that the first beta of the next version of the software, Movable Type 3.3, will be released on May 31.

Good news: We’ve got a new version of Movable Type on the way, and we wanted to let you know that the beta is coming soon. We plan to start the Movable Type 3.3 beta test on Wednesday, May 31.

The highlight this time around about the beta development stage is that a separate blog will be serving as a common place for everyone to keep informed(and get technical support) about the latest developments with the beta product. There is also a tight 3-week deadline for beta testing this time, informs Jay Allen. So whoever is a Movable Type fan and would like to get their hands dirty by test driving its multiple beta versions that would be released in the coming next few weeks, get ready and be prepared for the D-day.
You can read the announcement here:
Coming soon: Movable Type 3.3 (beta)

Update: More details about the new features of the Beta version to be released are here: What’s new in Movable Type 3.3?

Should I Be Developing Ajax Applications using Google Web Toolkit(GWT)?

0

So why should an Ajax developer be interested in the recently released Google Web Toolkit(GWT)? One possible reason could be to overcome the shortcomings of the typical Ajax web development model as noted in my earlier post. Firstly, a framework always provides a head start to a project, allowing the developers to worry only about writing the application logic; user interface elements, the plumbing work needed for the communication between the client and the server are provided by the framework itself. The more specific benefits of using the Google Web Toolkit are:

  1. The developer is relieved from the thankless job of understanding every single way in which the browsers differ from one another in handling the same web page, allowing them to create websites such that all these web browsers handle a page in (roughly) the same way.
  2. GWT allows the developers to interact with the browser’s history stack which means that the Ajax applications created using GWT can allow the users to use the ‘Back’ and ‘Forward’ buttons of the web browser and to bookmark the various pages of the website.

    Refer to points 2 & 3 in my earlier post.

  3. Developers can use a more modular and statically typed programming language in Java to create the interface and other components instead of hacking their way out with Javascript. Ultimately, its still the JavaScript code that is generated and served to the web browser, but GWT provides an abstraction layer that shields the developers from having to do much with the JavaScript language. The flip side of this is that for pure interface code, Javascript might offer a more natural solution than Java language when it comes to creating web pages; see the discussion below.

    Refer to point 1 in my earlier post.

    Being able to use Java to create Ajax applications also means better integration with the rest of the Java web development technologies like JSP, JSF, etc(note that code written using GWT uses the Java Web UI class library which is not related to any of the Java standard libraries and this code is statically translated to Javascript and HTML code before making available to the server. Integration would be limited to sharing something like a Java component between a JSP page and the code written using GWT). This may not appeal to those who are using other server-side technologies like PHP and ASP.NET.

    Java language also boasts of better programmer IDEs and tools with good support for Unit Testing and Refactoring. In fact, GWT itself has good JUnit integration through easy to use class libraries in the package com.google.gwt.junit.

    Javascript code can still be embedded within the Java code if only the services of the Javascript language are going to solve a particular problem, by using the Javascript Native Interface(JSNI)(on the lines of JNI). See this for more information.

  4. The biggest advantage of using GWT for creating Ajax applications is the relative ease with which the data can be communicated between the server and the client by just creating serializable Java objects.
  5. Good support for debugging. Eclipse IDE and GWT host mode form a good combination for convenient debugging of the GWT applications.

Having said all this, I am not a big fan of static translation of one programming language to the other. If it were as unified as in ASP.NET(see ASP.NET WebParts; all the translation happens at run-time), I would have welcomed it whole-heartedly. But different programming languages are created to solve different problems, and they are optimized to that specific job. I hate Javascript language for many reasons(as I do in case of Java) but still believe that Javascript is better oriented towards creating client-side code for the web browsers than Java language is(when the intention is to create a web interface). Are we going to use Java idioms here or are we going to try to imitate the Javascript idioms in the Java code? How many Java libraries are supported by the GWT SDK tools? What about the unsupported libraries whose functionality is needed for the application?

Secondly, the entire translation process is lengthy and inefficient: create an empty GWT application using the GWT SDK, fire up your favourite Java editor(eg: Eclipse) and create the Java source files in it, translate these Java files to Javascript + HTML files and finally integrate them with the rest of the server-side code(PHP, JSP etc). But there are advantages we get out of this investment as noted in the above mentioned points.

Not all the standard Java libraries are supported by GWT. For example, only java.lang and a part of java.util are supported by the GWT tools, which means the code written using Java libraries not supported by GWT cannot be translated by the GWT tools. The developer needs to make a call whether to achieve the desired functionality by writing custom Java code or by writing the code in Javascript.(I would be tempted to go the second way as that would allow me to use the same code in other applications that don’t make use of GWT).

By the way, why don’t we have the access to the GWT source code? Isn’t Google a big supporter of the Free Software community?

For developer centric GWT related discussion, go to the GWT Support Forums.
Related Post: A Case Against Ajax Web Development Model

buy prednisone medication COD purchase prednisone without prescription needed purchase prednisone prescription online prednisone no prior script prednisone no rx needed order prednisone usa cod buy prednisone without rx from us pharmacy buy prednisone online without rx purchase prednisone without prescription order prednisone saturday delivery buy prednisone amex online without prescription ordering prednisone over the counter buy prednisone amex online without rx where can i buy Prednisone ordering Paxil over the counter order Paxil without rx needed order Paxil pharmacy Paxil overnight delivery fed ex ordering Paxil without a script order Paxil order amex order Paxil amex online without prescription buy Paxil pay pal without prescription order rx free Paxil cheapest Paxil available online purchase Paxil without purchase Paxil without prescription how to order Paxil online without a prescription purchase Paxil cod next day delivery buy discount Paxil online buy Paxil no visa online without rx where to buy accutane buy frontpage software cheap mortgage application software buy autocad software best price for final draft 7 software iphone software download plagiarism software to buy for parents Crestor side effects buy masterwriter software discount bmi sesac microsoft software downloads wm5 software download treo software download cheap discount software xxasdf discount trellian software best antivirus software download cheap microsoft word software buy software for mac software discounts for educators microsoft office purchase Prednisone online no membership buy windows xp oem software buy flash cs3 software photoshop cs 5 full fashion conference italy buy Orlistat with amex ordering Lasix over the counter purchase online prescription Lasix without windows 7 product key purchase online cheapest xenical available online prescription xenical online online Maxalt achat Maxalt Valtrex with repronex where to buy Valtrex by cod where to purchase generic valtrex online without a prescription quality generic valtrex cheap valtrex usa (no prescriptions needed for Buspar|buy Buspar with no prescription|online pharmacies Buspar|Buspar cheap|buy Buspar without rx|purchase rx Buspar without|Buspar purchase online|purchase Buspar online without rx|purchase Buspar free consultation|buy Buspar Online|buy Buspar american express|buy Buspar Online|buy cheap Buspar with dr. prescription|Buspar side effects|fedex Buspar without priscription|overnight Buspar without a rx|order cheap overnight Buspar|Buspar toronto|uk order Buspar|Buspar no doctors prescription|Buspar mexico|Buspar order|no prescription Buspar with fedex|order generic Buspar|buy Buspar without rx from us pharmacy|prezzo Buspar|Buspar 10mg|Buspar from canada|purchasing Buspar without a script|buy Buspar australia|purchase Buspar visa without prescription|online purchase Buspar|buy Buspar no perscription cod|buy Buspar drugs|buy Buspar with visa|buy Buspar without rx needed|buy Buspar without prescription|buy Buspar no prescription low cost|purchase purchase Buspar no prescription cheap buy cheap Nolvadex cod buy Nolvadex infertility in internet visa at Wisconsin Ontario omicrosoft office 2003 megaupload online purchase Lasix Buy genuine accutane online buy nolvadex amex online where to buy synthroid in germany where to buy synthroid pills cheap discount Nolvadex overnight Accutane 20mg mexico order Lasix usa Lasix overnight delivery fed ex buy zithromax overnight purchase online prescription zithromax without buy Nolvadex cheap cheapest Nolvadex available online buy Nolvadex without rx from us pharmacy buy Nolvadex without a prescription overnight delivery buy 20mg Nolvadex free shipping buy Nolvadex no prescription order zithromax overnight delivery buy zithromax 100 mg visa Valtrex without doctor prescription buying zithromax over the counter order zithromax with no prescription order zithromax 250mg mastercard order zithromax 250 mg visa order zithromax 500mg amex buy mail order Orlistat buy Valtrex online now Orlistat tablets purchase cheap Maxalt onlinebuy generic Maxalt pills free fedex delivery Buspar buy cheap Finpecia under without rx purchase online finpecia without rx finpecia fedex no prescription buy line finpecia fedex Valtrex overnight without a rx Buspar u.p.s shipping cod order cheap overnight Buspar free fedex delivery prednisone prednisone no script fedex buy valtrex cheap without prescription generic Valtrex fedex Online overnight shipping Valtrex purchase Zithromax without purchase Zithromax no scams Arimidex delivered overnight order cheap overnight Arimidex purchase Cytotec over the counter fedex buy Cytotec online overnight adobe financial results microsoft office professional 2007 upgrade download microsoft office professional 2007 cheap Buspar by money order how to buy Valtrex without a prescription cheap valtrex uk buy Flomax in the uk purchase Proscar usa cod adobe lm service adobe after effects simple creativity latest adobe flash download buy Crestor amex measurement software Photoshop For Sale buy discount Tamsulosin line Autocad 2010 Review download adobe premiere complete removal of office 2003 adobe indesign cs2 photoshop lightroom 3 cheap where can i buy herbal Crestor where to buy Crestor buy Crestor online cod Buy Fincar online 5 mg mastercard cheapest price for microsoft office vio software discount coupon purchase Orlistat amex online without prescription buy maxalt online without a prescription adobe photoshop 6 cd key Cheap Software Buy Downloads For Photoshop flash catalyst sql ms office 2010 enterprise windows 7 upgrade oem Windows Server 2003 Standard Edition Downloads For Windows 7 Ultimate buy Valtrex no prescriptions application free download office microcoft2007 buy Crestor drugs Valtrex no prescription purchase Valtrex amex online without prescription Xenical Orlistat Flomax buy on line boilsoft viseo create new instrument logic studio 9 cheap purchase finpecia Flomax best buy buy cheap oem software formica countertop cyberlink power dvd 9 download buy Prednisone no prescriptions cheap indesign cs android acdsee buy Flomax australia generic Valtrex online lightroom license .txt download de driver para corel windvd buy microsoft office online cheap generic Valtrex online buy Flomax online no prescription buy pharmacy Flomax waterview cheap Valtrex by money order ifinance price price of valtrex buy valtrex doctor prescription buy generic Crestor order generic Tamsulosin imtoo dvd ripper serial look like buy Buspar without a rx cheap digital video buy Prednisone amex want to buy Buspar in malaysia Bupropion buy Bupropion buy no perscription Amitriptyline buy discount Zithromax cheapest Zithromax available online how to order Buspar online without a rx purchase prednisone cod next day delivery where can i purchase prednisone online prednisone online cash on delivery microsoft office 2010 3 user license cheap mac desktops no prescription Orlistat cod delivery Work Order Tracking System Acrobat 6.0 Professional Oem Version Windows 7 buy Valtrex where order Orlistat no rx cheap proffes Microsoft Windows Xp Purchase buy Valtrex legally Windows Xp Server buy cheap online pharmacy Buspar buy Prednisone online now generic Zithromax usa accutane 40 mg delivered overnight buy accutane 40 mg with no prescription media 8 oline cheap cs software Discount Microsoft WindowsLightroom 2 Windows 7Ms Office StandardPhotoshop Cs5 UpgradeComputer Monitors For SaleWindows Xp InstallSuite Microsoft OfficeAutocad Version 2007Adobe Acrobat 9.0 Standard DownloadIe8 Download For Windows 7Adobe Paint ShopMicrosoft Service Pack 2Free Download Adobe AcrobatStudent And Teacher EditionManage ImageAdobe Acrobat 7 Pro DownloadVista Home Premium To Windows 7 UltimateWindows 7 Home Premium Upgrade OemAdobe Creative Suite 5 Master Collection Student And Teacher EditionBuy Adobe Photoshop Lightroom 3Ms Office 2010 Home And StudentCompare Photo SoftwareMicrosoft Office Word Viewer 2010Windows 7 Upgrade Student Discount ProfessionalWindows 7 Updates DownloadCreative Suite WebAdobe Reader VistaMicrosoft Windows 7 Home Premium Upgrade 64 BitPhotoshop 2Ie8 Download For Windows 7Photoshop 2009Suite Microsoft OfficeMicrosoft Office 2007 VersionUpgrade Windows Vista To 7Autocad Lt 2010Autocad 2010 Best PriceDownload Acrobat Reader 8 buy Flomax online us pharmacy cheapest Buspar available online where can i purchase Buspar without a prescription sony oem software Valtrex from india Prednisone prescription order Buspar shipped by cash on delivery buy Valtrex with no prescription prezzo Valtrex buy Valtrex shipped cod Proscar no prescription overnight Proscar overnight no consult where to purchase cheap Cytotec no rx Cytotec to buy is it legal to buy Cytotec online in australia buy Cytotec cheapest buy finpecia without prescription finpecia buy cod want to buy finpecia in malaysia buy finpecia with mastercard Buy Finpecia 1 mg online microsoft onenote and educator discount window mirror film charset windows 1252 reinstal windows finpecia overdose excel new window windows for loop microsoft office 2008 for mac home student cheap collection software virtual dj software web design software mac cheap or discount photoshop software load windows xp buy Orlistat legally Rosuvastatin generic order buspar pharmacy buy Flomax in mo dreamweaver cs4 windows mobile opera adobe photoshop price epson creativity suite
Go to Top