view anagram/support/agref.h @ 6:607e3be6bad8

Adjust to the moving target called the C++ standard. Apparently nowadays it's not allowed to define an explicit copy constructor but not an assignment operator. Consequently, defining the explicit copy constructor in terms of the implicit/automatic assignment operator for general convenience no longer works. Add assignment operators. Caution: not tested with the IBM compiler, but there's no particular reason it shouldn't work.
author David A. Holland
date Mon, 30 May 2022 23:46:22 -0400
parents 13d2b8934445
children
line wrap: on
line source

/**********************************************************

The AnaGram Class Library

The AgReference Class
Copyright 1997 Parsifal Software. All Rights Reserved.
See the file COPYING for license and usage terms.

***********************************************************/


#ifndef AGREF_H
#define AGREF_H

#include "assert.h"


class AgReferenceCount {
private:
  int count;
public:
  AgReferenceCount()
    : count(0)
  {}
  virtual ~AgReferenceCount() {
    assert(count == 0);
  }
  inline AgReferenceCount(const AgReferenceCount &) : count(0) {}
  inline AgReferenceCount &operator = (const AgReferenceCount &) {
    return *this;
  }
  inline void lock()  {
    count++;
  }
  inline int unlock() {
/*
    if (count <= 0) {
      LOGSECTION("AgReferenceCount::unlock");
      LOGV(count);
    }
*/
    assert(count > 0);
    return (--count <= 0);
  }
};

class AgReferenceBase {
protected:
  AgReferenceCount *object;
  void doAssignmentLocks(const AgReferenceBase &r); /* {
    if (object!=0  && object->unlock()) delete object;
    object = r.object;
    if (object != 0) object->lock();
  }
*/
public:
  AgReferenceBase();// : object(0) {}
  AgReferenceBase(AgReferenceCount* object_);
  AgReferenceBase(const AgReferenceBase &r);
  virtual ~AgReferenceBase();
  int exists() const;
  void discardData();
/*
  AgReferenceBase(AgReferenceCount* object_)
    : object(object_)
  {
    if (object != 0) object->lock();
  }
  AgReferenceBase(const AgReferenceBase &r)
    : object(r.object)
  {
    if (object!= 0) object->lock();
  }
  virtual ~AgReferenceBase() {
    if (object!= 0 && object->unlock()) delete object;
  }

  int exists() const {
    return object != 0;
  }
  void discardData() {
    if (object && object->unlock()) delete object;
    object = 0;
  }
*/
};
/*
template <class T>
class AgReference : public AgReferenceBase {
public:
  inline AgReference() : AgReferenceBase() {}
  inline AgReference(T *x) : AgReferenceBase(x) {}
  inline AgReference(const AgReference<T> &r)
    : AgReferenceBase((const AgReferenceBase &)r)
  {}
  inline AgReference<T> &operator = (const AgReference<T> &t) {
    doAssignmentLocks(t);
    return *this;
  }
  inline T *operator -> () const {
    return (T *) object;
  }
  inline T *pointer() const {
    return (T *) object;
  }
};
*/


#endif /* AGREF_H */