2012-02-27 21:55:15 +04:00
/* ------------------------------------------------------------------------ */
2015-09-23 16:03:22 +03:00
/* Copyright 2002-2015, OpenNebula Project, OpenNebula Systems */
2012-02-27 21:55:15 +04:00
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------*/
# ifndef CLUSTERABLE_H_
# define CLUSTERABLE_H_
2016-03-10 18:28:33 +03:00
# include "ObjectCollection.h"
2012-02-27 21:55:15 +04:00
class Clusterable
{
public :
2016-03-10 18:28:33 +03:00
int add_cluster ( int cluster_id )
{
return cluster_ids . add ( cluster_id ) ;
} ;
int del_cluster ( int cluster_id )
{
return cluster_ids . del ( cluster_id ) ;
} ;
2012-02-27 21:55:15 +04:00
/**
2016-03-10 18:28:33 +03:00
* Returns the cluster IDs
2012-02-27 21:55:15 +04:00
*
2016-03-10 18:28:33 +03:00
* @ return The cluster IDs set
2012-02-27 21:55:15 +04:00
*/
2016-03-20 01:13:10 +03:00
std : : set < int > get_cluster_ids ( ) const
2012-02-27 21:55:15 +04:00
{
2016-03-10 18:28:33 +03:00
return cluster_ids . clone ( ) ;
2012-02-27 21:55:15 +04:00
} ;
/**
2016-03-10 18:28:33 +03:00
* Rebuilds the cluster collection from an xml object
* @ param xml xml object
* @ param xpath_prefix Parent nodes , e . g . " /DATASTORE/ "
2012-02-27 21:55:15 +04:00
*
2016-03-10 18:28:33 +03:00
* @ return 0 on success , - 1 otherwise
2012-02-27 21:55:15 +04:00
*/
2016-03-20 01:13:10 +03:00
int from_xml ( const ObjectXML * xml , const std : : string & xpath_prefix )
2016-03-10 18:28:33 +03:00
{
return cluster_ids . from_xml ( xml , xpath_prefix ) ;
} ;
/**
* Function to print the cluster IDs into a string in
* XML format
* @ param xml the resulting XML string
* @ return a reference to the generated string
*/
2016-03-20 01:13:10 +03:00
std : : string & to_xml ( std : : string & xml ) const
2012-02-27 21:55:15 +04:00
{
2016-03-10 18:28:33 +03:00
return cluster_ids . to_xml ( xml ) ;
2012-02-27 21:55:15 +04:00
} ;
protected :
2016-03-20 01:13:10 +03:00
Clusterable ( const std : : set < int > & _cluster_ids ) :
cluster_ids ( " CLUSTERS " , _cluster_ids ) { } ;
2012-02-27 21:55:15 +04:00
~ Clusterable ( ) { } ;
/**
2016-03-10 18:28:33 +03:00
* IDs of the clusters this object belongs to .
2012-02-27 21:55:15 +04:00
*/
2016-03-10 18:28:33 +03:00
ObjectCollection cluster_ids ;
2012-02-27 21:55:15 +04:00
} ;
# endif /*CLUSTERABLE_H_*/