I just got the entire day lost with this thing.
When I add a "ManyToOne" association on my entity, I get the classical Doctrine's proxy error:
Warning: require(data/DoctrineORMModule/Proxy/__CG__TournamentEntityCountry.php): failed to open stream: No such file or directory in /mnt/hgfs/httdocs/tournament/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 200
And here the two entities:
namespace Tournament\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table(options={"collate"="utf8_general_ci"})
* #ORM\Entity
*/
class Team
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue
*/
private $id;
/**
* #var string
* #ORM\Column(type="string", length=255)
*/
private $key;
/**
* #var string
* #ORM\Column(type="string", length=255)
*/
private $title;
/**
* #var string
* #ORM\Column(type="string", length=255,nullable=true)
*/
private $title2;
/**
* #var string
* #ORM\Column(type="string", length=255,nullable=true)
*/
private $code;
/**
* #var string
* #ORM\Column(type="string", length=255,nullable=true)
*/
private $synonyms;
/**
* #ORM\ManyToOne(targetEntity="Country", inversedBy="teams")
* #ORM\JoinColumn(name="country_id", referencedColumnName="id")
*/
private $country;
/**
* #var integer
* #ORM\Column(name="city_id", type="integer",nullable=true)
*/
private $city;
/**
* #var integer
* #ORM\Column(type="integer")
*/
private $club;
/**
* #var boolean
*/
private $national;
/**
* #var \DateTime
* #ORM\Column(name="created_at",type="datetime")
*/
private $created;
/**
* #var \DateTime
* #ORM\Column(name="updated_at",type="datetime")
*/
private $updated;
/**
* #var groups[]
* #ORM\ManyToMany(targetEntity="Group")
* #ORM\JoinTable(name="Group_has_team",joinColumns={#ORM\JoinColumn(name="team_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="group_id", referencedColumnName="id")})
*/
private $groups;
public function __construct()
{
$this->groups = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Set key
*
* #param string $key
* #return Team
*/
public function setKey($key)
{
$this->key = $key;
return $this;
}
/**
* Get key
*
* #return string
*/
public function getKey()
{
return $this->key;
}
/**
* Set title
*
* #param string $title
* #return Team
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set title2
*
* #param string $title2
* #return Team
*/
public function setTitle2($title2)
{
$this->title2 = $title2;
return $this;
}
/**
* Get title2
*
* #return string
*/
public function getTitle2()
{
return $this->title2;
}
/**
* Set code
*
* #param string $code
* #return Team
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* Get code
*
* #return string
*/
public function getCode()
{
return $this->code;
}
/**
* Set synonyms
*
* #param string $synonyms
* #return Team
*/
public function setSynonyms($synonyms)
{
$this->synonyms = $synonyms;
return $this;
}
/**
* Get synonyms
*
* #return string
*/
public function getSynonyms()
{
return $this->synonyms;
}
/**
* Set country
*
* #param integer $country
* #return Team
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* #return integer
*/
public function getCountry()
{
return $this->country;
}
/**
* Set cityId
*
* #param integer $cityId
* #return Team
*/
public function setCity($cityId)
{
$this->cityId = $cityId;
return $this;
}
/**
* Get cityId
*
* #return integer
*/
public function getCity()
{
return $this->cityId;
}
/**
* Set club
*
* #param boolean $club
* #return Team
*/
public function setClub($club)
{
$this->club = $club;
return $this;
}
/**
* Get club
*
* #return boolean
*/
public function getClub()
{
return $this->club;
}
/**
* Set national
*
* #param boolean $national
* #return Team
*/
public function setNational($national)
{
$this->national = $national;
return $this;
}
/**
* Get national
*
* #return boolean
*/
public function getNational()
{
return $this->national;
}
/**
* Set created
*
* #param \DateTime $created
* #return Team
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* #return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* #param \DateTime $updated
* #return Team
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* #return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
public function getGroups()
{
return $this->groups;
}
public function setGroups($groups)
{
$this->groups = $groups;
}
}
Country:
namespace Tournament\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table(options={"collate"="utf8_general_ci"})
* #ORM\Entity
*/
class Country
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue
*/
private $id;
/**
* #var string
* #ORM\Column(type="string", length=255)
*/
private $title;
/**
* #var string
* #ORM\Column(type="string", length=255)
*/
private $key;
/**
* #var string
* #ORM\Column(type="string", length=255)
*/
private $code;
/**
* #var string
* #ORM\Column(type="string", length=255,nullable=true)
*/
private $synonyms;
/**
* #var integer
* #ORM\Column(type="integer")
*/
private $pop;
/**
* #var integer
* #ORM\Column(type="integer")
*/
private $area;
/**
* #var integer
* #ORM\Column(name="continent_id",type="integer",nullable=true)
*/
private $continent;
/**
* #var integer
* #ORM\Column(name="country_id",type="integer",nullable=true)
*/
private $country;
/**
* #var boolean
* #ORM\Column(type="smallint")
*/
private $s;
/**
* #var boolean
* #ORM\Column(type="smallint")
*/
private $c;
/**
* #var boolean
* #ORM\Column(type="smallint")
*/
private $d;
/**
* #var string
* #ORM\Column(type="string", length=255,nullable=true)
*/
private $motor;
/**
* #var string
* #ORM\Column(type="string", length=255,nullable=true)
*/
private $iso2;
/**
* #var string
* #ORM\Column(type="string", length=255,nullable=true)
*/
private $iso3;
/**
* #var string
* #ORM\Column(type="string", length=255,nullable=true)
*/
private $fifa;
/**
* #var string
* #ORM\Column(type="string", length=255,nullable=true)
*/
private $net;
/**
* #var string
* #ORM\Column(type="string", length=255,nullable=true)
*/
private $wikipedia;
/**
* #var \DateTime
* #ORM\Column(name="created_at",type="datetime")
*/
private $created;
/**
* #var \DateTime
* #ORM\Column(name="updated_at",type="datetime")
*/
private $updated;
/**
* #var teams[]
* #ORM\OneToMany(targetEntity="Team" , mappedBy="country")
*/
private $teams;
public function __construct()
{
$this->teams = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Set title
*
* #param string $title
* #return Country
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set key
*
* #param string $key
* #return Country
*/
public function setKey($key)
{
$this->key = $key;
return $this;
}
/**
* Get key
*
* #return string
*/
public function getKey()
{
return $this->key;
}
/**
* Set code
*
* #param string $code
* #return Country
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* Get code
*
* #return string
*/
public function getCode()
{
return $this->code;
}
/**
* Set synonyms
*
* #param string $synonyms
* #return Country
*/
public function setSynonyms($synonyms)
{
$this->synonyms = $synonyms;
return $this;
}
/**
* Get synonyms
*
* #return string
*/
public function getSynonyms()
{
return $this->synonyms;
}
/**
* Set pop
*
* #param integer $pop
* #return Country
*/
public function setPop($pop)
{
$this->pop = $pop;
return $this;
}
/**
* Get pop
*
* #return integer
*/
public function getPop()
{
return $this->pop;
}
/**
* Set area
*
* #param integer $area
* #return Country
*/
public function setArea($area)
{
$this->area = $area;
return $this;
}
/**
* Get area
*
* #return integer
*/
public function getArea()
{
return $this->area;
}
/**
* Set continent
*
* #param integer $continent
* #return Country
*/
public function setContinent($continent)
{
$this->continent = $continent;
return $this;
}
/**
* Get continent
*
* #return integer
*/
public function getContinent()
{
return $this->continent;
}
/**
* Set country
*
* #param integer $country
* #return Country
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* #return integer
*/
public function getCountry()
{
return $this->country;
}
/**
* Set s
*
* #param boolean $s
* #return Country
*/
public function setS($s)
{
$this->s = $s;
return $this;
}
/**
* Get s
*
* #return boolean
*/
public function getS()
{
return $this->s;
}
/**
* Set c
*
* #param boolean $c
* #return Country
*/
public function setC($c)
{
$this->c = $c;
return $this;
}
/**
* Get c
*
* #return boolean
*/
public function getC()
{
return $this->c;
}
/**
* Set d
*
* #param boolean $d
* #return Country
*/
public function setD($d)
{
$this->d = $d;
return $this;
}
/**
* Get d
*
* #return boolean
*/
public function getD()
{
return $this->d;
}
/**
* Set motor
*
* #param string $motor
* #return Country
*/
public function setMotor($motor)
{
$this->motor = $motor;
return $this;
}
/**
* Get motor
*
* #return string
*/
public function getMotor()
{
return $this->motor;
}
/**
* Set iso2
*
* #param string $iso2
* #return Country
*/
public function setIso2($iso2)
{
$this->iso2 = $iso2;
return $this;
}
/**
* Get iso2
*
* #return string
*/
public function getIso2()
{
return $this->iso2;
}
/**
* Set iso3
*
* #param string $iso3
* #return Country
*/
public function setIso3($iso3)
{
$this->iso3 = $iso3;
return $this;
}
/**
* Get iso3
*
* #return string
*/
public function getIso3()
{
return $this->iso3;
}
/**
* Set fifa
*
* #param string $fifa
* #return Country
*/
public function setFifa($fifa)
{
$this->fifa = $fifa;
return $this;
}
/**
* Get fifa
*
* #return string
*/
public function getFifa()
{
return $this->fifa;
}
/**
* Set net
*
* #param string $net
* #return Country
*/
public function setNet($net)
{
$this->net = $net;
return $this;
}
/**
* Get net
*
* #return string
*/
public function getNet()
{
return $this->net;
}
/**
* Set wikipedia
*
* #param string $wikipedia
* #return Country
*/
public function setWikipedia($wikipedia)
{
$this->wikipedia = $wikipedia;
return $this;
}
/**
* Get wikipedia
*
* #return string
*/
public function getWikipedia()
{
return $this->wikipedia;
}
/**
* Set created
*
* #param \DateTime $created
* #return Country
*/
public function setCreatedAt($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* #return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* #param \DateTime $updated
* #return Country
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* #return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
public function getTeams()
{
return $this->teams;
}
public function setTeams($teams)
{
$this->teams = $teams;
}
}
File/folder permissions are completely right...
So stupid. The flag 'generate_proxies' was set to false in Doctrine's config... This kind of things that happen when you work in a shared project :P
Related
How to remove owing side from inversed MTO relation side without cascade option? , how to update the inversed side of relation without cascade option?
Error is that if i change address(OTM) of the room (MTO), room remains in the previous address, although i remove it .
if( $this->addrOTM_b_ -> getRoomMTO_b_1() -> contains($this) ) {
$this->addrOTM_b_ -> getRoomMTO_b_1() -> remove($this);
}
If i check the address of the room - it is correct new address.
But if i check the rooms in the address, they are wrong, because exists rooms which have been removed.
Maybe there is an order how i shall flush entities? Or an order how i shall remove rooms from addresses? Or maybe it is not possible to make at level of entity, and i shall make this at level of Controller action?
This post has a coment that it is not possible:Doctrine: can't removeElement from inverse side of the relation
This is just an illustration about bidirectional MTO relation,
Normally it is difficult to transfer room to another address, unless it is a boat/tent/van.
p.s.
I know that it is not good to flush inside the foreach loop,
but i can not clear entity manager, because i will use entities in the second loop.
Anyway these loops are litte, thre are only 5 addresses and 20 rooms.
//Controller action, kind of fixture
//FIRST ROUND seeting random address for each room
foreach ( $roomEntArr as $roomEnt ) {
$addrCnt = count($addrEntArr)-1;
$i = rand(0, $addrCnt);
$addrEnt = $addrEntArr[$i];
$roomEnt->setAddrOTM_b_($addrEnt);
$this->em->persist($roomEnt);
$this->em->persist($addrEnt);
$this->em->flush();
}
$addrRoomArr1 = [];
foreach ( $addrEntArr as $ent1 ) {
$addrId = $ent1->getId();
$roomEnts = $ent1->getRoomMTO_b_1(); $roomStr="";
if( !empty($roomEnts) ) {
foreach ($roomEnts as $addr) { $roomStr .= $addr->getId().','; }
}
$addrRoomArr1[$addrId] = $roomStr;
} //foreach ( $ent1arr as $ent1 ) {
$roomAddrArr1 = [];
if( $dir==='b' ) {
foreach ( $roomEntArr as $ent2 ) {
$roomId = $ent2->getId();
$addr = $ent2->getAddrOTM_b_(); $addrStr="";
if($addr !== null) { $addrStr = $addr->getId().','; }
$roomAddrArr1[$roomId] = $addrStr;
} //foreach ( $ent1arr as $ent1 ) {
} //if( $dir==='b' ) {
//SECOND ROUND seeting random address for each room
foreach ( $roomEntArr as $roomEnt ) {
$addrCnt = count($addrEntArr)-1;
$i = rand(0, $addrCnt);
$addrEnt = $addrEntArr[$i];
$roomEnt->setAddrOTM_b_($addrEnt);
$this->em->persist($roomEnt);
$this->em->persist($addrEnt);
$this->em->flush();
}
$addrRoomArr1 = [];
foreach ( $addrEntArr as $ent1 ) {
$addrId = $ent1->getId();
$roomEnts = $ent1->getRoomMTO_b_1(); $roomStr="";
if( !empty($roomEnts) ) {
foreach ($roomEnts as $addr) { $roomStr .= $addr->getId().','; }
}
$addrRoomArr1[$addrId] = $roomStr;
} //foreach ( $ent1arr as $ent1 ) {
$roomAddrArr1 = [];
if( $dir==='b' ) {
foreach ( $roomEntArr as $ent2 ) {
$roomId = $ent2->getId();
$addr = $ent2->getAddrOTM_b_(); $addrStr="";
if($addr !== null) { $addrStr = $addr->getId().','; }
$roomAddrArr1[$roomId] = $addrStr;
} //foreach ( $ent1arr as $ent1 ) {
} //if( $dir==='b' ) {
//Room entity
<?php
namespace DctrBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping\Index;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\ManyToMany;
use DctrBundle\Entity\AddrOTM_b_;
/**
/**
* #Table(name="t_roomMTO_b_1")
* #Entity( repositoryClass="DctrBundle\Repository\RoomMTO_b_1Repository" )
*/
class RoomMTO_b_1 {
/**
* #var integer
*
* #Column(name="id", type="integer" )
* #Id
* #GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ManyToOne(targetEntity="DctrBundle\Entity\AddrOTM_b_", inversedBy="roomMTO_b_1" )
* #JoinColumn(name="addr_id", referencedColumnName="id")
*/
private $addrOTM_b_;
public function __construct() {
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get AddrOTM_b_
*
* #return DctrBundle\Entity\AddrOTM_b_
*/
public function getAddrOTM_b_()
{
return $this->addrOTM_b_;
}
/**
* Get AddrOTM_b_
*
* #return DctrBundle\Entity\AddrOTM_b_
*/
public function setAddrOTM_b_( $addrOTM_b_ )
{
if ( $addrOTM_b_ !== null ) {
//if current address is not null, and if it is not the same
//1) remove the room from the previous address if it exists
//2) set new address to this room ( automatically removes the oldAddress from the room)
if ( $this->addrOTM_b_ !== null ) {
if( $addrOTM_b_->getId() != $this->addrOTM_b_->getId() ) {
// first you have to remove this room from previous address - this part does not work, according docs : Changes made only to the inverse side of an association are ignored. Make sure to update both sides of a bidirectional association (or at least the owning side, from Doctrine’s point of view). http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/unitofwork-associations.html
if( $this->addrOTM_b_ -> getRoomMTO_b_1() -> contains($this) ) {
$this->addrOTM_b_ -> getRoomMTO_b_1() -> remove($this);
}
// then you can set the room to the new address
$this->addrOTM_b_ = $addrOTM_b_;
} // if( $addrOTM_b_->getId() != $this->addrOTM_b_->getId ) {
} // if ( $this->addrOTM_b_ !== null ) {
else {
//if current address is null, just set the address
$this->addrOTM_b_ = $addrOTM_b_;
}
//3) add room to the new address
if ( !$addrOTM_b_->hasRoomMTO_b_1($this) ) {
//$addrMTM_b_1->getRoomMTM_b_()->removeElement($this);
$addrOTM_b_->addRoomMTO_b_1($this);
}
return $this;
} // if ( $addrOTM_b_ !== null ) {
else {
if ( $this->addrOTM_b_ !== null ) {
$idold = $this->addrOTM_b_->getId();
//remove this room from previous address
if( $this->addrOTM_b_ -> getRoomMTO_b_1() -> contains($this) ) {
$this->addrOTM_b_ ->getRoomMTO_b_1()->remove($this);
}
$this->addrOTM_b_ = null;
} // if ( $this->addrOTM_b_ !== null ) {
return true;
} // else of if ( $addrOTM_b_ !== null ) {
} //public function setAddrOTM_b_( $addrOTM_b_ )
/**
* #param DctrBundle\Entity\RoomMTO_b_1 $AddrOTM_b_
* #return bool
*/
public function hasAddrOTM_b_($addrOTM_b_)
{
if( ($addrOTM_b_!==null) && ($this->addrOTM_b_!== null) ) {
return ( $addrOTM_b_->getId() == $this->getAddrOTM_b_()->getId() );
}
else {
return false;
}
}
/**
* Return Entity as string
*
* #return string String representation of this class
*/
public function __toString()
{
return strval($this->id);
}
} // class RoomMTO_b_1 {
//Address entity
<?php
namespace DctrBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping\Index;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\ManyToMany;
use DctrBundle\Entity\RoomMTO_b_1;
/**
/**
* #Table(name="t_addrOTM_b_")
* #Entity( repositoryClass="DctrBundle\Repository\AddrOTM_b_Repository" )
*/
class AddrOTM_b_ {
/**
* #var integer
*
* #Column(name="id", type="integer" )
* #Id
* #GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #OneToMany(targetEntity="DctrBundle\Entity\RoomMTO_b_1", mappedBy="addrOTM_b_" )
*/
private $roomMTO_b_1;
public function __construct() {
$this->roomMTO_b_1 = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get RoomMTO_b_1
*
* #return DctrBundle\Entity\RoomMTO_b_1
*/
public function getRoomMTO_b_1()
{
return $this->roomMTO_b_1;
}
/**
* Remove RoomMTO_b_1
*
* #param DctrBundle\Entity\AddrOTM_b_ $RoomMTO_b_1
*/
public function removeRoomMTO_b_1 (\DctrBundle\Entity\RoomMTO_b_1 $roomMTO_b_1)
{
if( $roomMTO_b_1->getAddrOTM_b_()->getId() == $this->id ) {
$roomMTO_b_1->setAddrOTM_b_(null);
} //
if ( $this->hasRoomMTO_b_1($roomMTO_b_1) ) {
$this->roomMTO_b_1->removeElement($roomMTO_b_1);
} // else if ( !$this->hasRoomMTO_b_1($roomMTO_b_1) )
} //remove
/**
* Add RoomMTO_b_1
*
* #param DctrBundle\Entity\AddrOTM_b_ $RoomMTO_b_1
*
* #return RoomMTO_b_1
*/
public function addRoomMTO_b_1(\DctrBundle\Entity\RoomMTO_b_1 $roomMTO_b_1)
{
if(!$roomMTO_b_1 instanceof \DctrBundle\Entity\RoomMTO_b_1) {
throw new \InvalidArgumentException('$roomMTO_b_1 must be null or instance of DctrBundle\Entity\RoomMTO_b_1');
}
else if ( !$this->hasRoomMTO_b_1($roomMTO_b_1) ) {
$this->roomMTO_b_1->add($roomMTO_b_1);
//echo "<br> 150,addRoomMTO_b_1 setting room to address in ".__FILE__;
if ( !$roomMTO_b_1->hasAddrOTM_b_($this) ) {
$roomMTO_b_1->setAddrOTM_b_($this);
}
} // else if ( !$this->hasRoomMTO_b_1($RoomMTO_b_1) ) {
return $this;
} //
/**
* #param DctrBundle\Entity\AddrOTM_b_ $RoomMTO_b_1
* #return bool
*/
public function hasRoomMTO_b_1($roomMTO_b_1)
{
return $this->getRoomMTO_b_1()->contains($roomMTO_b_1);
}
/**
* Return Entity as string
*
* #return string String representation of this class
*/
public function __toString()
{
return strval($this->id);
}
} //class AddrOTM_b_ {
The reason was wrong syntax, WRONG - remove, RIGHT - removeElement
WRONG in room entity setAddrOTM_b_($addr) :
if( $this->addrOTM_b_ -> getRoomMTO_b_1() -> contains($this) ) {
$this->addrOTM_b_ -> getRoomMTO_b_1() -> remove($this);
}
RIGHT in room entity setAddrOTM_b_($addr):
if( $this->addrOTM_b_ -> getRoomMTO_b_1() -> contains($this) ) {
$this->addrOTM_b_ -> getRoomMTO_b_1() -> removeElement($this);
}
Doctrine does not generate database schema for ManyToMany relation.
c:\Bitnami\wampstack-5.6.30-0\apache2\htdocs\typejoy.biz>php vendor\doctrine\orm\bin\doctrine orm:schema-tool:create
creates two tables for two entities testChi and testPar, but does not create the #JoinTable "tParChiMTM".
ENtity testChi
<?php
namespace LogBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping\Index;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\JoinTable;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\ManyToMany;
use LogBundle\Entity\testPar;
/**
* #Table(name="ttestchi")
* #Entity()
*/
class testChi {
/**
* #var integer
*
* #Column(name="id", type="integer")
* #Id
* #GeneratedValue(strategy="AUTO")
*/
private $id;
/** #Column ( name="name", type="string", length=50, unique=false, nullable=true) */
private $name;
/** #ManyToMany ( targetEntity="testPar", mappedBy="chiMTM") */
private $parMTM;
public function __construct() {
$this->chiMTM = new ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get name
*
* #return integer
*/
public function getName()
{
return $this->name;
}
/**
* Set name
* #param integer $name
* #return name
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
//make you have to serialize, deserialize entity here ???
/**
* Get parMTM
*
* #return LogBundle\Entity\ParMTM
*/
public function getParMTM()
{
return $this->parMTM;
}
/**
* Remove parMTM
*
* #param \LogBundle\Entity\testPar $parMTM
*/
public function removeParMTM (\LogBundle\Entity\testPar $parMTM)
{
if ( $this->hasParMTM($parMTM) ) {
$this->parMTM->removeElement($parMTM);
}
}
/**
* Add parMTM
*
* #param \LogBundle\Entity\testPar $parMTM
*
* #return ParMTM
*/
public function addParMTM(\LogBundle\Entity\testPar $parMTM)
{
if ( !$this->hasParMTM($parMTM) ) {
$this->parMTM[] = $parMTM;
}
return $this;
}
/**
* #param \LogBundle\Entity\testPar $parMTM
* #return bool
*/
public function hasParMTM($parMTM)
{
if( $this->getParMTM() ) {
return $this->getParMTM()->contains($parMTM);
}
}
/**
* Return Entity as string
*
* #return string String representation of this class
*/
public function __toString()
{
return strval($this->id);
}
}
Entity testPar
<?php
namespace LogBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping\Index;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\JoinTable;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\ManyToMany;
use LogBundle\Entity\testChi;
/**
* #Table(name="ttestpar")
* #Entity()
*/
class testPar {
/**
* #var integer
*
* #Column(name="id", type="integer")
* #Id
* #GeneratedValue(strategy="AUTO")
*/
private $id;
/** #Column ( name="name", type="string", length=50, unique=false, nullable=true) */
private $name;
/** #ManyToMany ( targetEntity="testChi", inversedBy="parMTM") */
/** #JoinTable ( name="tParChiMTM") */
private $chiMTM;
public function __construct() {
$this->chiMTM = new ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get name
*
* #return integer
*/
public function getName()
{
return $this->name;
}
/**
* Set name
* #param integer $name
* #return name
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
//make you have to serialize, deserialize entity here ???
/**
* Get chiMTM
*
* #return LogBundle\Entity\ChiMTM
*/
public function getChiMTM()
{
return $this->chiMTM;
}
/**
* Remove chiMTM
*
* #param \LogBundle\Entity\testChi $chiMTM
*/
public function removeChiMTM (\LogBundle\Entity\testChi $chiMTM)
{
if ( $this->hasChiMTM($chiMTM) ) {
$this->chiMTM->removeElement($chiMTM);
}
}
/**
* Add chiMTM
*
* #param \LogBundle\Entity\testChi $chiMTM
*
* #return ChiMTM
*/
public function addChiMTM(\LogBundle\Entity\testChi $chiMTM)
{
if ( !$this->hasChiMTM($chiMTM) ) {
$this->chiMTM[] = $chiMTM;
}
return $this;
}
/**
* #param \LogBundle\Entity\testChi $chiMTM
* #return bool
*/
public function hasChiMTM($chiMTM)
{
if( $this->getChiMTM() ) {
return $this->getChiMTM()->contains($chiMTM);
}
}
/**
* Return Entity as string
*
* #return string String representation of this class
*/
public function __toString()
{
return strval($this->id);
}
}
c:\Bitnami\wampstack-5.6.30-0\apache2\htdocs\typejoy.biz>php vendor\doctrine\orm\bin\doctrine orm:schema-tool:create
creates two tables, but does not create the #JoinTable "tParChiMTM".
The reason was in annotations :
CORRECT
/**
* #ManyToMany ( targetEntity="testPar", mappedBy="chiMTM") */
/**
* #ManyToMany ( targetEntity="testChi", inversedBy="parMTM")
* ( name="tParChiMTM") */
private $chiMTM;
You can not start each line with /**, only the first line shall contain this, the subsequent lines can start only with single *.
WRONG:
/** #ManyToMany ( targetEntity="testChi", inversedBy="parMTM") */
/** #JoinTable ( name="tParChiMTM") */
I have these entities below. There is a 1:m relationship between them.
MetodoPago is PayingMethod, already saved in the database: "credit card", "cash", etc. And Pedido is Order.
Now I want to to associate a paying method to an order, so I have this code:
$pedido = new Pedido();
$repositoryMetodoPago = $this->getDoctrine()->getRepository('ProjectBackendBundle:MetodoPago');
$metodoPago = $repositoryMetodoPago->find(1);
$pedido->setMetodoPago($metodoPago);
$em = $this->getDoctrine()->getManager();
$em->persist($pedido);
$em->flush();
The problem with this code: in the same time the new order is saved, a new MetodoPago is also saved!! Im interested in that since I have already saved all the availablel paying methods.
My try: I have tried this setter:
public function setMetodoPago(\Project\BackendBundle\Entity\MetodoPago $metodoPago = null)
{
$this->metodoPago = $metodoPago->getId();
return $this;
}
but when I try to run the code above, I get
Warning: spl_object_hash() expects parameter 1 to be object, integer given in /vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1389
Sooo.. what should I do?? These are the entites:
class Pedido
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #ORM\ManyToOne(targetEntity="MetodoPago", cascade={"persist", "remove"})
* #ORM\JoinColumn(name="metodo_pago_id", referencedColumnName="id")
**/
private $metodoPago;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set metodoPago
*
* #param \Project\BackendBundle\Entity\MetodoPago $metodoPago
* #return Pedido
*/
public function setMetodoPago(\Project\BackendBundle\Entity\MetodoPago $metodoPago = null)
{
var_dump($metodoPago);
$this->metodoPago = $metodoPago;
return $this;
}
/**
* Get metodoPago
*
* #return \Project\BackendBundle\Entity\MetodoPago
*/
public function getMetodoPago()
{
return $this->metodoPago;
}
}
class MetodoPago
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #ORM\Column(type="string", name="nombre")
*/
protected $nombre;
/**
* #ORM\Column(type="float", name="precio")
*/
protected $precio;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nombre
*
* #param string $nombre
* #return MetodoPago
*/
public function setNombre($nombre)
{
$this->nombre = $nombre;
return $this;
}
/**
* Get nombre
*
* #return string
*/
public function getNombre()
{
return $this->nombre;
}
/**
* Set precio
*
* #param float $precio
* #return MetodoPago
*/
public function setPrecio($precio)
{
$this->precio = $precio;
return $this;
}
/**
* Get precio
*
* #return float
*/
public function getPrecio()
{
return $this->precio;
}
}
I'm working on a small project in wich i'm using ZF2 + Doctrine2.
I have a doctrine entity whith the following description:
<?php
namespace Akplanu\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Exemplaire
*
* #ORM\Table(name="exemplaire", indexes={#ORM\Index(name="fk_Exemplaire_Livre1_idx", columns={"Liv_id"}), #ORM\Index(name="fk_Exemplaire_Donateur1_idx", columns={"Don_id"}), #ORM\Index(name="fk_Exemplaire_Origin_1_idx", columns={"Origin_id"}), #ORM\Index(name="fk_Exemplaire_Etat_Livre1_idx", columns={"Etlv_id"})})
* #ORM\Entity(repositoryClass="Akplanu\Repository\ExemplaireRepository")
*/
class Exemplaire
{
/**
* #var integer
*
* #ORM\Column(name="Expl_id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var integer
*
* #ORM\Column(name="Expl_numEntr", type="integer", nullable=false)
*/
private $numEntre;
/**
* #var string
*
* #ORM\Column(name="Expl_lieuEdit", type="string", length=45, nullable=false)
*/
private $lieuEdit;
/**
* #var \DateTime
*
* #ORM\Column(name="Expl_datEdit", type="date", nullable=false)
*/
private $datEdit;
/**
* #var boolean
*
* #ORM\Column(name="Expl_tome", type="integer", nullable=true)
*/
private $tome;
/**
* #var \DateTime
*
* #ORM\Column(name="Expl_datDon", type="date", nullable=true)
*/
private $dateDon;
/**
* #var float
*
* #ORM\Column(name="Expl_prix", type="float", precision=10, scale=0, nullable=true)
*/
private $prix;
/**
* #var string
*
* #ORM\Column(name="Expl_comment", type="text", nullable=true)
*/
private $comment;
/**
* #var \Akplanu\Entity\Livre
*
* #ORM\ManyToOne(targetEntity="Akplanu\Entity\Livre")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="Liv_id", referencedColumnName="Liv_id")
* })
*/
private $livre;
/**
* #var \Akplanu\Entity\Donateur
*
* #ORM\ManyToOne(targetEntity="Akplanu\Entity\Donateur")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="Don_id", referencedColumnName="Don_id", nullable=true)
* })
*/
private $donateur;
/**
* #var \Akplanu\Entity\OrigineExemplaire
*
* #ORM\ManyToOne(targetEntity="Akplanu\Entity\OrigineExemplaire")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="Origin_id", referencedColumnName="Origin_id", nullable=false)
* })
*/
private $origine;
/**
* #var \Akplanu\Entity\EtatLivre
*
* #ORM\ManyToOne(targetEntity="Akplanu\Entity\EtatLivre")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="Etlv_id", referencedColumnName="Etlv_id", nullable=false)
* })
*/
private $etat;
/**
* #ORM\Column(name="Expl_datEntree" ,type="date" , nullable=false)
*/
private $dateEntree;
/**
* #ORM\Column(name="Expl_estEmprunter" ,type="boolean" , nullable=false)
*/
private $estEmprunter;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set numEntre
*
* #param integer $numEntre
* #return Exemplaire
*/
public function setNumEntre($numEntre)
{
$this->numEntre = $numEntre;
return $this;
}
/**
* Get numEntre
*
* #return integer
*/
public function getNumEntre()
{
return $this->numEntre;
}
/**
* Set lieuEdit
*
* #param string $lieuEdit
* #return Exemplaire
*/
public function setLieuEdit($lieuEdit)
{
$this->lieuEdit = $lieuEdit;
return $this;
}
/**
* Get lieuEdit
*
* #return string
*/
public function getLieuEdit()
{
return $this->lieuEdit;
}
/**
* Set datEdit
*
* #param \DateTime $datEdit
* #return Exemplaire
*/
public function setDatEdit($datEdit)
{
$this->datEdit = $datEdit;
return $this;
}
/**
* Get datEdit
*
* #return \DateTime
*/
public function getDatEdit()
{
return $this->datEdit;
}
/**
* Set tome
*
* #param boolean $tome
* #return Exemplaire
*/
public function setTome($tome)
{
$this->tome = $tome;
return $this;
}
/**
* Get tome
*
* #return boolean
*/
public function getTome()
{
return $this->tome;
}
/**
* Set dateDon
*
* #param \DateTime $dateDon
* #return Exemplaire
*/
public function setDateDon($dateDon)
{
$this->dateDon = $dateDon;
return $this;
}
/**
* Get dateDon
*
* #return \DateTime
*/
public function getDateDon()
{
return $this->dateDon;
}
/**
* Set prix
*
* #param float $prix
* #return Exemplaire
*/
public function setPrix($prix)
{
$this->prix = $prix;
return $this;
}
/**
* Get prix
*
* #return float
*/
public function getPrix()
{
return $this->prix;
}
/**
* Set comment
*
* #param string $comment
* #return Exemplaire
*/
public function setComment($comment)
{
$this->comment = $comment;
return $this;
}
/**
* Get comment
*
* #return string
*/
public function getComment()
{
return $this->comment;
}
/**
* Set livre
*
* #param \Akplanu\Entity\Livre $livre
* #return Exemplaire
*/
public function setLivre(\Akplanu\Entity\Livre $livre )
{
$this->livre = $livre;
return $this;
}
/**
* Get livre
*
* #return \Akplanu\Entity\Livre
*/
public function getLivre()
{
return $this->livre;
}
/**
* Set donateur
*
* #param \Akplanu\Entity\Donateur $donateur
* #return Exemplaire
*/
public function setDonateur(\Akplanu\Entity\Donateur $donateur )
{
$this->donateur = $donateur;
return $this;
}
/**
* Get donateur
*
* #return \Akplanu\Entity\Donateur
*/
public function getDonateur()
{
return $this->donateur;
}
/**
* Set origine
*
* #param \Akplanu\Entity\OrigineExemplaire $origine
* #return Exemplaire
*/
public function setOrigine(\Akplanu\Entity\OrigineExemplaire $origine )
{
$this->origine = $origine;
return $this;
}
/**
* Get origine
*
* #return \Akplanu\Entity\OrigineExemplaire
*/
public function getOrigine()
{
return $this->origine;
}
/**
* Set etat
*
* #param \Akplanu\Entity\EtatLivre $etat
* #return Exemplaire
*/
public function setEtat(\Akplanu\Entity\EtatLivre $etat )
{
$this->etat = $etat;
return $this;
}
/**
* Get etat
*
* #return \Akplanu\Entity\EtatLivre
*/
public function getEtat()
{
return $this->etat;
}
public function getDateEntree()
{
return $this->dateEntree;
}
public function setDateEntree($dateEntree)
{
$this->dateEntree = $dateEntree;
}
public function getEstEmprunter()
{
return $this->estEmprunter;
}
public function setEstEmprunter($estEmprunter)
{
$this->estEmprunter = $estEmprunter;
}
}
And a repository with the following code:
<?php
namespace Akplanu\Repository;
use Akplanu\Entity\Exemplaire;
use Doctrine\ORM\EntityRepository;
class ExemplaireRepository extends EntityRepository
{
/**
* add or update an exemplaire
*/
public function save(Exemplaire $exemplaire)
{
$this->getEntityManager()->persist($exemplaire);
$this->getEntityManager()->flush();
}
/**
* delete a list exemplaire base on ids array
*/
public function delete($idsExemplaire)
{
$dql = "DELETE FROM Akplanu\Entity\Exemplaire d WHERE d.id IN (:idsExemplaire)";
$query = $this->getEntityManager()->createQuery($dql);
$query->setParameter('idsExemplaire',$idsExemplaire);
$query->execute();
}
/**
* find Exemplaire by id
*/
public function findById($id)
{
return $this->find((int)$id);
}
/**
* find exemplaire by name
*/
public function findByNumeroEntree($numeroEntree)
{
return $this->findBy(array('numeroEntree'=>$numeroEntree),array('numeroEntree'=>'asc'));
}
/**
* retrieve list of all exemplaire
*/
public function getAll()
{
return $this->findAll();
}
public function getListExemplairesPouvantEtreEmprunter()
{
$dql = "SELECT e,l FROM Akplanu\Entity\Exemplaire e
JOIN e.livre l
WITH e.estEmprunter = false";
$query = $this->getEntityManager()->createQuery($dql);
return $query->getResult();
}
}
?>
When i call the ExemplaireRepository::findById() method via my service in the contoller(by using ajax request), the request doesn't return any result even if i edit the method as follow:
/**
* find Exemplaire by id
*/
public function findById($id)
{
$dql = "SELECT e,l,d,o,t FROM Akplanu\Entity\Exemplaire e
JOIN e.livre l
JOIN e.donateur d
JOIN e.origine o
JOIN e.etat t
WHERE e.id=:id";
$query = $this->getEntityManager()->createQuery($dql);
$query->setParameter('id', $id);
return $query->getResult();
}
In FireBug Console i have a wainting icon than is shown indefinitly without any error message, but the ExemplaireRepository::getListExemplairesPouvantEtreEmprunter() is working well!
Has somebody already face that kind of problem? Where can be it cause? And How can i solve it.
Thank you in advance.
This is most likely a setup error in your code. I would suggest using the doctrine modules for Zend Framework 2.
https://github.com/doctrine/DoctrineORMModule
https://github.com/doctrine/DoctrineModule
The readmes explain how to install the modules using composer .
I've been using this site for a while and so far never needed to ask a new question (found all answers I've needed until now).
I need to push_back multiple objects into a vector but VS throws an error (This may be due to a corruption of the heap, which indicates a bug in PVSS00DataGate.exe or any of the DLLs it has loaded) that I cannot seem to work out for myself.
Here is what I am trying to do, it works to push_back the first object into the vector but when I try to push_back a second object that is when the error occurs.
class HWObject{}
void DataLogger::WriteNewMessages()
{
unsigned int iBattery = 0;
unsigned int iSignal = 0;
TimeVar tTimeStamp;
// I want to store all HWObjects in a temporary vector (loggerData)
std::vector<HWObject> loggerData;
CharString strElement;
strElement.format( "batteryCondition.value" );
SendOneValuePVSS( (const char *)strElement, iBattery, tTimeStamp );
strElement.format( "signalStrength.value" );
SendOneValuePVSS( (const char *)strElement, iSignal, tTimeStamp );
}
void DataLogger::SendOneValuePVSS(const char *szElementName, double dValue, TimeVar, &tValue)
{
HWObject obj;
obj.setOrgTime(tValue); // Current time
obj.setTimeOfPeriphFlag();
CharString address;
address = strID;
address += ".";
address += szElementName;
obj.setAddress(address);
loggerData.reserve( loggerData.size() + 1 );
loggerData.push_back( obj );
obj.cutData();
}
dataLogger is declared in
class DataLogger
{
public:
std::vector<HWObject> loggerData;
...
}
Here is the class HWObject, I didn't want to overwhelm you with code.
public:
/** Default constructor*/
HWObject();
/** Constructor, which sets the periphAddr and transformationType.
* #param addressString address of the HW object
* #param trans type of transformation
*/
HWObject(const char* addressString, TransformationType trans);
/** Destructor. If the date pointer is not NULL, it is deleted.
*/
virtual ~HWObject();
/** Creates a new HWObject
* This function returns an empty HWObject, no properties are duplicated or copied!
* #classification public use, overload, call base
*/
virtual HWObject * clone() const;
/** Reset all pvss2 relevant parts of the HWObject. when overloading this member
* don't forget to call the basic function!
* #classification public use, overload, call base
*/
virtual void clear();
/** Gets pointer to data
* #return pointer to data
*/
const PVSSchar * getDataPtr() const { return dataPtr; }
/** Gets the data buffer pointer
* #return data buffer pointer
*/
PVSSchar * getData() { return dataPtr; }
/** Cut the data buffer out of the HWObject.
* This function is used to avoid the deletion
* of the data buffer, when a new pointer is set using
* setData() or the HWObject is deleted.
* #return pointer to the data of the HWObject
*/
PVSSchar * cutData();
/** Get the data buffer lenght
* #return length of the data buffer
*/
PVSSushort getDlen() const { return dataLen; }
/** Set ptr to the data buffer, pointer is captured.
* The actual data pointer in the HWObject is deleted,
* if it is not NULL. To avoid the deletion use cutData()
* in order to cut out the pointer.
* #param ptr pointer to new data
*/
void setData(PVSSchar *ptr);
/** Set the data length
* #param len length to be set
*/
void setDlen(const PVSSushort len) { dataLen = len; }
/** Get the periph address
* #return periph address string
*/
const CharString & getAddress() const { return address; }
/** Get the transformation type
* #return type of transformation
*/
TransformationType getType() const { return transType; }
/** Set the transformation type
* #param typ type of transformation for setting
*/
void setType(const TransformationType typ) { transType = typ; }
/** Get the subindex
* #return subindex
*/
PVSSushort getSubindex() const { return subindex; }
/** Set the subindex
* #param sx subindex to be set
*/
void setSubindex( const PVSSushort sx) { subindex = sx; }
/** Get the origin time
* #return origin time
*/
const TimeVar& getOrgTime() const { return originTime; }
/** Get the origin time
* #return oriin time
*/
TimeVar& getOrgTime() { return originTime; }
/** Set the origin time
* #param tm origin time to be set
*/
void setOrgTime(const TimeVar& tm) { originTime = tm; }
/** Get HWObject purpose
* #return objSrcType
*/
ObjectSourceType getObjSrcType() const { return objSrcType; }
/** Set HWObject purpose
* #param tp objSrcType
*/
void setObjSrcType(const ObjectSourceType tp) { objSrcType = tp; }
/** Get number of elements in data buffer
* #return number of elements in data buffer
*/
PVSSushort getNumberOfElements() const { return number_of_elements; }
/** Set number of elements in data buffer
* #param var number of elements in data buffer
*/
void setNumberOfElements(const PVSSushort var) { number_of_elements = var; }
/** Prints the basic HWObject information on stderr.
* in case of overloading don't forget to call the base function!
* #classification public use, overload, call base
*/
virtual void debugPrint() const;
/** Prints th basic HWObject info in one CharString for internal debug DP.
* in case of overloading call base function first, then append specific info
* #classification public use, overload, call base
*/
virtual CharString getInfo() const;
/** Set the periph address
* #param adrStr pointer to address string
*/
virtual void setAddress(const char *adrStr);
/** Set the additional data (flag, orig time, valid user byte,etc)
* #param data aditional flags that be set
* #param subix subindex, use subix 0 for setting values by default
*/
virtual void setAdditionalData(const RecVar &data, PVSSushort subix);
/** Set the 'origin time comes from periph' flag
*/
void setTimeOfPeriphFlag()
{
setSbit(DRV_TIME_OF_PERIPH);
}
/** Check whether time comes from periph
* #return PVSS_TRUE if the time is from perip
*/
PVSSboolean isTimeFromPeriph() const
{
// If isTimeOfPeriph is set, it must be valid
return getSbit(DRV_TIME_OF_PERIPH);
}
/** Set the flag if you want to receive callback if event has answered the value change
*/
void setWantAnswerFlag()
{
setSbit(DRV_WANT_ANSWER);
}
/** Get the status of the 'want answer, flag
*/
PVSSboolean getWantAnswerFlag() const
{
// If isTimeOfPeriph is set, it must be valid
return getSbit(DRV_WANT_ANSWER);
}
/** Set the user bit given by input parameter.
* Status bits defined by the enum DriverBits
* #param bitno bit number
* #return PVSS_TRUE if bit was set
*/
PVSSboolean setSbit(PVSSushort bitno)
{
return (status.set(bitno) && status.set(bitno + (PVSSushort)DRV_VALID_INVALID - (PVSSushort)DRV_INVALID));
}
/** Clear the user bit given by input parameter
* #param bitno bit number
* #return PVSS_TRUE if bit was cleared
*/
PVSSboolean clearSbit(PVSSushort bitno)
{
return (status.clear(bitno) && status.set(bitno + (PVSSushort)DRV_VALID_INVALID - (PVSSushort)DRV_INVALID));
}
PVSSboolean isValidSbit(PVSSushort bitno) const
{
return status.get(bitno + (PVSSushort)DRV_VALID_INVALID - (PVSSushort)DRV_INVALID);
}
/** Check any bit
* #param bitno bit number
* #return status of the bit on bitno position
*/
PVSSboolean getSbit(PVSSushort bitno) const {return status.get(bitno);}
/** Clear all status bits
* return status of clear all
*/
PVSSboolean clearStatus() {return status.clearAll();}
/** Get the status of this object
* #return bit vector status
*/
const BitVec & getStatus() const {return status;}
/** Set status of the bit vector
* #param bv deference to bit vector to be set as status
*/
void setStatus(const BitVec &bv) {status = bv;}
/** Set a user byte in the status.
* #param userByteNo number of user byte range 0..3
* #param val value to set
* #return PVSS_TRUE execution OK
* PVSS_FALSE in case of error
*/
PVSSboolean setUserByte (PVSSushort userByteNo, PVSSuchar val);
/** Reads a user byte from the status.
* #param userByteNo number of user byte range 0..3
* #return the requested user byte
*/
PVSSuchar getUserByte (PVSSushort userByteNo) const;
/** Check validity of user byte.
* #param userByteNo number of user byte range 0..3
* #return PVSS_TRUE user byte is valid
* PVSS_FALSE user byte is not valid
*/
PVSSboolean isValidUserByte(PVSSushort userByteNo) const;
/** Format status bits into a string
* #param str status bits converted to string
*/
void formatStatus (CharString & str) const ;
// ------------------------------------------------------------------
// internal ones
/** Read data from bin file
* #param fp file handle
*/
virtual int inFromBinFile( FILE *fp );
/** Write data to bin file
* #param fp file handle
*/
virtual int outToBinFile( FILE *fp );
/** Set data length
* #param dlen data length
*/
void setDlenLlc (PVSSushort dlen) {dataLenLlc = dlen;}
virtual void updateBufferLlc (HWObject * hwo, int offset1 = 0);
virtual int compareLlc (HWObject * hwo, int offset1 = 0, int offset2 = 0, int len = -1);
/** Get dataLenLlc
* #return dataLenLlc
*/
PVSSushort getDlenLlc () const {return dataLenLlc;}
/** Function to delete the data buffer; overload if special deletion must be done
*/
virtual void deleteData ();
/** Set HW identifier
* #param id hw identifier to be set
*/
void setHwoId(PVSSulong id) {hwoId = id;}
/** Get HW identifier
* #return hw identifier
*/
PVSSulong getHwoId() const {return hwoId;}
protected:
/// the dynamic data buffer
PVSSchar* dataPtr;
/// the data buffer len
PVSSushort dataLen;
/// the pvss2 periph address string
CharString address;
/// the start subix for the data buffer
PVSSushort subindex;
/// the datatype of the data in the buffer (i.e. transformationtype)
TransformationType transType;
/// the time of income, normally set by the constructor
TimeVar originTime;
/// the purpose of this HWObject
ObjectSourceType objSrcType;
/// the number of elements in the data buffer, used for arrays and records
PVSSushort number_of_elements; // fuer array!!!
/// the user bits of the original config
BitVec status;
private:
PVSSushort dataLenLlc;
PVSSulong hwoId;
};
You're not showing the important parts. I'd guess that HWObject has
dynamically allocated memory, and doesn't implement the rule of three
(copy constructor, assignment operator and destructor). But it's only a
guess. (Unless you're using special techniques like reference counting
or smart pointers, copy must do a deep copy, and assignment should
probably use the swap idiom.)
Also, there's no point in reserving size() + 1 just before
push_back.