Rogue wave:继承自RWSet

时间:2017-10-29 19:57:11

标签: c++

我的任务是从我们很老的项目中移除Rogue wave。我正在创建主要RW对象周围的包装器(RWCString,RWCollectable,RWCRegEx,RWSet

我遇到了RWSet的问题

从Rogue wave在其文档中发布的Bus示例中创建POC。

我在>>上遇到链接器错误运营商。我的包装器只是一个穿透包装器。

我没有在<<<<<<<<<运营商。如果我从项目中取出>>运算符(restoreGuts),项目会编译并将数据保存到文件(RWFile)。

#pragma once

#ifndef __BUS_H__
#define __BUS_H__

#include <rw/rwset.h>
#include <rw/collstr.h>
#include <rw/collect.h>

#include <OptumBaseCollectable.h>
#include <OptumSet.h>
#include <rw/epersist.h>
#include <rw/edefs.h>

#define MODULE_FUNCTION
class Bus  : public OptumBaseCollectable {

RW_DECLARE_COLLECTABLE_CLASS(MODULE, Bus)
//RWDECLARE_COLLECTABLE(Bus)

public:

  Bus();
  Bus(int busno, const RWCString& driver);
  ~Bus();
  //OptumBaseCollectable* optBaseColl;
  // Inherited from class "RWCollectable":
  RWspace      binaryStoreSize() const;
  int          compareTo(const OptumBaseCollectable*) const;
  RWBoolean    isEqual(const OptumBaseCollectable*) const;
  unsigned     hash() const;
  void         restoreGuts(RWFile&);
  void         restoreGuts(RWvistream&);
  void         saveGuts(RWFile&) const;
  void         saveGuts(RWvostream&) const; 
 /* RWCollectable* newSpecies() const;*/

  void         addPassenger(const char* name);
  void         addCustomer(const char* name);
  size_t       customers() const;
  size_t       passengers() const;
  RWCString    driver() const     {return driver_;}
  int          number() const     {return busNumber_;}

  inline friend RWFile& operator>>(RWFile& f, OptumSet*& pCl);

  //RWvistream& operator>>(RWvistream& vstream, const Bus* p);

private:

  OptumSet *      customers_;
  OptumSet *      passengers_;
  int          busNumber_;
  RWCString    driver_;  
};

RWDECLARE_PERSISTABLE(Bus)

class Client : public RWCollectable  {
  RWDECLARE_COLLECTABLE(Client)
  Client();
  Client(const char* name);
  RWspace      binaryStoreSize() const;
  int          compareTo(const RWCollectable*) const;
  RWBoolean    isEqual(const RWCollectable*) const;
  unsigned     hash() const;
  void         restoreGuts(RWFile&);
  void         restoreGuts(RWvistream&);
  void         saveGuts(RWFile&) const;
  void         saveGuts(RWvostream&) const;
private:
  RWCString    name_;
//ignore other client information for this example
};
#endif

Bus.cpp
#include "StdAfx.h"
#include "bus.h"
#include <rw/pstream.h>
#include <rw/rwfile.h>
#include <rw/epersist.h>
#ifdef __GLOCK__
#include <fstream.hxx>
#else
#include <fstream>
#endif

RW_DEFINE_COLLECTABLE_CLASS_BY_ID(MODULE, Bus,100)

Bus::Bus() :
  busNumber_  (0),
  driver_     ("Unknown"),
  passengers_ (rwnil)
{
    //optBaseColl = new OptumBaseCollectable();
}

Bus::Bus(int busno, const RWCString& driver) :
  busNumber_  (busno),
  driver_     (driver),
  passengers_ (rwnil)
{
    customers_ = new OptumSet(64);  
}

Bus::~Bus()  {
  customers_->clearAndDestroy();
  delete passengers_;
  delete customers_;
}

RWspace
Bus::binaryStoreSize() const  {
  RWspace count = RWCollectable::binaryStoreSize() +
    customers_->recursiveStoreSize() +
    sizeof(busNumber_) +
    driver_.binaryStoreSize();

 if (passengers_)
     count += passengers_->recursiveStoreSize();
   else
     count += nilStoreSize();

   return count;
}


int
Bus::compareTo(const OptumBaseCollectable* c) const  {
  const Bus* b = (const Bus*)c;
  if (busNumber_ == b->busNumber_) return 0;
  return busNumber_ > b->busNumber_ ? 1 : -1;
}

RWBoolean
Bus::isEqual(const OptumBaseCollectable* c) const  {
  const Bus* b = (const Bus*)c;
  return busNumber_ == b->busNumber_;
}

unsigned
Bus::hash() const  {
  return (unsigned)busNumber_;
}

size_t
Bus::customers() const  {
  return customers_->entries();
}

size_t
Bus::passengers() const{    return passengers_ ? passengers_->entries() : 0;
}

void 
Bus::saveGuts(RWFile& f) const  {
  OptumBaseCollectable::saveGuts(f);    // Save base class
  f.Write(busNumber_);           // Write primitive directly
  f << driver_ << customers_;    // Use Rogue Wave provided versions
  f << passengers_;              // Will detect nil pointer automatically
}

void 
Bus::saveGuts(RWvostream& strm) const  {
  OptumBaseCollectable::saveGuts(strm);   // Save base class
  strm << busNumber_;              // Write primitives directly
  strm << driver_ << customers_;   // Use Rogue Wave 
                                   // provided versions
  strm << passengers_;     // Will detect nil pointer automatically
}

void Bus::restoreGuts(RWFile& f)  {
  OptumBaseCollectable::restoreGuts(f);  // Restore base class
  f.Read(busNumber_);             // Restore primitive
  f >> driver_ >> customers_;     // Uses Rogue Wave
                                  // provided versions

  delete passengers_;             // Delete old RWSet
  f >> passengers_;               // Replace with a new one
}

void Bus::restoreGuts(RWvistream& strm)  {
  RWCollectable::restoreGuts(strm); // Restore base class
  strm >> busNumber_ >> driver_ >> customers_;

  delete passengers_;             // Delete old RWSet
  strm >> (RWCollection&)passengers_;            // Replace with a new one
}

void
Bus::addPassenger(const char* name)  {
  Client* s = new Client(name);
  customers_->insert( s );

  if (!passengers_)
    passengers_ = new OptumSet(64);

  passengers_->insert(s);
}

void
Bus::addCustomer(const char* name)  {
  customers_->insert( new Client(name) );
}

///////////////    Here are Client methods //////////////
RWDEFINE_NAMED_COLLECTABLE(Client,"client")

Client::Client() {} // Uses RWCString default constructor

Client::Client(const char* name) : name_(name) {}

RWspace
Client::binaryStoreSize() const {
  return name_.binaryStoreSize();
}

int
Client::compareTo(const RWCollectable* c) const  {
  return name_.compareTo(((Client*)c)->name_);
}

RWBoolean
Client::isEqual(const RWCollectable* c) const  {
  return name_ == *((Client*)c)->name_;
}

unsigned
Client::hash() const  {
  return name_.hash();
}

void
Client::restoreGuts(RWFile& f)  {
  f >> name_;
}

void
Client::restoreGuts(RWvistream& vis)  {
  vis >> name_;
}

void
Client::saveGuts(RWFile& f) const  {
  f << name_;
}

void
Client::saveGuts(RWvostream& vos) const  {
  vos << name_;
}

    #ifndef _OPTUMSET_H
#define _OPTUMSET_H
#include <rw\rwset.h>

#define MODULE_FUNCTION
class __declspec(dllexport) OptumSet : public RWSet
{   
    RW_DECLARE_COLLECTABLE_CLASS(MODULE, OptumSet)
    //RWDECLARE_COLLECTABLE(OptumSet)
public:     
    OptumSet (size_t n = RWDEFAULT_CAPACITY);
    OptumSet (const OptumSet & h);
    virtual ~OptumSet();

};

#endif

OptumSet.CPP

#include <OptumSet.h>

RW_DEFINE_COLLECTABLE_CLASS_BY_ID(MODULE, OptumSet,50)
//RWDEFINE_COLLECTABLE(OptumSet, 100)

OptumSet::OptumSet(size_t n) 
{
    std::string mystr = "mystr";
}

OptumSet::~OptumSet()
{
}

OptumSet::OptumSet (const OptumSet & h) : RWSet(h)
{
    std::string mystr = "mystr";
}

同样,OptumSet旨在作为传递类。我已经尝试了RW包含在.h文件中的Declare和Defines的每个组合。

错误13错误LNK2019:未解析的外部符号“类RWFile&amp; __cdecl运算符&gt;&gt;(类RWFile&amp;,类OptumSet *&amp;)”(?? 5 @ YAAAVRWFile @@ AAV0 @ AAPAVOptumSet @@@ Z)在函数“public:virtual void __thiscall Bus :: restoreGuts(class RWFile&amp;)”中引用(?restoreGuts @ Bus @@ UAEXAAVRWFile @@@ Z)C:\ Carol \ Projects \ RWCollectionPOC \ Bus.obj RWCollectionPOC

我希望使用记录在案的公共&gt;&gt;类RWFile&amp;,Class *&amp;)的RW方法。它不是虚拟的,所以我无法覆盖它。这是公开的,所以我试图直接转到RWCollectable,它有&gt;&gt;方法,是RWSet的基础。

如果您对整个POC感兴趣,请告诉我,我可以提供。

提前致谢

这不重复。这需要使用Roguewave实现,然后是链接器错误。我知道我错过了什么,但我不知道它是什么。如果我添加&gt;&gt;的声明然后我会得到它已经定义。所以我很困惑。

0 个答案:

没有答案