Closed Thread
Results 1 to 9 of 9

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

  1. #1
    KivraS is offline Newbie
    Join Date
    Jun 2009
    Posts
    7
    Rep Power
    0

    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 05:15 PM.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

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

    For those of us who don't have Visual Studio - what errors exactly are you getting?
    sudo rm -rf /

  4. #3
    KivraS is offline Newbie
    Join Date
    Jun 2009
    Posts
    7
    Rep Power
    0

    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 ==========

  5. #4
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    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.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  6. #5
    KivraS is offline Newbie
    Join Date
    Jun 2009
    Posts
    7
    Rep Power
    0

    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

  7. #6
    KivraS is offline Newbie
    Join Date
    Jun 2009
    Posts
    7
    Rep Power
    0

    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

  8. #7
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    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.)
    sudo rm -rf /

  9. #8
    KivraS is offline Newbie
    Join Date
    Jun 2009
    Posts
    7
    Rep Power
    0

    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....

  10. #9
    KivraS is offline Newbie
    Join Date
    Jun 2009
    Posts
    7
    Rep Power
    0

    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!

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Sociallinked - Internal Project Developers & Engineers & Management
    By Bioshox in forum Member Software/Projects
    Replies: 0
    Last Post: 11-10-2010, 03:39 AM
  2. Online Developer Project Management, Ideas
    By Peter Kelly in forum General Programming
    Replies: 5
    Last Post: 08-27-2010, 01:35 AM
  3. Network management project. HELP!
    By airborne in forum Visual Basic Programming
    Replies: 1
    Last Post: 05-03-2010, 05:22 AM
  4. Software Project Management
    By Shaddix in forum The Lounge
    Replies: 1
    Last Post: 12-04-2009, 10:01 PM

Tags for this Thread

Bookmarks

Posting Permissions

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