summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjoye <joye>2014-07-09 20:42:12 (GMT)
committerjoye <joye>2014-07-09 20:42:12 (GMT)
commite8f7d5d9c556871a7800f444f4231ea140216bee (patch)
tree3ee139b59bfaaf7b399d5d0cf4a4ee17916c2c68 /src
parentc00cc63dc2546a1aff16c3530596278ba495f5e3 (diff)
downloadblt-e8f7d5d9c556871a7800f444f4231ea140216bee.zip
blt-e8f7d5d9c556871a7800f444f4231ea140216bee.tar.gz
blt-e8f7d5d9c556871a7800f444f4231ea140216bee.tar.bz2
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r--src/bltChain.C117
-rw-r--r--src/bltChain.h37
-rw-r--r--src/bltGrElemBar.C2
-rw-r--r--src/bltGrElemLine.C2
-rw-r--r--src/bltGrElemOption.C4
5 files changed, 84 insertions, 78 deletions
diff --git a/src/bltChain.C b/src/bltChain.C
index 3449479..3000b15 100644
--- a/src/bltChain.C
+++ b/src/bltChain.C
@@ -33,10 +33,31 @@
using namespace Blt;
-#ifndef ALIGN
-#define ALIGN(a) \
- (((size_t)a + (sizeof(double) - 1)) & (~(sizeof(double) - 1)))
-#endif
+// ChainLink
+
+ChainLink::ChainLink(void* clientData)
+{
+ prev_ =NULL;
+ next_ =NULL;
+ manage_ =0;
+ clientData_ = clientData;
+}
+
+ChainLink::ChainLink(size_t ss)
+{
+ prev_ =NULL;
+ next_ =NULL;
+ manage_ =1;
+ clientData_ = (void*)calloc(1,ss);
+}
+
+ChainLink::~ChainLink()
+{
+ if (manage_ && clientData_)
+ free(clientData_);
+}
+
+// Chain
Chain::Chain()
{
@@ -50,8 +71,8 @@ Chain::~Chain()
ChainLink* linkPtr = head_;
while (linkPtr) {
ChainLink* oldPtr =linkPtr;
- linkPtr = linkPtr->next;
- free(oldPtr);
+ linkPtr = linkPtr->next_;
+ delete oldPtr;
}
}
@@ -60,8 +81,8 @@ void Chain::reset()
ChainLink* linkPtr = head_;
while (linkPtr) {
ChainLink* oldPtr = linkPtr;
- linkPtr = linkPtr->next;
- free(oldPtr);
+ linkPtr = linkPtr->next_;
+ delete oldPtr;
}
head_ =NULL;
tail_ =NULL;
@@ -76,19 +97,19 @@ void Chain::linkAfter(ChainLink* linkPtr, ChainLink* afterPtr)
}
else {
if (!afterPtr) {
- linkPtr->next = NULL;
- linkPtr->prev = tail_;
- tail_->next = linkPtr;
+ linkPtr->next_ = NULL;
+ linkPtr->prev_ = tail_;
+ tail_->next_ = linkPtr;
tail_ = linkPtr;
}
else {
- linkPtr->next = afterPtr->next;
- linkPtr->prev = afterPtr;
+ linkPtr->next_ = afterPtr->next_;
+ linkPtr->prev_ = afterPtr;
if (afterPtr == tail_)
tail_ = linkPtr;
else
- afterPtr->next->prev = linkPtr;
- afterPtr->next = linkPtr;
+ afterPtr->next_->prev_ = linkPtr;
+ afterPtr->next_ = linkPtr;
}
}
@@ -103,19 +124,19 @@ void Chain::linkBefore(ChainLink* linkPtr, ChainLink* beforePtr)
}
else {
if (beforePtr == NULL) {
- linkPtr->next = head_;
- linkPtr->prev = NULL;
- head_->prev = linkPtr;
+ linkPtr->next_ = head_;
+ linkPtr->prev_ = NULL;
+ head_->prev_ = linkPtr;
head_ = linkPtr;
}
else {
- linkPtr->prev = beforePtr->prev;
- linkPtr->next = beforePtr;
+ linkPtr->prev_ = beforePtr->prev_;
+ linkPtr->next_ = beforePtr;
if (beforePtr == head_)
head_ = linkPtr;
else
- beforePtr->prev->next = linkPtr;
- beforePtr->prev = linkPtr;
+ beforePtr->prev_->next_ = linkPtr;
+ beforePtr->prev_ = linkPtr;
}
}
@@ -129,83 +150,57 @@ void Chain::unlinkLink(ChainLink* linkPtr)
unlinked = 0;
if (head_ == linkPtr) {
- head_ = linkPtr->next;
+ head_ = linkPtr->next_;
unlinked = 1;
}
if (tail_ == linkPtr) {
- tail_ = linkPtr->prev;
+ tail_ = linkPtr->prev_;
unlinked = 1;
}
- if (linkPtr->next) {
- linkPtr->next->prev = linkPtr->prev;
+ if (linkPtr->next_) {
+ linkPtr->next_->prev_ = linkPtr->prev_;
unlinked = 1;
}
- if (linkPtr->prev) {
- linkPtr->prev->next = linkPtr->next;
+ if (linkPtr->prev_) {
+ linkPtr->prev_->next_ = linkPtr->next_;
unlinked = 1;
}
if (unlinked)
nLinks_--;
- linkPtr->prev =NULL;
- linkPtr->next =NULL;
+ linkPtr->prev_ =NULL;
+ linkPtr->next_ =NULL;
}
void Chain::deleteLink(ChainLink* link)
{
unlinkLink(link);
- free(link);
+ delete link;
link = NULL;
}
ChainLink* Chain::append(void* clientData)
{
- ChainLink* link = Chain_NewLink();
+ ChainLink* link = new ChainLink(clientData);
linkAfter(link, NULL);
- Chain_SetValue(link, clientData);
return link;
}
ChainLink* Chain::prepend(void* clientData)
{
- ChainLink* link = Chain_NewLink();
+ ChainLink* link = new ChainLink(clientData);
linkBefore(link, NULL);
- Chain_SetValue(link, clientData);
return link;
}
-ChainLink* Blt::Chain_AllocLink(size_t extraSize)
-{
- size_t linkSize = ALIGN(sizeof(ChainLink));
- ChainLink* linkPtr = (ChainLink*)calloc(1, linkSize + extraSize);
- if (extraSize > 0) {
- // Point clientData at the memory beyond the normal structure
- linkPtr->clientData = ((char *)linkPtr + linkSize);
- }
-
- return linkPtr;
-}
-
-void Blt::Chain_InitLink(ChainLink* linkPtr)
-{
- linkPtr->clientData = NULL;
- linkPtr->next = linkPtr->prev = NULL;
-}
-
-ChainLink* Blt::Chain_NewLink(void)
-{
- ChainLink* linkPtr = (ChainLink*)malloc(sizeof(ChainLink));
- linkPtr->clientData = NULL;
- linkPtr->next = linkPtr->prev = NULL;
- return linkPtr;
-}
int Blt::Chain_IsBefore(ChainLink* firstPtr, ChainLink* lastPtr)
{
- for (ChainLink* linkPtr = firstPtr; linkPtr; linkPtr = linkPtr->next)
+ for (ChainLink* linkPtr = firstPtr; linkPtr; linkPtr = linkPtr->next())
if (linkPtr == lastPtr)
return 1;
return 0;
}
+
diff --git a/src/bltChain.h b/src/bltChain.h
index df55c7c..2969d55 100644
--- a/src/bltChain.h
+++ b/src/bltChain.h
@@ -35,18 +35,33 @@
#define Chain_GetLength(c) (((c) == NULL) ? 0 : (c)->nLinks())
#define Chain_FirstLink(c) (((c) == NULL) ? NULL : (c)->head())
#define Chain_LastLink(c) (((c) == NULL) ? NULL : (c)->tail())
-#define Chain_PrevLink(l) ((l)->prev)
-#define Chain_NextLink(l) ((l)->next)
-#define Chain_GetValue(l) ((l)->clientData)
-#define Chain_FirstValue(c) (((c)->head == NULL) ? NULL : (c)->head->clientData)
-#define Chain_SetValue(l, v) ((l)->clientData = (void*)(v))
+
+#define Chain_PrevLink(l) ((l)->prev())
+#define Chain_NextLink(l) ((l)->next())
+#define Chain_GetValue(l) ((l)->clientData())
namespace Blt {
- struct ChainLink {
- ChainLink* prev;
- ChainLink* next;
- void* clientData;
+ class Chain;
+
+ class ChainLink {
+ friend class Chain;
+
+ protected:
+ ChainLink* prev_;
+ ChainLink* next_;
+ int manage_;
+ void* clientData_;
+
+ public:
+ ChainLink(void*);
+ ChainLink(size_t);
+ virtual ~ChainLink();
+
+ ChainLink* prev() {return prev_;}
+ ChainLink* next() {return next_;}
+ void* clientData() {return clientData_;}
+ void setClientData(void* d) {clientData_ =d;}
};
class Chain {
@@ -72,10 +87,6 @@ namespace Blt {
ChainLink* prepend(void* clientData);
};
- extern ChainLink* Chain_AllocLink(size_t size);
- extern void Chain_InitLink(ChainLink* link);
- extern void Chain_Init(Chain* chain);
- extern ChainLink* Chain_NewLink(void);
extern int Chain_IsBefore(ChainLink* first, ChainLink* last);
};
diff --git a/src/bltGrElemBar.C b/src/bltGrElemBar.C
index ed5ca77..3efb206 100644
--- a/src/bltGrElemBar.C
+++ b/src/bltGrElemBar.C
@@ -236,7 +236,7 @@ int BarElement::configure()
// Point to the static normal pen if no external pens have been selected.
ChainLink* link = Chain_FirstLink(ops->stylePalette);
if (!link) {
- link = Chain_AllocLink(sizeof(BarStyle));
+ link = new ChainLink(sizeof(BarStyle));
ops->stylePalette->linkAfter(link, NULL);
}
BarStyle* stylePtr = (BarStyle*)Chain_GetValue(link);
diff --git a/src/bltGrElemLine.C b/src/bltGrElemLine.C
index b8e37a1..e28f775 100644
--- a/src/bltGrElemLine.C
+++ b/src/bltGrElemLine.C
@@ -290,7 +290,7 @@ int LineElement::configure()
// selected.
ChainLink* link = Chain_FirstLink(ops->stylePalette);
if (!link) {
- link = Chain_AllocLink(sizeof(LineStyle));
+ link = new ChainLink(sizeof(LineStyle));
ops->stylePalette->linkAfter(link, NULL);
}
LineStyle* stylePtr = (LineStyle*)Chain_GetValue(link);
diff --git a/src/bltGrElemOption.C b/src/bltGrElemOption.C
index 27c7d08..8fdad62 100644
--- a/src/bltGrElemOption.C
+++ b/src/bltGrElemOption.C
@@ -242,14 +242,14 @@ int StyleSetProc(ClientData clientData, Tcl_Interp* interp,
elemPtr->freeStylePalette(stylePalette);
ChainLink* link = Chain_FirstLink(stylePalette);
if (!link) {
- link = Chain_AllocLink(size);
+ link = new ChainLink(size);
stylePalette->linkAfter(link, NULL);
}
PenStyle* stylePtr = (PenStyle*)Chain_GetValue(link);
stylePtr->penPtr = NORMALPEN(ops);
for (int ii = 0; ii<objc; ii++) {
- link = Chain_AllocLink(size);
+ link = new ChainLink(size);
stylePtr = (PenStyle*)Chain_GetValue(link);
stylePtr->weight.min = (double)ii;
stylePtr->weight.max = (double)ii + 1.0;