OSDN Git Service

alpha 1 development in progress.
[dennco/dennco.git] / Source / TKContainer.cpp
1 //  Copyright (c) 2012 Dennco Project
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 //
17 //  Created by tkawata on 12/11/2011.
18 //
19
20 #include "TKContainer.h"
21 #include "TKCell.h"
22 #include "DNStorage.h"
23 #include "DNUtils.h"
24
25 TKContainer::~TKContainer()
26 {
27     doDestroy();
28     releaseDataStore();
29 }
30
31 bool TKContainer::doTick(float time)
32 {
33     mLock.lock();
34     for ( TKCellMap::iterator it = mCells.begin(); it != mCells.end(); ++it ) {
35         it->second->doTick(time);
36     }
37     mLock.unlock();
38     return true;
39 }
40
41 bool TKContainer::doDestroy()
42 {
43     mLock.lock();
44
45     for ( TKCellMap::iterator it = mCells.begin(); it != mCells.end(); ++it ) {
46         (it->second)->doDestroy();
47     }
48     for ( TKCellMap::iterator it = mCells.begin(); it != mCells.end(); ++it ) {
49         delete it->second;
50     }
51     mCells.clear();
52     mInterfaceCells.clear();
53
54     mLock.unlock();
55     return true;
56 }
57
58 bool TKContainer::setDataStore(std::string storagePath)
59 {
60     mStorage = new DNStorage(storagePath.c_str());
61     return mStorage->isValid();
62 }
63
64 bool TKContainer::releaseDataStore()
65 {
66     mLock.lock();
67     if (mStorage)
68     {
69         delete mStorage;
70         mStorage = NULL;
71     }
72     mLock.unlock();
73     return true;
74 }
75
76 TKCell* TKContainer::getCell(std::string theFQNName)
77 {
78     TKCellMap::iterator it = mCells.find(theFQNName);
79     if (it == mCells.end())
80     {
81         return NULL;
82     }
83     else
84     {
85         return it->second;
86     }
87 }
88
89 TKCell* TKContainer::getInterfaceCell(std::string theFQNName)
90 {
91     DNLocker locker(&mLock);
92
93     if (mInterfaceCells.empty())
94     {
95         return NULL;
96     }
97     TKCellMap::iterator it = mInterfaceCells.find(theFQNName);
98     if (it == mInterfaceCells.end())
99     {
100         return NULL;
101     }
102     else
103     {
104         return it->second;
105     }
106 }
107
108 TKCellCode* TKContainer::getCellCode(std::string theCellCodeName)
109 {
110     TKCellCodeMap::iterator it = mCellCodes.find(theCellCodeName);
111     if (it == mCellCodes.end())
112     {
113         return NULL;
114     }
115     else
116     {
117         return it->second;
118     }
119 }