templates

What's the best way to generate environment-specific files for a Rails project?

I have some settings I need in a Javascript file -- servers to connect to -- that changes based on my environment. For development, test, and staging, I want to use the staging servers; for production, the production servers. I already have the settings in Ruby (configured in my environment/xyz.rb files). So far, I've been dynamically...

Forward declare method pointer

I am using the pimpl idiom and want to reference one of the methods of the forward declared class. Below isn't exactly what I'm doing but uses the same concepts. template< typename Class, void (Class::*Method)(void) > struct Call { Call( Class* c ) : m_c(c) { } void operator()( void ) { (m_c->*Method)(); } ...

Website Design - Changing only the body content

Currently I am designing a new website and I want to plan it properly. The main page consists of a Top Content (Header including logo etc) The body with the menu on the left and obviously the footer at the end of the page. In the menu I have 50 pages and I want to change ONLY the body content of it. It is not worth it to replicate all...

"Permanent" std::setw

Hi, is there any way how to set std::setw manipulator (or its function 'width') permanently? Look at this: #include <iostream> #include <iomanip> #include <algorithm> #include <iterator> int main( void ) { int array[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256 }; std::cout.fill( '0' ); std::cout.flags( std::ios::hex ); std::cout.wid...

Hiding implementation details on an email templating system written in Python

I am writing an application where one of the features is to allow the user to write an email template using Markdown syntax. Besides formatting, the user must be able to use placeholders for a couple of variables that would get replaced at runtime. The way this is currently working is very simple: the templates have the Pythonic %(var...

simple C++ templates suited for STL Containers

I need a template like this, which work perfectly template <typename container> void mySuperTempalte (const container myCont) { //do something here } then i want to specialize the above template for std::string so i came up with template <typename container> void mySuperTempalte (const container<std::string> myCont) { //check...

Can I use templates instead of macros for Exception class creation?

I often want to define new 'Exception' classes, but need to have an appropriate constructor defined because constructors aren't inherited. class MyException : public Exception { public: MyException (const UString Msg) : Exception(Msg) { }; } Typedefs don't work for this, because they are simply aliases, not new classes. Curre...

Factory method implementation - C++

I have the following code for "factory" design pattern implementation. class Pen{ public: virtual void Draw() = 0; }; class RedPen : public Pen{ public: virtual void Draw(){ cout << "Drawing with red pen" << endl; } }; class BluePen : public Pen{ public: virtual void Draw(){ cout << "Drawing with ...

is it possible to detect pointer-to-member-function?

i want a specialize template in a pointer-to-member-function case. Is there a way to detect this? right now i declare struct isPtrToMemberFunc, then add an extra template (class TType=void) to each class (right now just 1) and specialize the extra template to see if its isPtrToMemberFunc. Is there a way to detect this automatically? if n...

How to Change Default Copyright Template

Whenever I make a new file in xcode, it puts something like this at the top of the file: // Copyright __MyCompanyName__ 2008. All rights reserved. How can I change that to something useful? Update: found the answer here. ...

Converting binary data to printable hex

In this thread some one commented that the following code should only be used in 'toy' projects. Unfortunately he hasn't come back to say why it's not of production quality so I was hoping some one in the community may be able to either assure me the code is ok (because I quite like it) or identify what is wrong. template< class T1, cla...

Any software for pattern-matching and -rewriting source code?

I have some old software (in a language that's not dead but is dead to me ;-)) that implements a basic pattern-matching and -rewriting system for source code. I am considering resurrecting this code, translating it into a modern language, and open-sourcing the project as a refactoring power-tool. Before I go much further, I want to know ...

Django Templates: With Template AutoEscaping on, do I need to pass URLs to URLEncode?

I am running Django trunk and have template Autoescaping on (default). Do I need to pass template URLs to the URLENCODE filter, or does Autoescape take care of that automatically? The Django docs aren't clear. Django docs say this about Autoescape: When auto-escaping is in effect, all variable content has HTML escaping applied to it...

Help to correct source code, with template.

I tried to compile the example posted (http://stackoverflow.com/questions/412165/c-service-providers) and failed to VS8 VC9. I have little experience with template. Any suggestions? Tanks. These are the errors : dictionarystl.cpp(40) : error C2663: 'std::_Tree<_Traits>::find' : 2 overloads have no legal conversion for 'this' pointer dic...

Any drawbacks or gotchas to using Jinja2 templates in Django?

After reading the Jinja2 documentation, I'm interested in employing it in future Django projects. However, I'm wondering if anyone has encountered any drawbacks or gotchas when using Jinja2 templates with Django? If so, how did you work around them? I wouldn't mind hearing about positive experiences either, just to get a good cross se...

Setting iso-8859-1 instead of utf-8 in oscommerce / sts template website ?

In an oscommerce site I have the following: Server response = Content-type: text/html;charset=UTF-8 and I want: Content-type: text/html;charset=ISO-8859-1 How and where do I set this up. Html looks like this on the page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html dir="LTR" lang="nl"> <head> <meta ht...

Trashed Postgres template1

I was screwing around in psql and renamed the template0 and template1 before realizing their usage. Now, I am getting a "permission denied to copy database 'template1'" from inside psql and form command-line when I try to recreate template1. To save time, is there anything else I need to know about template1 vis a vis OS read/write per...

Inheriting from a non-templated class that has a templated constructor - how to resolve ambiguity?

Hello all, Let's say we have a class, MyParent: class MyParent { public: template<namespace T> MyParent() { T* Something; } }; And a derived class, which uses this constructor: class MyDerived : public MyParent { public: MyDerived() : MyParent<int>() { } }; Then I get a compiling error, because there's ambiguit...

Template instantiation with VARIANT return type.

An explicit instantiation of a static template member function keeps failing to compile with the message error C2785: 'at_Intermediate CUtil::convert_variant(const VARIANT &)' and '<Unknown>' have different return types When I make a corresponding class with non-static member functions, the compiler likes me. // utility class - stati...

Can C++ template do this for conditions to improve code?

I want do this: func(conditionA ? pa1 : pa2, conditionB ? pb1 : pb2, conditionC ? pc1 : pc2); In C style function, there is no problem. But if func() is a template function, compiler will report errors. Here pa1 and pa2, ... are different class and have a static method - "convert()". convert() is also declared as inline for performance ...