Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
J

Jessn

@Jessn
About
Posts
4
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Singleton class
    J Jessn

    Singleton! Intent Ensure a class only has one instance, and provide a global point of access to it. Motivation It's important for some classes to have exactly one instance. Although there can be many printers in a system, there should be only one printer spooler. There should be only one file system and one window manager. A digital filter will have one A/D converter. An accounting system will be dedicated to serving one company. How do we ensure that a class has only one instance and that the instance is easily accessible? A global variable makes an object accessible, but it doesn't keep you from instantiating multiple objects. A better solution is to make the class itself responsible for keeping track of its sole instance. The class can ensure that no other instance can be created (by intercepting requests to create new objects), and it can provide a way to access the instance. This is the Singleton pattern.

    class CSingleton
    {
    public:
    static CSingleton * getInstance() {
    if (!_singleton) _singleton = new CSingleton;
    return _singleton;
    }

    protected:
    CSingleton() { }
    ~CSingleton() { }

    private:
    static CSingleton * _singleton;
    };

    CSingleton* CSingleton ::_singleton = NULL;

    Try to look at singleton destroyers too especially when you singleton holds a database connection or similar resources. You can also create a SINGLETON TEMPLATE like the one below. In this way your singleton holds a pointer and it ensures that only one instance exists of the object the pointer is pointing at.

    template < typename T >
    class CSingleton
    {
    public:
    static CSingleton * getInstance() {
    if (!_singleton) _singleton = new CSingleton;
    return _singleton;
    }

    // Access to the pointer, but NOT the singleton itself
    const T* operator->() { return m_ptr; };

    protected:
    CSingleton() { m_ptr = new T; }
    ~CSingleton() { if (m_ptr) delete m_ptr; }

    private:
    static CSingleton * _singleton;
    T * m_ptr;
    };

    Hth

    -- Jess Nielsen, b.sc. Security Analyst http://jessn.blogspot.com/

    C / C++ / MFC question tutorial

  • Multiple database support
    J Jessn

    heyitsAtul wrote:

    Hi, Can anyone suggest how to design application, which support multiple databases (like SQL Server, Oracle) and with minimum change, we can shift database from one to another. Thanks.

    It can be done in several ways. First of all you need to have an abstraction layer. That layer needs to be a generic layer that matches the interface for both databases. Secondly, I'll recommend that use a factory. Try to take a look at the following link for inspiration: Connection pool[^] HTH

    -- Jess Nielsen, b.sc. Security Analyst http://jessn.blogspot.com/

    modified on Monday, November 8, 2010 3:20 AM

    Design and Architecture database sql-server oracle design sysadmin

  • Multiple database support
    J Jessn

    heyitsAtul wrote:

    Hi, Can anyone suggest how to design application, which support multiple databases (like SQL Server, Oracle) and with minimum change, we can shift database from one to another. Thanks.

    It can be done in several ways. First of all you need to have an abstraction layer. That layer needs to be a generic layer that matches the interface for both databases. Secondarily, I'll recommend that use a factory. Try to take a look at the following link for inspiration Connection pool[^] Hth

    -- Jess Nielsen, b.sc. Security Analyst http://jessn.blogspot.com/

    Design and Architecture database sql-server oracle design sysadmin

  • CInternetSession.OpenURL on Windows Mobile fails
    J Jessn

    Hi there I am trying to establish an Internet session (HTTP GET) with a MFC application on a Windows Mobile 6 platform. First I tried with OpenRequest() and SendRequest(), but when the code reached SendRequest () the application crashed in the evil way. Secondily I tried to use OpenURL() but it keeps saying that it cannot find the server. I have even connected the device to my WLAN to ensure I had a stable Internet connection.

    CString GoogleMap::getMapUrl(int width, int height, double lng, double
    lat, int zoom, CString format)
    {
    char * szUrl = (char*)malloc(256);
    char * szFormat = "http://maps.google.com/staticmap?center=%f,%f&format=%s&zoom=%d&size=%dx%d&key=%s";

    sprintf(szUrl, szFormat, lat, lng, format, zoom, width, height,m_szAPIKey);
    CString s = CString(szUrl);
    return s;
    }

    BYTE* GoogleMap::loadHttpFile(CString url, long &length)
    {
    BYTE* buffer = NULL;
    CInternetSession session;
    CHttpConnection * hc = NULL;

    hc = session.GetHttpConnection(_T("maps.google.com"), 0, 80, NULL,NULL);
    if (!hc) return NULL;
    //CHttpFile* pFile = hc->OpenRequest(CHttpConnection::HTTP_VERB_GET,_T("index.html"));
    //pFile->SendRequest();
    CHttpFile* pFile = (CHttpFile*)session.OpenURL(url); // FAILS!!!

    length = (long)pFile->GetLength();
    if (!length) return NULL;
    buffer = (BYTE*)malloc(length + 1);
    memset(buffer, 0, length +1);
    for ( DWORD dwRead1;dwRead1=pFile->Read(buffer,length); );
    return buffer;
    }

    Could someone please tell me what I do wrong? Thanks in advance, Jess -- Jess Nielsen, b.sc. Security Analyst http://jessn.blogspot.com/

    C / C++ / MFC c++ html database com sysadmin
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups