WvStreams
catmgr.cc
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  *
3  * XPLC - Cross-Platform Lightweight Components
4  * Copyright (C) 2003, Net Integration Technologies, Inc.
5  * Copyright (C) 2003, Pierre Phaneuf
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20  * USA
21  */
22 
23 #include <assert.h>
24 #include <xplc/utils.h>
25 #include <xplc/uuidops.h>
26 #include "catmgr.h"
27 #include "category.h"
28 
33 
34 CategoryManager::CategoryManager():
35  categories(0) {
36 }
37 
38 CategoryManager::~CategoryManager() {
39  if(categories)
40  delete categories;
41 }
42 
44  const UUID& aUuid,
45  const char* aString) {
46  CategoryNode* cat;
47  CategoryEntryNode* entry;
48 
49  for(cat = categories; cat; cat = cat->next) {
50  if(cat->category == aCatid)
51  break;
52  }
53 
54  if(!cat) {
55  cat = new CategoryNode(aCatid, categories);
56  categories = cat;
57  }
58 
59  assert(cat);
60 
61  for(entry = cat->entries; entry; entry = entry->next) {
62  if(entry->entry == aUuid)
63  return;
64  }
65 
66  entry = new CategoryEntryNode(aUuid, aString, cat->entries);
67  assert(entry);
68 
69  cat->entries = entry;
70 }
71 
73  CategoryNode* cat;
74 
75  for(cat = categories; cat; cat = cat->next) {
76  if(cat->category == aUuid)
77  return new Category(this, cat->entries);
78  }
79 
80  return new Category(this, NULL);
81 }
82 
Category
Definition: category.h:28
UUID_MAP_ENTRY
#define UUID_MAP_ENTRY(iface)
Add an entry to an interface map.
Definition: utils.h:68
ICategory
Represents a category.
Definition: ICategory.h:36
UUID_MAP_BEGIN
#define UUID_MAP_BEGIN(component)
Start the interface map for "component".
Definition: utils.h:63
CategoryEntryNode
Definition: categorynode.h:28
CategoryManager
Definition: catmgr.h:29
ICategoryManager
Definition: ICategoryManager.h:37
utils.h
CategoryManager::registerComponent
virtual void registerComponent(const UUID &, const UUID &, const char *)
Register a component with a category.
Definition: catmgr.cc:43
CategoryNode
Definition: categorynode.h:48
UUID_MAP_END
#define UUID_MAP_END
Marks the end of an interface map.
Definition: utils.h:80
IObject
Definition: IObject.h:65
_GUID
The structure underlying UUIDs.
Definition: uuid.h:94
CategoryManager::getCategory
virtual ICategory * getCategory(const UUID &)
Get a category object for the specified category.
Definition: catmgr.cc:72