+ Reply to Thread
Results 1 to 9 of 9

Thread: Help with singleton patern!!(pool management project)

  1. #1
    Newbie KivraS is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    6

    Help with singleton patern!!(pool management project)

    Hello there and nice to meet you all!!!I just registered in your forum.And i intend to be an active user.
    I am a 22 yo University student from greece!


    I was assigned to develop a PoolManagement library for a lesson in c++
    The programm supose to open a X number of connections in a database
    and handle them to the main programm( multiple connection asked by threads) for doing general use cases as insert update etc etc.

    The problem i have (well the most annoying of many many others)
    was when i tryied to aplly the singleton patern to the poolManager class
    So there can be only one class for a single database

    I made a map<> to store all pool managers for diferent databases
    Well after doiing so i had tones of errors!! When i solved them another 25 errors apeared.......and became an error labyrinth!!!

    I upoloaded the project on rapidshare if someone wants to check it
    Its a visual studio 2008 file.

    rapidshare.com/files/242455885/DB_poolManager_exception_.rar

    I am in a desperate condition i have a week to deliver the project
    and i will not pass the lesson if i dont do so! HELPP!!!!


    else the code is


    MAIN function
    Code:
    // conDB.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include "poolManager.h"
    #include "dataHandler.h"
    #include <conio.h>
    #include <stdio.h>
    #include <iostream>
    #include <process.h>
    #include <windows.h>
    #include <vector>
    using namespace std;
    
    int main()
    {
    	//_RecordsetPtr pointerRec;
    	//_bstr_t stringConn;
    	//poolManager *pool;
    	//pool=poolManager::getInstance("ena");
    	int epil=0;
    	string database;
    	map<string,Handler*> handlers;
    	vector<HANDLE> threads;
    
    	cout<<"1-Eisagogi dedomenon";
    	cout<<"2-Anagnosi dedomenon";
    	
    	switch(epil)
    	{	
    	case 1:
    	cout<<"dose vasi dedomenon";
    	getline(cin,database);
    	if (handlers.find(database) == false)
    	{
    		handlers[database]= new Handler(database);
    	}
    	
    
    	break;
    	case 2:
    	cout<<"dose vasi dedomenon:";
    	getline(cin,database);
    	break;
    	default:
    	cout<<"lathos epilogi";
    	break;
    	}
    
    
    	
    	
    
    
    }


    class poolmanager .H

    Code:
    #ifndef POOLMANAGER_H
    #define POOLMANAGER_H
    #include "stdafx.h"
    #include <iostream>
    #include <process.h>
    #include <windows.h>
    #include <map>
    #import "c:\Program Files\Common Files\System\ado\msado15.dll" \
    	no_namespace rename("EOF", "EndOfFile")
    #include <conio.h>
    #include <stdio.h>
    #include <string>
    #include "Connection.h"
    const int N=3;
    using namespace std;
    
    class poolManager
    {
    	public:
    		
    		
    		static poolManager* getInstance(string name);
    		~poolManager();
    		void createConnections(_RecordsetPtr pRst, _bstr_t strCnn);
    		class ConnectionCl giveConnection();
    		void getStats();
    		void returnConnection(class ConnectionCl a);
    		
    	private:
    		
    		poolManager(string dbName);
    			static map<string,poolManager*> pm;
    		string dbName;
    		ConnectionCl ConTable[N];
    		int openedConnections;
    		int freeConnections;
    		bool connectionFree;
    		bool isFree[N];
    		CRITICAL_SECTION crit;
    		
    
    };
    
    #endif


    Class pool manager cpp
    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <conio.h>
    #include <stdio.h>
    #include <vector>
    
    #include "poolManager.h"
    
    
    using namespace std;
    
    
    poolManager* poolManager::getInstance(string name)
    {
    	if( pm.find(name)==false)
    	{
    		poolManager *poolM = new poolManager(name);
    		pm[name]=poolM;
    		
    	}
    	return pm[name];
    
    	}
    
    poolManager::poolManager(string name)
    {	
    	InitializeCriticalSection(&crit);
    	int i;
    	dbName=name;
    	connectionFree=true;
    	openedConnections=0;
    	freeConnections=N;
    	for(i=0;i<N;i++)
    	{
    		isFree[i]=true;
    		ConTable[N].create(name);
    		ConTable[N].setIndex(N);
    	}
    	cout<<"Etrekse o constructor"<<endl;
    }
    
    poolManager::~poolManager()
    {
    	DeleteCriticalSection(&crit);
    }
    
    
    
    
    void poolManager::createConnections(_RecordsetPtr pRst, _bstr_t strCnn)
    {
    
    	
    
    
    
    }
    
    
    void poolManager::returnConnection(class ConnectionCl a)
    {
    		int tmpIndex;
    		tmpIndex=a.getIndex();
    		isFree[tmpIndex]=true;
    		freeConnections++;
    
    }
    
    void poolManager::getStats()
    {
    
    	cout<<"oi eleftheres sindeseis einai"<<freeConnections;
    
    
    }
    
    ConnectionCl poolManager::giveConnection()
    {
    
    	int FreeConIndex=0;
    	bool found=false;
    	while((found==false)&&(FreeConIndex<N))
    	{
    		if(isFree[FreeConIndex]==true)
    		{
    			found =true;
    			isFree[FreeConIndex]=false;
    			freeConnections--;
    		}
    		else
    		{
    			FreeConIndex++;
    		}
    	}
    	if(found==true)
    	return ConTable[FreeConIndex];
    	//else
    	//Epistrofi error
    
    }
    Last edited by KivraS; 06-09-2009 at 07:15 PM.

  2. #2
    Code Warrior dargueta has much to be proud of dargueta has much to be proud of dargueta has much to be proud of dargueta has much to be proud of dargueta has much to be proud of dargueta has much to be proud of dargueta has much to be proud of dargueta has much to be proud of dargueta's Avatar
    Join Date
    Oct 2007
    Age
    19
    Posts
    2,839
    Blog Entries
    8

    Re: Help with singleton patern!!(pool management project)

    For those of us who don't have Visual Studio - what errors exactly are you getting?
    Coding without commenting is like throwing up. You're making a mess.

  3. #3
    Newbie KivraS is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    6

    Re: Help with singleton patern!!(pool management project)

    Well the errors are these.....
    When i formed the singleton patern they apeared!





    Code:
    ------ Build started: Project: DB_poolManager, Configuration: Debug Win32 ------
    Compiling...
    poolManager.cpp
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(25) : error C2275: 'std::string' : illegal use of this type as an expression
            c:\program files\microsoft visual studio 9.0\vc\include\xstring(2210) : see declaration of 'std::string'
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(25) : error C2146: syntax error : missing ')' before identifier 'name'
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(25) : error C2059: syntax error : ')'
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(26) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(28) : error C2597: illegal reference to non-static member 'poolManager::dbName'
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(29) : error C2597: illegal reference to non-static member 'poolManager::connectionFree'
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(30) : error C2597: illegal reference to non-static member 'poolManager::openedConnections'
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(31) : error C2597: illegal reference to non-static member 'poolManager::freeConnections'
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(34) : error C2597: illegal reference to non-static member 'poolManager::isFree'
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(34) : error C3867: 'poolManager::isFree': function call missing argument list; use '&poolManager::isFree' to create a pointer to member
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(34) : error C2109: subscript requires array or pointer type
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(35) : error C2597: illegal reference to non-static member 'poolManager::ConTable'
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(35) : error C3867: 'poolManager::ConTable': function call missing argument list; use '&poolManager::ConTable' to create a pointer to member
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(35) : error C2109: subscript requires array or pointer type
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(35) : error C2228: left of '.create' must have class/struct/union
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(36) : error C2597: illegal reference to non-static member 'poolManager::ConTable'
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(36) : error C3867: 'poolManager::ConTable': function call missing argument list; use '&poolManager::ConTable' to create a pointer to member
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(36) : error C2109: subscript requires array or pointer type
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(36) : error C2228: left of '.setIndex' must have class/struct/union
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(41) : error C2352: 'poolManager::~poolManager' : illegal call of non-static member function
            c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.h(21) : see declaration of 'poolManager::~poolManager'
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(42) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(50) : error C2601: 'poolManager::createConnections' : local function definitions are illegal
            c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(16): this line contains a '{' which has not yet been matched
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(60) : error C2601: 'poolManager::returnConnection' : local function definitions are illegal
            c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(16): this line contains a '{' which has not yet been matched
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(69) : error C2601: 'poolManager::getStats' : local function definitions are illegal
            c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(16): this line contains a '{' which has not yet been matched
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(77) : error C2601: 'poolManager::giveConnection' : local function definitions are illegal
            c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(16): this line contains a '{' which has not yet been matched
    c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(100) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\kivras\desktop\db_poolmanager(exception)\poolmanager.cpp(16)' was matched
    Build log was saved at "file://c:\Documents and Settings\KivraS\Desktop\DB_poolManager(exception)\Debug\BuildLog.htm"
    DB_poolManager - 26 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  4. #4
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,673
    Blog Entries
    57

    Re: Help with singleton patern!!(pool management project)

    Is there a reason why you made your constructor private? You'll never be able to use it.
    CodeCall Blog | CodeCall Wiki | Shareware
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  5. #5
    Newbie KivraS is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    6

    Re: Help with singleton patern!!(pool management project)

    Quote Originally Posted by WingedPanther View Post
    Is there a reason why you made your constructor private? You'll never be able to use it.
    Well thats the singleton patern.
    I make the constructor private so only the getInstance function can call the constructor after it cheks there isnt any other same class defined

  6. #6
    Newbie KivraS is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    6

    Re: Help with singleton patern!!(pool management project)

    i just found the silly error caused the other 24!~!
    sytax error was.....

    But still have this error now

    Code:
    poolManager.obj : error LNK2001: unresolved external symbol "private: static class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class poolManager *,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class poolManager *> > > poolManager::pm" (?pm@poolManager@@0V?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAVpoolManager@@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAVpoolManager@@@std@@@2@@std@@A)
    C:\Documents and Settings\KivraS\Desktop\DB_poolManager(exception)\Debug\DB_poolManager.exe : fatal error LNK1120: 1 unresolved externals

  7. #7
    Code Warrior dargueta has much to be proud of dargueta has much to be proud of dargueta has much to be proud of dargueta has much to be proud of dargueta has much to be proud of dargueta has much to be proud of dargueta has much to be proud of dargueta has much to be proud of dargueta's Avatar
    Join Date
    Oct 2007
    Age
    19
    Posts
    2,839
    Blog Entries
    8

    Re: Help with singleton patern!!(pool management project)

    Uuuugly. Could you post the fixed code? I think you're not linking to something you should be. First try cleaning the project; I believe it's Build > Clean Project or something like that. After that try recompiling. If it still gives you the error, let us know.

    (Alternatively you defined a function somewhere and forgot to implement it.)
    Coding without commenting is like throwing up. You're making a mess.

  8. #8
    Newbie KivraS is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    6

    Re: Help with singleton patern!!(pool management project)

    Quote Originally Posted by dargueta View Post
    Uuuugly. Could you post the fixed code? I think you're not linking to something you should be. First try cleaning the project; I believe it's Build > Clean Project or something like that. After that try recompiling. If it still gives you the error, let us know.

    (Alternatively you defined a function somewhere and forgot to implement it.)
    Ok i updated the code in the fields.
    I tryed to clean and rebuild but i get the same error.
    The linker error 2001 again....

  9. #9
    Newbie KivraS is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    6

    Re: Help with singleton patern!!(pool management project)

    The problem solved .
    Just to mention


    I just needed to declare the map<string,poolManager>
    Inside the getInstance function not inside the class!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Replies: 7
    Last Post: 07-27-2009, 06:43 AM
  2. Project 1 - Game Network 1.0
    By Donovan in forum C and C++
    Replies: 19
    Last Post: 06-21-2009, 06:23 AM
  3. Replies: 8
    Last Post: 05-30-2009, 11:56 AM
  4. Send image one project to another ?
    By nomanforu in forum C# Programming
    Replies: 0
    Last Post: 06-03-2008, 12:12 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts